How do I clear a directory on a salt-minion using a state file? I want to delete all *.conf files in /etc/supervisord/conf.d/ before I set up other supervisor services.

The following top.sls configuration has no effect:


file.remove fails as being unavailable.


Had same issue as you. That's what worked for me.

      - name: /etc/supervisord/conf.d/           
      - clean: True
| improve this answer | |

Not a perfect answer, but you could use file.absent on the directory, then recreate it. Note that this will delete the dir every time the state is run. You could get fancy with a jinja conditional surrounding the following:

    - name: /etc/supervisord/conf.d

    - name: /etc/supervisord/conf.d
    - user: root
    - group: root
    - mode: 0755
    - require:
        - file: supervisor-conf-delete
| improve this answer | |

You can use the cmd module in salt states. The following code could be present in your state file:

rm -f /etc/supervisord/conf.d/*.conf:

You can also write more complicated commands if you wish.

| improve this answer | |
  • Thanks, that would do it, but it doesn't feel very stateful. Any idea why the file.absent would not work? Maybe it doesn't understand wildcards. Or perhaps a directory module with an absent function would be more appropriate? – Petrus Theron Aug 5 '13 at 12:41
  • I don't see how "directory.absent" would be anymore stateful than a command run that has states. If you need to have a state, just introduce them in your shell script as required: docs.saltstack.com/en/latest/ref/states/all/… – noamik Jun 20 '14 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.