28 lines
722 B
YAML

---
- name: "list previous host configs"
shell: ls -1 /etc/icinga2/conf.d/ansible_routeros/ | sed -e 's/\.[^\.]*$//'
register: previous_hosts
delegate_to: localhost
run_once: true
changed_when: false
- name: "create conf file for host"
template:
src: "host"
dest: "/etc/icinga2/conf.d/ansible_routeros/{{ inventory_hostname }}.conf"
notify:
- reload icinga2
- name: "remove stale hosts"
file:
path: "/etc/icinga2/conf.d/ansible_routeros/{{ item }}.conf"
state: absent
with_items: "{{ previous_hosts.stdout_lines }}"
when: "hostvars[item] is undefined"
delegate_to: localhost
run_once: true
notify:
- reload icinga2
# vim: set tabstop=2 shiftwidth=2 expandtab smarttab: