# Expand group\_name in a loop with\_items

**URL:** <https://forum.ansible.com/t/expand-group-name-in-a-loop-with-items/19929>\
**Category:** Ansible Project\
**Created:** [December 3, 2015, 11:57am UTC](https://forum.ansible.com/t/expand-group-name-in-a-loop-with-items/19929 "2015-12-03T11:57:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manuel\_Jimenez](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@Manuel\_Jimenez](https://forum.ansible.com/u/Manuel_Jimenez)\
**Post date:** [December 3, 2015, 11:57am UTC](https://forum.ansible.com/t/expand-group-name-in-a-loop-with-items/19929/1 "2015-12-03T11:57:47Z")

</div>

Hello,  
I need to expand the group\_name for each host in the iteration because I would like to have different folders for each group.

So if the playbook is doing frontend1 I wan’t to access to frontends templates

Example:

Inventory  
[frontend1]  
1.2.3.4

[frontend2]  
1.2.3.5

[backend1]  
2.3.4.5

[backend2]  
2.3.4.6

[backends:children]  
backend1  
backend2

[frontends:children]  
frontend1  
frontend2

Templates directory inside role

roles/  
roles/cron/  
roles/cron/backends/  
roles/cron/backends/test\_cron.j2

roles/cron/frontends/  
roles/cron/frontends/test\_cron.j2

TASK

- template: src={{ item.src }} dest={{ item.dest }}

with\_items:

- { src: ‘templates/cron/{{ ansible\_groupname }}/test\_cron.j2’, dest: ‘/etc/cron.d/crawlers’ }

But it doesn’t work. I don’t know what variable should I use there…

Thanks!

---

<div class="post-metadata">

**Author:** ![Manuel\_Jimenez](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@Manuel\_Jimenez](https://forum.ansible.com/u/Manuel_Jimenez)\
**Post date:** [December 3, 2015, 5:05pm UTC](https://forum.ansible.com/t/expand-group-name-in-a-loop-with-items/19929/2 "2015-12-03T17:05:13Z")

</div>

Fixed with:

- …/templates/cron/{{ group\_names[1] }}/test\_cron.j2 …
