Ansible嵌套循环交叉列表参考?
Ansible nested loop cross list reference?
我正在努力解决这个问题,坦率地说,我开始认为它不会那样工作。
- name: Create directories
file:
path: "{{ item[0] }}"
state: directory
owner: some_user
group: some_group
mode: some_mode
with_nested:
- [ '/var/lib/{{ item[1] }}', '/var/lib/{{ item[1] }}/conf' ]
- [ 'app1', 'app2' ]
显然这里存在范围问题,我只是不明白。
如果不够清楚,我想先创建应用程序目录,然后在每个目录中创建 conf 目录。
提前致谢
创建目录只需要一个循环:
- name: Create directories
file:
path: "/var/lib/{{ item }}/conf"
state: directory
with_items:
- app1
- app2
来自docs:
If state=directory
, all immediate subdirectories will be created if they do not exist, since 1.7 they will be created with the supplied permissions
更新:如果有多个子文件夹(conf、日志等):
- name: Create directories
file:
path: "/var/lib/{{ item[1] }}/{{ item[0] }}"
state: directory
with_nested:
- [ 'conf', 'logs' ]
- [ 'app1', 'app2' ]
我正在努力解决这个问题,坦率地说,我开始认为它不会那样工作。
- name: Create directories
file:
path: "{{ item[0] }}"
state: directory
owner: some_user
group: some_group
mode: some_mode
with_nested:
- [ '/var/lib/{{ item[1] }}', '/var/lib/{{ item[1] }}/conf' ]
- [ 'app1', 'app2' ]
显然这里存在范围问题,我只是不明白。
如果不够清楚,我想先创建应用程序目录,然后在每个目录中创建 conf 目录。
提前致谢
创建目录只需要一个循环:
- name: Create directories
file:
path: "/var/lib/{{ item }}/conf"
state: directory
with_items:
- app1
- app2
来自docs:
If
state=directory
, all immediate subdirectories will be created if they do not exist, since 1.7 they will be created with the supplied permissions
更新:如果有多个子文件夹(conf、日志等):
- name: Create directories
file:
path: "/var/lib/{{ item[1] }}/{{ item[0] }}"
state: directory
with_nested:
- [ 'conf', 'logs' ]
- [ 'app1', 'app2' ]