目录所有者权限无法通过 ansible 循环正确更新

目录所有者权限无法通过 ansible 循环正确更新

我正在尝试使用以下 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' }

答案1

嗯,因为你将它定义为{{ IDM }}。将owner和设置group{{ item.owner }}{{ item.group }}

- name: create directory with loop
  file:
    path: "{{ item.dest }}"
    mode: "{{ item.mode }}"
    owner: "{{ item.owner }}"
    group: "{{ item.group }}"
    recurse: yes
    state: directory

相关内容