Created
March 21, 2015 16:05
-
-
Save funollet/bcbcaf0f4e752a8adc94 to your computer and use it in GitHub Desktop.
An example with Ansible to manage files in a directory; unmanaged files must be removed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: localhost | |
connection: local | |
vars: | |
conf_d: results/conf.d | |
put_files: | |
- a.conf | |
- b.conf | |
tasks: | |
- name: Put files in conf.d/ | |
template: | |
src: "templates/{{ item }}.j2" | |
dest: "{{ conf_d}}/{{ item }}" | |
with_items: put_files | |
- name: Make list of all files | |
shell: "ls {{ conf_d }}" | |
register: all_files | |
- name: Remove extra files | |
file: | |
path: "results/conf.d/{{ item }}" | |
state: absent | |
with_items: all_files.stdout_lines | difference(put_files) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
init: | |
mkdir -p results/conf.d/ | |
mkdir -p templates | |
touch templates/{a,b}.conf.j2 | |
touch results/conf.d/unwanted_file.conf | |
touch results/conf.d/break_my_config.conf | |
run: | |
ansible-playbook -i localhost, clumsy.yml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment