# Roles Loop

**URL:** <https://forum.ansible.com/t/roles-loop/34225>\
**Category:** Ansible Project\
**Created:** [November 23, 2020, 12:19pm UTC](https://forum.ansible.com/t/roles-loop/34225 "2020-11-23T12:19:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![blue\_fox](https://avatars.discourse-cdn.com/v4/letter/b/8491ac/32.png) [@blue\_fox](https://forum.ansible.com/u/blue_fox)\
**Post date:** [November 23, 2020, 12:19pm UTC](https://forum.ansible.com/t/roles-loop/34225/1 "2020-11-23T12:19:37Z")

</div>

I like to make a loop for a role , each time he copie each host in file

example:

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [November 23, 2020, 12:32pm UTC](https://forum.ansible.com/t/roles-loop/34225/2 "2020-11-23T12:32:01Z")

</div>

> I like to make a loop for a role , each time he copie each host in file
> 
> example:  
> ------------------  
> hosts file
> 
> webserver]
> 
> 10.10.10.10
> 
> 20.20.20.20
> 
> ---------------------  
> turn 1 for loop: copie 10.10.10.10. in file and send it to distant server
> 
> turn 2 for loop: copie 20.20.20.20. in file and send it to distant server
> 
> Thank you

So you want to execute the role only for members of webserver group?

If so you can add the following condition:

&nbsp;&nbsp;&nbsp;&nbsp;when: "'webserver' in group\_names"

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![blue\_fox](https://avatars.discourse-cdn.com/v4/letter/b/8491ac/32.png) [@blue\_fox](https://forum.ansible.com/u/blue_fox)\
**Post date:** [November 23, 2020, 1:36pm UTC](https://forum.ansible.com/t/roles-loop/34225/3 "2020-11-23T13:36:21Z")

</div>

i want to copy each host in webservers group in file and send it to ather server distant.

each role execute ---- \> copy one host in file

thank you

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [November 23, 2020, 1:46pm UTC](https://forum.ansible.com/t/roles-loop/34225/4 "2020-11-23T13:46:47Z")

</div>

> i want to copy each host in webservers group in file and send it to ather server distant.
> 
> each role execute ---- \> copy one host in file

It is not clear to me what you want to achieve. How does your role look like?

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![blue\_fox](https://avatars.discourse-cdn.com/v4/letter/b/8491ac/32.png) [@blue\_fox](https://forum.ansible.com/u/blue_fox)\
**Post date:** [November 23, 2020, 1:55pm UTC](https://forum.ansible.com/t/roles-loop/34225/5 "2020-11-23T13:55:15Z")

</div>

i need to test each time each ip address alone in another server, therefore i need to copy each ip address in webservers group in file and sen this file to server distant for test it  
the test treatment = role

1- copy the primary ip and send the file in testing server  
2- execute roles for testing  
3- copy the seconde in the same file ip and send it in testing server  
4- execute the same role for testing

Thank you
