# Is there a way to define a list of values in vars?

**URL:** <https://forum.ansible.com/t/is-there-a-way-to-define-a-list-of-values-in-vars/22452>\
**Category:** Ansible Project\
**Created:** [September 1, 2016, 2:57pm UTC](https://forum.ansible.com/t/is-there-a-way-to-define-a-list-of-values-in-vars/22452 "2016-09-01T14:57:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![synova.marketing](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@synova.marketing](https://forum.ansible.com/u/synova.marketing)\
**Post date:** [September 1, 2016, 2:57pm UTC](https://forum.ansible.com/t/is-there-a-way-to-define-a-list-of-values-in-vars/22452/1 "2016-09-01T14:57:12Z")

</div>

Hi,

Is there a way to do the same as “with\_items” but globally for the playbook?

For example something like :

variable1:

- {url: ‘[http://someting](http://someting)’, dest: ‘something’, src: ‘something’}
- {url: ‘[http://someting2](http://someting2)’, dest: ‘something2’, src: ‘something2’}

and use it like this in the playbook.

- name: Download something  
get\_url:  
url=“{{ variable1.url }}”  
dest=“/tmp/{{ variable1.dest}}”

and in an other place use the same infos

- name: Extract  
unarchive:  
src=/tmp/{{ variable1.src}}  
dest=/tmp/ copy=no

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [September 1, 2016, 5:20pm UTC](https://forum.ansible.com/t/is-there-a-way-to-define-a-list-of-values-in-vars/22452/2 "2016-09-01T17:20:13Z")

</div>

> Hi,
> 
> Is there a way to do the same as "with\_items" but globally for the playbook?
> 
> For example something like :
> 
> variable1:  
> &nbsp;&nbsp;- {url: '[http://someting](http://someting)', dest: 'something', src: 'something'}  
> &nbsp;&nbsp;- {url: '[http://someting2](http://someting2)', dest: 'something2', src: 'something2'}

This will work.

> and use it like this in the playbook.
> 
> &nbsp;&nbsp;- name: Download something  
> &nbsp;&nbsp;&nbsp;&nbsp;get\_url:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url="{{ variable1.url }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest="/tmp/{{ variable1.dest}}"
> 
> and in an other place use the same infos
> 
> - name: Extract  
> &nbsp;&nbsp;&nbsp;&nbsp;unarchive:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src=/tmp/{{ variable1.src}}  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest=/tmp/ copy=no

But this will not. Since it is a list you need to specify which list item you want.

Fist item (someting):  
{{ variable1[0].url }}

Second item (someting2):  
{{ variable1[1].url }}

---

<div class="post-metadata">

**Author:** ![synova.marketing](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@synova.marketing](https://forum.ansible.com/u/synova.marketing)\
**Post date:** [September 2, 2016, 1:47pm UTC](https://forum.ansible.com/t/is-there-a-way-to-define-a-list-of-values-in-vars/22452/3 "2016-09-02T13:47:56Z")

</div>

Hi,

Thank you. I find this way of doing to do what I need with your help :

vars:  
modules:

- {name: ‘test’, url: ‘[https://url](https://url)’, archive: ‘test.ar.gz’}
- {name: ‘test2’, url: ‘[https://url2](https://url2)’, archive: ‘test.zip’}

tasks:

- name: Extract archives  
unarchive:  
src=/tmp/{{ item.archive}}  
dest=/tmp/modules copy=no  
with\_items: “{{ modules }}”
