Ansible

目錄所有者權限未通過 ansible 循環正確更新

  • January 18, 2022

我正在嘗試使用以下 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 }}. 設置ownergroup改為{{ 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

引用自:https://serverfault.com/questions/1090344