ansible playbook 学习
同时创建多个目录的yml,1
2
3
4
5
6
7
8
9
- hosts: testhost
vars_files:
- /tmp/vars.yml
tasks:
- name: use disk name make dir
command:mkdir -p "/tmp/{{ dict_1.a }}/{{ dict_1.b }}/{{ dict_1.c }}"
"/tmp/{{ dict_2['a'] }}/{{ dict_2['b'] }}/{{ dict_2['c'] }}"
"/tmp/{{ list_1 }}/{{ list_1 }}/{{ list_1 }}"
"/tmp/{{ list_2 }}/{{ list_2 }}/{{ list_2 }}"
额外变量文件 vars.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
---
dict_1: #yml 注释可以随便折腾
a: AA #缩进必须用空格
b: BB
c: CC
dict_2: { a: D1, b: D1, c: D1 }#字典也可以这样
list_1:
- 11
- 22
- 33
list_2: [ L1, L2, L3 ] #列表也可以这样
结果:
1
2
3
4
5
6
7
8
root@svntest:/tmp# ll
total 40
drwxrwxrwx6 root root 20480 May 17 14:14 ./
drwxr-xr-x 24 root root4096 Dec 182013 ../
drwxr-xr-x3 root root4096 May 17 14:14 11/
drwxr-xr-x3 root root4096 May 17 14:14 AA/
drwxr-xr-x3 root root4096 May 17 14:14 D1/
drwxr-xr-x3 root root4096 May 17 14:14 L1/
附:jinja2讲法
Yaml说明
Yaml在线解析
页:
[1]