Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
554 views
in Technique[技术] by (71.8m points)

ansible - Check folders permission with loop

My current playbook is working but it is not checking the folders group permissions recursively. It only checks at the last level of the folder hierarchy (e.g. /*/bin, /*/sbin ...)

How can I modify my below playbook sot that it checks folder permissions on the entire path ?

    - name: Ensure system directories are owned by root group.
      block: 
        - name: Verify the command directories exist.
          become: true
          stat:
            path: "{{ item }}"
          loop:
            - /bin/
            - /sbin/
            - /usr/bin/
            - /usr/sbin/
            - /usr/local/bin
            - /usr/local/sbin
          register: command_directories
        
        - name: Verify command directories belong to root.
          loop: |
            {{ command_directories.results|map(attribute='item')|zip(command_directories.results|map(attribute='stat.gr_name'))|list }}
    
          assert:
            that: item.1 == 'root'
          loop_control:
            label: "{{ item.0 }}"
    
        - set_fact:
            stig_text: "PASSED"
        
      rescue:
    
        - name: configure the command directories ownership to root and create if it doesn't exist.
          become: true
          file:
            path: "{{ item.item }}"
            group: root
            state: "{{ 'directory' if item.stat.exists else 'touch' }}"
            recurse: yes
          loop: "{{ command_directories.results }}"
          register: file_perms_rule 
      
        - set_fact:
            stig_text: "PASSED"
          when: file_perms_rule.changed

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...