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/20210301094931.6ec9b613%40gmail.com.

Attachment: pgpMb3XtQPJP8.pgp
Description: OpenPGP digital signature

Reply via email to