我有以下任务,我无法为数组变量添加循环。 ShopID 被定义为 group_vars 内的一个数组。我的目标是一个一个地调用每个变量。
- name: Create directories with required permission
file:
path: "{{ item.dest }}"
mode: "{{item.mode}}"
owner: "{{ item.owner }}"
group: "{{ item.group }}"
recurse: yes
state: directory
loop:
- { dest: '/home/{{ ShopID }}', mode: '0755', owner: 'root', group: 'root' }
- { dest: '/home/{{ ShopID }}/.ssh', mode: '0700', owner: "{{ ShopID }}", group: "{{ ShopID }}" }
- { dest: '/home/{{ ShopID }}/to_xxx', mode: '0777', owner: "{{ ShopID }}", group: "{{ ShopID }}" }
- { dest: '/home/{{ ShopID }}/to_xxx/known_customers', mode: '0777', owner: "{{ ShopID }}", group: "{{ ShopID }}" }
上述任务的输出是这样的 -
failed: [file.xyz.com] (item={'dest': '/home/[77712351, 77712352]/.ssh', 'mode': '0700', 'owner': [77712351, 77712352], 'group': [77712351, 77712352]}) => {"ansible_loop_var": "item", "changed": false, "gid": 0, "group": "root", "item": {"dest": "/home/[77712351, 77712352]/.ssh", "group": [77712351, 77712352], "mode": "0700", "owner": [77712351, 77712352]}, "mode": "0755", "msg": "chown failed: failed to look up user [77712351, 77712352]", "owner": "root", "path": "/home/[77712351, 77712352]/.ssh", "size": 4096, "state": "directory", "uid": 0}