thanks Vladimir, thanks for the solution , can you also please advise instead of specific ip when i want all ip addresses without bracket constraint from ip_ist.txt what approach i should follow?
On Mon, Mar 1, 2021 at 9:49 AM Vladimir Botka <[email protected]> wrote: > On Sun, 28 Feb 2021 23:52:38 -0800 (PST) > Sakshi Rathore <[email protected]> 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 > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAJeB3MPn6S%2B0r7_4R08Hg5oNUR-jL6gZ1druaxp3ngc4U5p1iQ%40mail.gmail.com.
