Mục tiêu:Ansible - Tạo nhiều thư mục nếu không tồn tại
- Tạo nhiều thư mục nếu họ không tồn tại.
- Không thay đổi quyền truy cập của thư mục hiện
playbook hiện tại:
- name: stat directories if they exist
stat:
path: "{{ item }}"
with_items:
- /data/directory
- /data/another
register: myvar
- debug: var=myvar.results
- name: create directory if they don't exist
file:
path: "{{ item.invocation.module_args.path }}"
state: directory
owner: root
group: root
mode: 0775
with_items: "{{ stat.results }}"
# when: myvar.results.stat.exists == false
Các when
tuyên bố là sai.
Tôi đã xem ví dụ được cung cấp; http://docs.ansible.com/ansible/stat_module.html. Nhưng điều này chỉ hoạt động cho một thư mục duy nhất.
Điều này hy vọng sẽ làm việc cho tất cả –