为了避免重复地输入命令,ansible提供了脚本功能
yaml和json类似,是一种表示数据的文本格式
执行脚本playbook的方法
```
ansible-playbook deploy.yml
```
playbook包括几个关键字
hosts 主机ip
remote_user 以某个用户身份执行
vars 变量
tasks 核心,定义顺序执行的动作Action
handlers event处理操作,有且仅有在被Action触发时才会执行
以下为一个例子
```
tr@tr-desktop:~$ cat deploy.yaml
---
- hosts: host
vars:
http_port: 80
max_clients: 200
remote_user: tr
tasks:
- name: ensure apache is at the lastest version
apt: pkg=httpd state=latest
- name: write the configuration file
template: src=/etc/hosts dest=/tmp/test.conf
notify:
- restart apache
- name: ensure apache is running
service: name=httpd state=started
handlers:
- name: restart apache
service: name=httpd state=restarted
```