664/775 권한이 필요한 디렉토리를 제외하고 기본값이 기본값으로 644 (디렉토리의 경우 755)가되도록 Ansible을 사용하여 디렉토리 트리에 권한을 설정하는 방법을 알아 내려고합니다.
순진한 구현은 다음과 같습니다.
file:
path: "mypath"
mode: "u+rwX,go+rX,go-w"
recurse: True
file:
path: "mypath/exception"
mode: "g+w"
recurse: True
그러나 이것은 분명히 멱 등성이 아닙니다. 실행할 때마다 mypath / exception은 그룹 쓰기 권한이 제거 된 다음 즉시 다시 추가됩니다.
대안은 mypath / *에있는 각 개별 하위 디렉토리를 열거하는 것입니다.
멱 등성 방식으로 이것을 수행하는 다른 방법이 있습니까?
find
모듈을 사용하여 경로 목록을 생성 한 다음을 사용하는 대신 해당 경로에서 작업 할 수 recurse
있습니다. 예를 들면 :
---
- hosts: localhost
gather_facts: false
tasks:
- find:
paths:
- mypath
recurse: true
file_type: any
register: results
- file:
path: "{{ item.path }}"
mode: "u+rwX,go+rX,go-w"
when: >-
"mypath/exception" not in item.path
loop: "{{ results.files }}"
loop_control:
label: "{{ item.path }}"
- file:
path: "{{ item.path }}"
mode: "g+w"
when: >-
"mypath/exception" in item.path
loop: "{{ results.files }}"
loop_control:
label: "{{ item.path }}"
샘플 디렉토리 트리에 대해 위의 플레이 북을 실행하면 다음과 같은 결과가 나타납니다.
PLAY [localhost] ******************************************************************************
TASK [find] ***********************************************************************************
ok: [localhost]
TASK [file] ***********************************************************************************
skipping: [localhost] => (item=mypath/exception)
ok: [localhost] => (item=mypath/dir2)
ok: [localhost] => (item=mypath/dir3)
skipping: [localhost] => (item=mypath/exception/file3)
skipping: [localhost] => (item=mypath/exception/file2)
skipping: [localhost] => (item=mypath/exception/file1)
ok: [localhost] => (item=mypath/dir2/dirc)
ok: [localhost] => (item=mypath/dir2/dira)
ok: [localhost] => (item=mypath/dir2/dirb)
ok: [localhost] => (item=mypath/dir2/dirc/somefile)
ok: [localhost] => (item=mypath/dir2/dira/somefile)
ok: [localhost] => (item=mypath/dir2/dirb/somefile)
ok: [localhost] => (item=mypath/dir3/dirc)
ok: [localhost] => (item=mypath/dir3/dira)
ok: [localhost] => (item=mypath/dir3/dirb)
ok: [localhost] => (item=mypath/dir3/dirc/somefile)
ok: [localhost] => (item=mypath/dir3/dira/somefile)
ok: [localhost] => (item=mypath/dir3/dirb/somefile)
TASK [file] ***********************************************************************************
ok: [localhost] => (item=mypath/exception)
skipping: [localhost] => (item=mypath/dir2)
skipping: [localhost] => (item=mypath/dir3)
ok: [localhost] => (item=mypath/exception/file3)
ok: [localhost] => (item=mypath/exception/file2)
ok: [localhost] => (item=mypath/exception/file1)
skipping: [localhost] => (item=mypath/dir2/dirc)
skipping: [localhost] => (item=mypath/dir2/dira)
skipping: [localhost] => (item=mypath/dir2/dirb)
skipping: [localhost] => (item=mypath/dir2/dirc/somefile)
skipping: [localhost] => (item=mypath/dir2/dira/somefile)
skipping: [localhost] => (item=mypath/dir2/dirb/somefile)
skipping: [localhost] => (item=mypath/dir3/dirc)
skipping: [localhost] => (item=mypath/dir3/dira)
skipping: [localhost] => (item=mypath/dir3/dirb)
skipping: [localhost] => (item=mypath/dir3/dirc/somefile)
skipping: [localhost] => (item=mypath/dir3/dira/somefile)
skipping: [localhost] => (item=mypath/dir3/dirb/somefile)
PLAY RECAP ************************************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0
이 플레이 북 은 적절하게 멱 등성을 갖습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다