24cun_cn 发表于 2018-7-30 08:14:03

ansible自己总结(playbook)

#这个是你选择的主机  
- hosts: webservers
  
#这个是变量
  
vars:
  
    http_port: 80
  
    max_clients: 200
  
#远端的执行权限
  
remote_user: root
  
tasks:
  
#利用yum模块来操作
  
- name: ensure apache is at the latest
  
version
  
    yum: pkg=httpd state=latest
  
- name: write the apache config file
  
    template: src=/srv/httpd.j2
  
dest=/etc/httpd.conf
  
#触发重启服务器
  
    notify:
  
    - restart apache
  
- name: ensure apache is running
  
    service: name=httpd state=started
  
#这里的restart
  
apache 和上面的触发是配对的。这就是handlers的作用。相当于tag
  
handlers:
  
    - name: restart apache
  
      service: name=httpd state=restarted
页: [1]
查看完整版本: ansible自己总结(playbook)