ansible template用法

template作为ansible重要的企业实战解决方案。

变量文件引入

touch vars.yml

1
2
3
4
5
6
7
8
9
10
11
12
---
- hosts: websrvs
remote_user: root
vars_files:
- vars.yml

tasks:
- name: install package
yum: name={{ vars1 }}

- name: create file
file: name=/data/{{ var2 }}.log state=touch

template使用,变量优先级

1
2
3
-e
current playbook
hosts

when条件的使用

在task后添加when子句可使用条件测试。
when os_type == "linux"