I have below task and I am failing to add the loop for the array variable. ShopID is defined as an array inside group_vars. My aim is to call each variable one by one.
- 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 }}" }
Output for the above task is something like this-
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}
Put the task into a file, e.g.
and include it in the loop
gives