Skip to content

Instantly share code, notes, and snippets.

Last active October 3, 2019 12:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
- name: Configure telegraf {{name}}
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
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