using extra-vars with list and dict

115 views
Skip to first unread message

Veera

unread,
Nov 16, 2023, 4:08:58 AM11/16/23
to Ansible Project
Hi,

I am missing the format of  input the extra-vars with multiple choices . 
In the playbook , I am passing 2 variables as extra vars  and they are working fine .

ansible-playbook myplaybook.yml -e "server_ip=10.100.100.100  host_names=myserver1_10.100.100.100"
   
   and able to execute my playbook successfully.  However when I have multiple IP's to feed in like below 
 
ansible-playbook myplaybook.yml -e "server_ip='10.100.100.100', '10.100.100.101' ....'10.100.100.10N' host_names='myserver1_10.100.100.100', 'myserver2_10.100.100.102', .....'myserver10N_10.100.100.10N' "
 
   The playbook uses a temporary inventory  and looking to input the same with hostnames as myserver_IP one after the other .  
  ansible.builtin.add_host:
        hostname: '{{ host_names }}'
        groups: my_group
        ansible_ssh_private_key_file: "{{ mykeypath }}"
        ansible_ssh_user: "root"
        ansible_ssh_extra_args: '-o StrictHostKeyChecking=no'

Two extra vars as lists to be passed  and  the items in extra_vars lists are to be processed 1+1 at a time . (ie .. the IP 10.100.100.105  must be processed  along with host_names=myserver105_10.100.100.105"


   


Dick Visser

unread,
Nov 16, 2023, 6:03:11 AM11/16/23
to ansible...@googlegroups.com
So you extra vars param should look like:

--extra-vars '{"server_ip": ["10.100.1.1", "10.2.1.3", "9.3.1.2a"]}'





--
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/a144a34b-2744-458f-b943-94606d55020dn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages