(4)playbook

playbook语法:注意空格,不能是tab键

1)例1:安装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文件

猜你喜欢

转载自www.cnblogs.com/lovelinux199075/p/9004657.html