# How to generate a group of ip list by referencing a variable in play books?

**URL:** <https://forum.ansible.com/t/how-to-generate-a-group-of-ip-list-by-referencing-a-variable-in-play-books/21519>\
**Category:** Ansible Project\
**Created:** [May 23, 2016, 1:09am UTC](https://forum.ansible.com/t/how-to-generate-a-group-of-ip-list-by-referencing-a-variable-in-play-books/21519 "2016-05-23T01:09:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sicheng\_Tang](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@Sicheng\_Tang](https://forum.ansible.com/u/Sicheng_Tang)\
**Post date:** [May 23, 2016, 1:09am UTC](https://forum.ansible.com/t/how-to-generate-a-group-of-ip-list-by-referencing-a-variable-in-play-books/21519/1 "2016-05-23T01:09:48Z")

</div>

Hi all:  
I have a group of host whose IPs are 10.129.51.158,10.129.50.235,10.129.50.232 and I will define them as variable, like this  
ip = 10.129.51.158,10.129.50.235,10.129.50.232

Is there any way to generate a play book like this by referencing this ip?

[my-role]  
10.129.51.158

10.129.50.235

10.129.50.232

[my-role:vars]

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [May 29, 2016, 7:39pm UTC](https://forum.ansible.com/t/how-to-generate-a-group-of-ip-list-by-referencing-a-variable-in-play-books/21519/2 "2016-05-29T19:39:06Z")

</div>

Hi,

> Hi all:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I have a group of host whose IPs  
> are 10.129.51.158,10.129.50.235,10.129.50.232 and I will define them as  
> variable, like this  
> ip = 10.129.51.158,10.129.50.235,10.129.50.232
> 
> Is there any way to generate a play book like this by referencing this ip?
> 
> [my-role]  
> 10.129.51.158  
> 10.129.50.235  
> 10.129.50.232
> 
> [my-role:vars]  
> ,

I'm sorry, I do not understand your question. As you have not gotten  
any answers yet, it might be others have not understood it, too.

What you outline above is part of a hosts file. But where do you want  
to define the ip? And what should it be used for?

Do you want to iterate/loop over all members of your group my-role?  
That can be done. See the example in the docs:  
[https://docs.ansible.com/ansible/playbooks\_loops.html#id29](https://docs.ansible.com/ansible/playbooks_loops.html#id29)

Johannes
