语言格式:yml
单个yml文件示例:
--- - hosts: webservers #主机组 vars: ##变量设置 http_port: 80 max_clients: 200 remote_user: root tasks: ###主要任务 - 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 handlers: ##在发生改变时执行的操作 - name: restart apache service: name=httpd state=restarted
‘notify’ 下列出的即是 handlers.
ansible-playbook基本介绍
项目结构:
site.yml webservers.yml fooservers.yml roles/ common/ files/ templates/ tasks/ handlers/ vars/ defaults/ meta/ webservers/ files/ templates/ tasks/ handlers/ vars/ defaults/ meta/