On Sun, 28 Feb 2021 23:52:38 -0800 (PST)
Sakshi Rathore <
sakshira...@gmail.com> wrote:
> i need to insert some ip addresses from a file into dynamic inventory file.
> while doing this i am getting square bracket also .
> how can i remove or escape square bracket into inventory file?
> sample input file is:
>
> ["ipadd1" , "ipadd2" , "ipadd3" , "ipadd4"]
> ["ipadd5" , "ipadd6" , "ipadd7" , "ipadd8"]
Given the file ip_list.txt is on the controller, try
- set_fact:
ip_list: "{{ lookup('file', 'ip_list.txt').split('\n')|
map('from_yaml')|list }}"
should give
ip_list:
- [ipadd1, ipadd2, ipadd3, ipadd4]
- [ipadd5, ipadd6, ipadd7, ipadd8]
Select the items, e.g. the third item from the second list
- debug:
var: ip_list[1][2]
should give
ip_list[1][2]: ipadd7
--
Vladimir Botka