标签:htm install 角色 handler 设置 logs ping ssi ansi
playbook是一个或多个“paly”组成的列表。play的主要功能在于将事先并归为一组的主机扮成事先通过ansible中task定义好的角色,从根本上将,所谓的task就是调用ansible的一个module。将多个play组织的一个playbook中就可以让它们连同起来按事先安排的机制同唱一台大戏。
/etc/ansible/playbooks/nginx.yml

分析
1、定义了执行的远程主机是 webservers组,这个组定义主机有(192.168.88.2,192.168.88.3)
2、定义了变量,这个变量可以运用到我们模板文件中(nginx2.conf)
3、定义了远程主机执行任务的是用户root
remote_usery也可用于各task中,支持通过sudo的方式在远程主机上执行任务,其可用于play全局后某任务;此外,设置可以在sudo时使用sudo_user指定sudo时切换的用户
- hosts: webnodes
remote_user: heboan
tasks:
- name: test connection
ping:
remote_user: heboan
sudo: yes
4、任务列表:定义了5个任务
①create directory /data/www
②copy index.html
③install nginx is at the latest version
④start nginx
⑤write the nginx config file
其中任务⑤是替换配置文件,我们都知道nginx配置文件变更需要重启才会生效,所以这里关联了一个[restart nginx]的handlers
5、因为有关联操作,所以我们需要定义handlers
模板文件(/etc/ansible/templates/nginx/nginx2.conf)
注意(第14行我忘记了分号结尾,需要补上)

分析:
我们这个模板用到了我们在nginx.yml中定义的变量
运行剧本

包含文件,鼓励复用
当多个playbook涉及复用的任务列表时,可以将复用的内容剥离出来,写到独立的文档当中最后在需要的地方include进来即可。示例如下:
【tasks/foo.yml】 --- # possibly saved as tasks/foo.yml - name: placeholder foo command: /bin/foo - name: placeholder bar command: /bin/bar 然后就可以在使用的playbook中include进来,如: tasks: - include: tasks/foo.yml
标签:htm install 角色 handler 设置 logs ping ssi ansi
原文地址:http://www.cnblogs.com/sellsa/p/7793465.html