# Ansible - create a list from variable

**URL:** <https://forum.ansible.com/t/ansible-create-a-list-from-variable/31184>\
**Category:** Ansible Project\
**Created:** [August 31, 2019, 1:15pm UTC](https://forum.ansible.com/t/ansible-create-a-list-from-variable/31184 "2019-08-31T13:15:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheSmiths](https://avatars.discourse-cdn.com/v4/letter/t/ee59a6/32.png) [@TheSmiths](https://forum.ansible.com/u/TheSmiths)\
**Post date:** [August 31, 2019, 1:15pm UTC](https://forum.ansible.com/t/ansible-create-a-list-from-variable/31184/1 "2019-08-31T13:15:57Z")

</div>

Hi,

I would like to create a list from parsing a variable that contains multiple ips separated by a comma.

The variable:

**ips\_input: “,1.1.1.1/32,2.2.2.2/32,3.3.3.3/32”**

every item in the list should contain ip/mask.

the expected result:

**ips\_input\_parsed: [**  
**{**  
**single\_ip: “1.1.1.1/32”**  
**}.**

**{**  
**single\_ip: “2.2.2.2/32”**  
**}.**

**{**  
**single\_ip: “3.3.3.3/32”**  
**}.**

**]**

tried many different ways including regex\_replace with no success.

please advise.

Thanks,  
Morrissey

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [September 3, 2019, 3:10pm UTC](https://forum.ansible.com/t/ansible-create-a-list-from-variable/31184/2 "2019-09-03T15:10:32Z")

</div>

[http://www.mydailytutorials.com/how-to-split-strings-and-join-them-in-a%E2%80%8Bnsibl%E2%80%8Be/](http://www.mydailytutorials.com/how-to-split-strings-and-join-them-in-a%E2%80%8Bnsibl%E2%80%8Be/)

If your IP addresses are separated only by commas, and the comma-delimited strings contain only IP addresses, split() will do the job nicely. If there are things other than IP addresses in the input string, or if (as in your example string) you have empty strings, you will need to sanity-check the output from split().

Regards, K.
