Oskar Oskar -4 years ago 261
Linux Question

SaltStack - change file permissions

I need to change file permissions in Linux using SaltStack.

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


- user: root

- group: root

- mode: 400

But what should I use for files?

I can use:


- 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 file to the minion, I just need to change file permissions.

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

What options do I have?

Answer Source

If the file is not managed by salt you might want to use cmd.run instead and directly call the unix commands:

chown root:root /path/to/file:

chmod 444 /path/to/file:
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download