gpt4 book ai didi

Ansible - 创建多个文件夹(如果不存在)

转载 作者:行者123 更新时间:2023-12-02 19:39:45 24 4
gpt4 key购买 nike

目标:

  • 创建多个目录(如果不存在)。
  • 不要更改现有文件夹的权限

当前的剧本:

    - name: stat directories if they exist
stat:
path: "{{ item }}"
loop:
- /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
loop: "{{ stat.results }}"
when: not myvar.results.stat.exists

when 语句是错误的。

我查看了the example provided 。但这仅适用于单个文件夹。

最佳答案

使用 Ansible 模块,您不需要检查某些东西是否存在,您只需描述所需的状态,因此:

- name: create directory if they don't exist
file:
path: "{{ item }}"
state: directory
owner: root
group: root
mode: 0775
loop:
- /data/directory
- /data/another

关于Ansible - 创建多个文件夹(如果不存在),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42186301/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com