我想在目录树中递归地更改文件的权限。文件数量有数千个。
我现在在我的剧本上做了以下事情
- name: find all the files inside the wordpress directory
find:
path: /home/vagrant/wordpress
file_type: file
recurse: true
register: files_found
- name: Ensure permissions on folders are in 644
file:
path: "{{ item['path'] }}"
mode: '0644'
loop: "{{ files_found['files'] }}"
由于目录结构中存在大量文件,这需要“无限”的时间。
command
find
命令的 Ansible exec
模块真的是最好的选择吗?由于具有
file
模块和 loop
、 的解决方案
不可行,因为
目前只剩下一个使用
command
模块,就像最小的例子中那样
---
- hosts: localhost
become: false
gather_facts: false
tasks:
- name: Recursively ensure file permissions in a directory
ansible.builtin.command:
cmd: find {{ path }} -type f -printf "%p\n" -exec chmod {{ mode }} {} \;
vars:
path: /home/ansible_user/test
mode: '0644'
register: files
- debug:
var: files.stdout_lines
或