4

How to work around Recursive directory management doesn't preserve permissions?

I want to copy all files in (local) /monitoring/files/etc to /etc on the minion.

copy_files_in_etc:
  file.recurse:
    - source:
      - salt://monitoring/files/etc
    - name: /etc
    - template: jinja

Above snippets works, but I am missing the executable bit for some files.

For example scripts in /etc/cron.daily should be executable.

What is the most simple way to work around this?

I search a way to make all files matching this expression to be executable:

/etc/cron.(daily|hourly|monthly|weekly/)
guettli
  • 3,591
  • 17
  • 72
  • 123

2 Answers2

5

It looks like this was fixed.

copy_files_in_etc:
  file.recurse:
    - source:
    - salt://monitoring/files/etc
    - name: /etc
    - template: jinja
    - file_mode: keep

Search for file_mode at the following link: https://docs.saltstack.com/en/latest/ref/states/all/salt.states.file.html#salt.states.file.recurse

This will cause the files to have the same mode as on the salt master.

Dereckson
  • 136
  • 8
Utah_Dave
  • 532
  • 2
  • 6
1

You can use file_mode and dir_mode. In your case, file_mode should be enough.

copy_files_in_etc:
  file.recurse:
    - source:
      - salt://monitoring/files/etc
    - name: /etc
    - template: jinja
    - file_mode: '0755'
Halfgaar
  • 8,084
  • 6
  • 45
  • 86
  • Yes, this would set the executable bit for all files in `/etc/cron.(daily|hourly|monthly|weekly/)`, but it would set it on all other files in `/etc`, too. – guettli Nov 28 '16 at 13:09
  • Perhaps it's better to make different `id`s (sections) in one SLS file, which each manages a subsection. Having one SLS for the entire `/etc` will also make it hard to roll out changes in a controlled manner. Your `monitoring.sls` could have the `id` `cron_files`, `nagios_files`, `misc_daemon_files`, etc. – Halfgaar Nov 28 '16 at 14:09