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

22 views
Skip to first unread message

synova.m...@gmail.com

unread,
Sep 1, 2016, 11:55:00 AM9/1/16
to Ansible Project
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', dest: 'something', src: 'something'}
  - {url: '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



Kai Stian Olstad

unread,
Sep 1, 2016, 1:20:50 PM9/1/16
to ansible...@googlegroups.com
On 01. sep. 2016 16:57, synova.m...@gmail.com wrote:
> 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', dest: 'something', src: 'something'}
> - {url: 'http://someting2', dest: 'something2', src: 'something2'}

This will work.


> 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

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 }}

--
Kai Stian Olstad

synova.m...@gmail.com

unread,
Sep 2, 2016, 9:47:57 AM9/2/16
to Ansible Project
Hi,

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

vars:
  modules:
    - {name: 'test', url: 'https://url', archive: 'test.ar.gz'}
    - {name: 'test2', url: 'https://url2', archive: 'test.zip'}

tasks:
  - name: Extract archives
    unarchive:
      src=/tmp/{{ item.archive}}
      dest=/tmp/modules copy=no
    with_items: "{{ modules }}"
Reply all
Reply to author
Forward
0 new messages