# with\_first\_found and with\_items

**URL:** <https://forum.ansible.com/t/with-first-found-and-with-items/26242>\
**Category:** Ansible Project\
**Created:** [December 10, 2017, 7:56pm UTC](https://forum.ansible.com/t/with-first-found-and-with-items/26242 "2017-12-10T19:56:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![George\_V](https://avatars.discourse-cdn.com/v4/letter/g/ac8455/32.png) [@George\_V](https://forum.ansible.com/u/George_V)\
**Post date:** [December 10, 2017, 7:56pm UTC](https://forum.ansible.com/t/with-first-found-and-with-items/26242/1 "2017-12-10T19:56:25Z")

</div>

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
