(4)playbook

Playbook syntax: pay attention to spaces, not the tab key

1) Example 1: Install apache

#vim apache.yml 
- hosts: 192.168.1.31
  tasks:
  - name: Install Apache Package
    yum: name=httpd state=latest

  - name: Copy Apache Conf
    copy: src=/tmp/httpd.conf dest=/etc/httpd/conf/httpd.conf
    notify: Restart Apache Service

  - name: Start Apache
    service: name=httpd state=started enabled=yes

  handlers:
  - name: Restart Apache Service
    service: name=httpd state=restarted
说明:
目标主机是:192.168.1.31
安装httpd,把本地/tmp/httpd.conf文件拷贝到目标主机指定目录
启动httpd和开机启动
handlers:处理方式(重启httpd)
notify动作:当copy文件改变的时候,会触发处理方式handlers(重启httpd)
ansible-playbook apache.yml --syntax-check              //检测语法
ansible-playbook apache.yml                                        //执行playbook文件

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325651790&siteId=291194637