Skip to content

Instantly share code, notes, and snippets.

@SpComb
Last active October 3, 2019 12:04
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 SpComb/cfb7c87bef0ccc0f26758723c7ce002d to your computer and use it in GitHub Desktop.
Save SpComb/cfb7c87bef0ccc0f26758723c7ce002d to your computer and use it in GitHub Desktop.
- 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