我正在尝试使用以下 ansible 任务在我的 linux 机器上创建和更新目录权限,但它没有正确更改所有权:
例如:目录/home/xyz/xyz/{{ IDM }}
和/home/{{ IDM }}
所有权权限恢复为{{ 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' }
好吧,因为您将其定义为
{{ IDM }}
. 设置owner
和group
改为{{ item.owner }}
和{{ item.group }}
。