微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Ansible安装Nginx

一、要做什么先把思维导图画出来

Ansible安装Nginx

Ansible安装Nginx

二、接下来我们开始根据自己的思维去写东西
```

(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

后执行

Ansible安装Nginx

这里的主机在hosts文件定义:hosts文件和入口文件平级,然后在浏览器访问

Ansible安装Nginx

Nginx验证成功

三、问题1:如果安装的时候碰到这个问题

Ansible安装Nginx


不要乱百度去了下边就是解决这个问题的关键,上边提示install Nginx packages错误那就是执行with_items安装的时候出错了,在目标服务器安装一下源就好了
yum install epel-release
到此问题解决接下来在执行一遍就可以安装成功。

自学ansible跟着我: 拎壶冲冲冲

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐