Skip to content

Instantly share code, notes, and snippets.

@Rabattkarte
Last active March 7, 2018 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rabattkarte/3723c00aef94400cf44fa95a2836748f to your computer and use it in GitHub Desktop.
Save Rabattkarte/3723c00aef94400cf44fa95a2836748f to your computer and use it in GitHub Desktop.
$ cd /tmp/testdir/sites-enabled/
$ touch 12098 dlij 0921 dpo 210983uj1m foo bar abc def
$ ls
0921 12098 210983uj1m abc bar def dlij dpo foo
$ salt-call state.apply remove_files_in_dir_except_list
local:
----------
ID: file
Function: 0./tmp/testdir/sites-enabled/
Name: remove files in dir
Result: True
Comment: Files cleaned from directory /tmp/testdir/sites-enabled
Started: 16:57:14.746713
Duration: 5.838 ms
Changes:
----------
removed:
- /tmp/testdir/sites-enabled/bar
- /tmp/testdir/sites-enabled/dlij
- /tmp/testdir/sites-enabled/210983uj1m
- /tmp/testdir/sites-enabled/12098
- /tmp/testdir/sites-enabled/foo
- /tmp/testdir/sites-enabled/dpo
- /tmp/testdir/sites-enabled/0921
Summary for local
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 5.838 ms
$ ls
abc def
settings:
nginx:
sites:
- abc
- def
{% set wanted_sites = salt['pillar'].get('settings:nginx:sites') %}
remove files in dir:
file.directory:
- name: /tmp/testdir/sites-enabled/
- clean: True
{% if wanted_sites is not none %}
- exclude_pat: E@({{ wanted_sites|join(')|(') }})
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment