I am trying to create and update directory permission on my linux machine by using below ansible task but it does not change the ownership properly:
for instance: directory /home/xyz/xyz/{{ IDM }}
and /home/{{ IDM }}
ownership permssion gets reverted to {{ IDM }}:{{ IDM }}
- name: create directory with loop
file:
path: "{{ item.dest }}"
mode: "{{item.mode}}"
owner: "{{ IDM }}"
group: "{{ IDM }}"
recurse: yes
state: directory
loop:
- { dest: '/home/{{ IDM }}', mode: '0755', owner: root, group: root }
- { dest: '/home/{{ IDM }}/.ssh', mode: '0700', owner: "{{ IDM }}", group: "{{ IDM }}" }
- { dest: '/home/{{ IDM }}/to_xyz', mode: '0777', owner: "{{ IDM }}", group: "{{ IDM }}" }
- { dest: '/home/{{ IDM }}/to_xyz/known_customers', mode: '0777', owner: "{{ IDM }}", group: "{{ IDM }}" }
- { dest: '/home/{{ IDM }}/from_xyz', mode: '0777', owner: "{{ IDM }}", group: "{{ IDM }}" }
- { dest: '/home/{{ IDM }}/from_xyz/merchant_invoice', mode: '0777', owner: "{{ IDM }}", group: "{{ IDM }}" }
- { dest: '/home/{{ IDM }}/from_xyz/clearing', mode: '0777', owner: "{{ IDM }}", group: "{{ IDM }}" }
- { dest: '/home/{{ IDM }}/from_xyz/settlement_report', mode: '0777', owner: "{{ IDM }}", group: "{{ IDM }}" }
- { dest: '/home/{{ IDM }}/archive', mode: '0777', owner: "{{ IDM }}", group: "{{ IDM }}" }
- { dest: '/home/{{ IDM }}/archive/settlement_report', mode: '0777', owner: "{{ IDM }}", group: "{{ IDM }}" }
- { dest: '/home/{{ IDM }}/archive/clearing', mode: '0777', owner: "{{ IDM }}", group: "{{ IDM }}" }
- { dest: '/home/{{ IDM }}/archive/dunning', mode: '0777', owner: "{{ IDM }}", group: "{{ IDM }}" }
- { dest: '/home/xyz/xyz/{{ IDM }}', mode: '0755', owner: 'root', group: 'root' }
Well, because you define it as
{{ IDM }}
. Setowner
andgroup
to{{ item.owner }}
and{{ item.group }}
instead.