Clear Directory with Salt State File

Solution 1:

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

remove-supervisord-confd:
   file.directory:
      - name: /etc/supervisord/conf.d/           
      - clean: True

Solution 2:

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:

supervisor-conf-delete:
  file.absent:
    - name: /etc/supervisord/conf.d

supervisor-conf-create:
  file.directory:
    - name: /etc/supervisord/conf.d
    - user: root
    - group: root
    - mode: 0755
    - require:
        - file: supervisor-conf-delete

Solution 3:

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:
    cmd.run

You can also write more complicated commands if you wish.