Skip to content

Instantly share code, notes, and snippets.

@vrutkovs
Created February 16, 2018 12:34
Show Gist options
  • Select an option

  • Save vrutkovs/a3fa9d6bf5bbdae7fefd2bed95edf8fd to your computer and use it in GitHub Desktop.

Select an option

Save vrutkovs/a3fa9d6bf5bbdae7fefd2bed95edf8fd to your computer and use it in GitHub Desktop.
- hosts: localhost
tasks:
- debug:
msg: "nested test a={{ item[0] }} b={{ item[1] }} c={{ item[2] }}"
vars:
elements:
- [ 'red', 'blue', 'green' ]
- [ 1, 2, 3 ]
- [ 'up', 'down', 'strange']
loop: "{{ lookup('nested', elements) }}"
$ pip install --user ansible==2.5.0b2
$ $ ansible-playbook loops.yaml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAY [localhost] ******************************************************************************************************************************************************************************
TASK [Gathering Facts] ************************************************************************************************************************************************************************
ok: [localhost]
TASK [debug] **********************************************************************************************************************************************************************************
ok: [localhost] => (item=[u'red', u'blue', u'green']) => {
"changed": false,
"failed": false,
"item": [
"red",
"blue",
"green"
],
"msg": "nested test a=red b=blue c=green"
}
ok: [localhost] => (item=[1, 2, 3]) => {
"changed": false,
"failed": false,
"item": [
1,
2,
3
],
"msg": "nested test a=1 b=2 c=3"
}
ok: [localhost] => (item=[u'up', u'down', u'strange']) => {
"changed": false,
"failed": false,
"item": [
"up",
"down",
"strange"
],
"msg": "nested test a=up b=down c=strange"
}
PLAY RECAP ************************************************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0
- hosts: localhost
tasks:
- shell: echo "nested test a={{ item[0] }} b={{ item[1] }} c={{ item[2] }}"
with_nested:
- [ 'red', 'blue', 'green' ]
- [ 1, 2, 3 ]
- [ 'up', 'down', 'strange']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment