# using extra-vars with  list and dict

**URL:** <https://forum.ansible.com/t/using-extra-vars-with-list-and-dict/38583>\
**Category:** Ansible Project\
**Created:** [November 16, 2023, 9:08am UTC](https://forum.ansible.com/t/using-extra-vars-with-list-and-dict/38583 "2023-11-16T09:08:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Veera](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/veera/32/4107_2.png) [@Veera](https://forum.ansible.com/u/Veera)\
**Post date:** [November 16, 2023, 9:08am UTC](https://forum.ansible.com/t/using-extra-vars-with-list-and-dict/38583/1 "2023-11-16T09:08:57Z")

</div>

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"

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [November 16, 2023, 11:02am UTC](https://forum.ansible.com/t/using-extra-vars-with-list-and-dict/38583/2 "2023-11-16T11:02:34Z")

</div>

According to [https://docs.ansible.com/ansible/latest/playbook\_guide/playbooks\_variables.html#defining-variables-at-runtime](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”]}’
