Skip to content

Instantly share code, notes, and snippets.

@SpComb
Last active Oct 3, 2019
Embed
What would you like to do?
- name: Configure telegraf {{name}}
template:
src: "{{ src }}"
dest: "{{ dest }}"
owner: root
group: "{{ telegraf_group }}"
mode: 0640
notify: reload telegraf
# mark for prune
- name: Touch telegraf {{name}} for prune
shell: "test -f {{ dest }} && touch {{ dest }}"
check_mode: no # always run
changed_when: false
failed_when: false
- name: Configure telegraf agent
include_tasks: conf.yml
vars:
name: telegraf.conf
src: telegraf.conf.j2
dest: /etc/telegraf/telegraf.conf
- ...
# relies on conf.yml touching each file
- name: Prune old configs
command: find /etc/telegraf/telegraf.d/ -type f -not -newer /etc/telegraf/telegraf.conf {% if not ansible_check_mode %}-delete {% endif %}-print
check_mode: no # always run, but without -delete if check_mode
register: prune_telegraf_configs
changed_when: prune_telegraf_configs.stdout_lines
notify: reload telegraf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment