1

How can I delete a directory with SaltStack, if it is empty?

First I remove a file in this directory, and then I would like to delete the directory. But if there is one or several files in the directory, then the directory should not be removed.

I checked the docs of file.absent but found no solution.

guettli
  • 3,113
  • 14
  • 59
  • 110

1 Answers1

2

You can use unless (https://docs.saltstack.com/en/latest/ref/states/requisites.html)

/path/to/directory:
  file.absent:
    - unless: file.path_exists_glob('/path/to/directory/*')