According to https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html#defining-variables-at-runtime you can use the JSON notation to pass in a list. So you extra vars param should look like:
--extra-vars '{"server_ip": ["10.100.1.1", "10.2.1.3", "9.3.1.2a"]}' On Thu, 16 Nov 2023 at 10:09, Veera <sveem...@gmail.com> wrote: > 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" > > > > > > -- > 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-project+unsubscr...@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 > <https://groups.google.com/d/msgid/ansible-project/a144a34b-2744-458f-b943-94606d55020dn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAF8BbLatjd4Z%3DnxM%3D5evHRkG4%2Bvjhp%2BZQgcgOGrhy044QUdqgw%40mail.gmail.com.