ansible - 使用循环检查文件夹权限
问题描述
我当前的剧本正在运行,但它没有递归检查文件夹组权限。它只检查文件夹层次结构的最后一级(例如/*/bin
, /*/sbin
...)
如何修改下面的剧本以便检查整个路径上的文件夹权限?
- 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
解决方案
推荐阅读
- opendaylight - 编译 Opendaylight Fluorine 的 hello world 示例时出错 - yang 工具问题
- javascript - Get all the Child Elements and push it into array
- java - 在给定大小的单元格java中间绘制字符串
- python - 如何准确测量在 python 3.7 中返回值的函数的 cpu 时间?
- c# - 如何从 gziptream 生成的字节数组创建 gz zip 文件
- react-native - Redux Store 更新但 mapStateToProps 中没有更新状态
- ios - How to shorten build time of Flutter iOS app using fastlane
- c++ - How I can use Keyboard interaction in this code
- ios - Set color for all UINavigationBars
- amazon-cloudformation - 删除 CloudFormation 堆栈时“Route53 更改无法传播”失败