一、要做什么先把思维导图画出来
```
(base) [root@bogon ansible]# cat site.yaml
- hosts: ceshi
roles:
(base) [root@bogon Nginx]# cat files/index.html
user ansible install Nginx
(base) [root@bogon Nginx]# cat handlers/main.yaml
---
- name: restart Nginx
service: name=Nginx state=restarted
(base) [root@bogon Nginx]# cat tasks/main.yaml
---
- name: install Nginx packages
yum: name={{ item }} state=latest
with_items:
- epel-release
- Nginx
- name: copy Nginx.conf template
template: src=Nginx.conf.j2 dest=/etc/Nginx/Nginx.conf
notify: restart Nginx
- name: copy index.html
copy: src=index.html dest=/usr/share/Nginx/html/index.html
- name: make sure Nginx service running
service: name=Nginx state=started
(base) [root@bogon Nginx]# cat templates/Nginx.conf.j2
在随便一个地方复制粘贴过来Nginx.conf一份即可修改名字为Nginx.conf.j2,修改Nginx.conf.j2文件中的worker_connectios定义为变量 如下
events {
worker_connections {{worker_connections}};
}
(base) [root@bogon Nginx]# cat vars/main.yaml
worker_connections: 10240
然后执行:
三、问题1:如果安装的时候碰到这个问题
不要乱百度去了下边就是解决这个问题的关键,上边提示install Nginx packages错误那就是执行with_items安装的时候出错了,在目标服务器安装一下源就好了
yum install epel-release
到此问题解决接下来在执行一遍就可以安装成功。
自学ansible跟着我: 拎壶冲冲冲
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。