Hi Ansible List,
There is a need to dynamically add new groups to icinga configs so each time a new grpup is added to /etc/ansible/hosts, a template should be added to icinga monitoring into /etc/icinga/objects. I’ve managed to craft the logic using set_facts and now I’m stuck at with_first_found and with_items:
-
name: icinga - get all group names
set_fact: my_group_names=‘{{ item}}’
with_items: ‘{{groups}}’
register: my_group_list -
name: icinga - debug my_group_names
debug: var=item.ansible_facts.my_group_names
with_items: ‘{{my_group_list.results}}’ -
name: icinga - setfact icinga_groups
set_fact:
icinga_groups: “{{ my_group_list.results | map(attribute=‘ansible_facts.my_group_names’) | list }}” -
name: icinga - scp templates
template: src={{ lookup(‘first_found’, [‘/etc/ansible/deployment/templates/etc/icinga/objects/hsec-service-’ + item + ‘.cfg’, '/etc/ansible/deployment/templates/etc/icinga/objects/hsec-service-DEFAULT + ‘.cfg’]) }} dest=/etc/icinga/objects/{{ item }}
with_items: icinga_groups
when: “inventory_hostname in groups[‘monitoring’]”
I’ve found references about with_items not working with with_fist found and the posts talk about using lookup instead. Adding -vvvv to the playbook gives me a stacktrace “ValueError: zero length field name in format”. What is the correct syntax ?
Thank you