Assume a directory like this:
- etc/nginx/sites-available/
- hostA
- hostB
- hostC
Where hostA and hostB are created by salt. hostC was created earlier by salt as well, but since than it has been removed from pillar and is no longer needed. I want the directory to contain only files that represent current state. There is option to have the directory with clean: True
, but that will result in seeing a full diff of the directory every time I highstate – in our case it's 30 different files created on every highstate. That's making it very hard to check the changes that took place. Is there any way to work around this?
Update: current output (pseudo yaml)
- directory
- deleted:
- file: hostA
- file: hostB
- file: hostC
- file
- new file: hostA
- file
- new file: hostB
I would expect
- directory:
- deleted:
- file: hostC
Best Answer
You can get a listing of the directory you want by calling the
file.find
module, and since you have a list of the files you want to manage, you can delete the files that are not in the list of files to manage.Here's some code adapted from a state file I had to manage /etc/yum.repos.d. I'm going to assume your files to manage are from pillar, and they are keys to a dict, with the values being the rest of the data that goes into rendering the file.