Search code examples
linuxsalt-project

How do you change file permissions on a minion in SaltStack?


I need to change file permissions in Linux using SaltStack.

For a directory I can use the file.directory function, for example:

file.directory:
  - user: root
  - group: root
  - mode: 400

But what should I use for files?

I can use:

file.managed:
  - user: root
  - group: root
  - mode: 444

And it works, but I have a warning message:

[WARNING ] State for file: /boot/grub/grub.cfg - Neither 'source' nor 'contents' nor 'contents_pillar' nor 'contents_grains' was defined, yet 'replace' was set to 'True'. As there is no source to replace the file with, 'replace' has been set to 'False' to avoid reading the file unnecessarily.

It expects a source directive, but I don't want to download the file to the minion, I just need to change file permissions.

The file.exists function doesn't have a user, group and mode directives.

What options do I have?


Solution

  • The warning message you get pretty much says it all. If you specify replace: False the message will be gone:

    file.managed:
      - user: root
      - group: root
      - mode: 444
      - replace: False
    

    Using cmd.run would obviously remove this message, but it's too generic and is more like a workaround here. The more salty approach would be to use file.managed state because this is what it was designed for.