Ansible - create a list from variable

15 views
Skip to first unread message

TheSmiths

unread,
Sep 3, 2019, 10:52:49 AM9/3/19
to Ansible Project
Hi,

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

The variable:


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



 


Karl Auer

unread,
Sep 3, 2019, 11:10:53 AM9/3/19
to ansible-project

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.


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/290b5352-d845-4cd1-9724-46d89907d51d%40googlegroups.com.


--
Karl Auer

Email  : ka...@2pisoftware.com
Website: http://2pisoftware.com


GPG/PGP : 301B 1F4E 624D AD99 242C 7A68 EC24 7113 E854 4A4E
Previous:
958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816
Reply all
Reply to author
Forward
0 new messages