Este é um bom exemplo de saída que você mesmo pode experimentar.
Crie um novo manual chamado iteration_loop.yml
:
---
- name: Change mod/own
hosts: all
tasks:
- name: show me the iterations
debug: msg={{ item.0.username }} {{ item.1.path }} then {{ item.1.permissions }} {{ item.1.path }}
with_subelements:
- users
- directories
vars:
users:
- username: bar
directories:
- path: /data
permissions: rX
- path: /js
permissions: rX
- username: foo
directories:
- path: /
permissions: rwX
Em seguida, execute o manual assim:
ansible-playbook -i '172.16.222.131,' iteration_loop.yml
e a saída deve fornecer a você como os itens são acessados:
PLAY [Change mod/own] *********************************************************
GATHERING FACTS ***************************************************************
ok: [172.16.222.131]
TASK: [show me the iterations] ************************************************
ok: [172.16.222.131] => (item=({'username': 'bar'}, {'path': '/data', 'permissions': 'rX'})) => {
"item": [
{
"username": "bar"
},
{
"path": "/data",
"permissions": "rX"
}
],
"msg": "bar"
}
ok: [172.16.222.131] => (item=({'username': 'bar'}, {'path': '/js', 'permissions': 'rX'})) => {
"item": [
{
"username": "bar"
},
{
"path": "/js",
"permissions": "rX"
}
],
"msg": "bar"
}
ok: [172.16.222.131] => (item=({'username': 'foo'}, {'path': '/', 'permissions': 'rwX'})) => {
"item": [
{
"username": "foo"
},
{
"path": "/",
"permissions": "rwX"
}
],
"msg": "foo"
}
PLAY RECAP ********************************************************************
172.16.222.131 : ok=2 changed=0 unreachable=0 failed=0