我有几个用户的 homedir,例如 /home/user1 /home/user2 /home/user(n-1)
我需要 ansible 来获取主目录列表并在每个主目录中以正确的权限创建文件。
现在我有了这个剧本
---
- hosts: pc070
tasks:
- name: Find home
find:
paths: /home
recurse: no
file_type: directory
register: homedir
- name: Create temp directory
file:
path: "{{ item.path }}/temp"
state: directory
with_items:
"{{ homedir.files }}"
但是我得到了 root 所有者的目录
答案1
嗯,很简单
---
- hosts: pc070
tasks:
- name: Find home
find:
paths: /home
recurse: no
file_type: directory
register: homedir
- name: Create ASS directory
file:
path: "{{ item.path }}/bigboobsinside"
state: directory
with_items:
"{{ homedir.files }}"
- name: Set permission
file:
path: "{{ item.path }}"
state: directory
recurse: yes
owner: "{{ item.path | basename }}"
group: "domain users"
with_items:
"{{ homedir.files }}"