这是一个很好的输出示例,您可以尝试一下。创建一个新的剧本,名为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
然后像这样运行剧本:
ansible-playbook -i '172.16.222.131,' iteration_loop.yml
并且输出应该给您如何访问项目:
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
shell
模块,因为我需要执行递归ACL,而acl
模块不支持。