使用Ansible部署Nginx
来源:互联网 发布:洛枳扮演者晁然淘宝店 编辑:程序博客网 时间:2024/06/05 07:01
基于学习的目的,演示使用ansible往远程linux服务器上部署nginx。
创建playbook相关目录和文件
mkdir ansible-studymkdir -p ansible-study/filesmkdir -p ansible-study/templatestouch ansible-study/hoststouch ansible-study/web-notls.yml
创建主部署文件web-notls.yml
文件路径:./playbook/ansible-nginx
- name: Configure webserver with nginx hosts: webservers sudo: True tasks: - name: Nginx Install rpm yum: name: http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm - name: Nginx install nginx yum: name: nginx state: latest - name: copy nginx config file copy: src=files/nginx.conf dest=/etc/nginx/sites-available/default - name: copy index.html template: src: templates/index.html.j2 dest: /usr/share/nginx/html/index.html mode: 0644 - name: restart nginx service: name=nginx state=restarted
编辑一个nginx配置文件
运行Playbook之前,它还需要2个额外的文件,首先,需要定义个nginx的配置文件
通常来讲,Ansible会将一般文件放在名为files的子目录中,将Jinja2模版文件放在名为templates的子目录中。
文件路径:./playbook/ansible-nginx/files
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/html index index.html index.htm; server_name localhost; location / { try_files $uri $uri/ = 404; }}
创建一个定制的首页
添加一个定制的首页,用来测试Nginx的服务正常与否。
文件路径:./playbook/ansible-nginx/templates
<html> <head> <title>Welcome to ansible</title> </head> <body> <h1>nginx,configured by Ansible</h1> <p>If you can see this,Ansible successfully installed nginx.</p> <p>{{ ansible_managed }}</p> </body></html>
运行playbook,部署nginx
执行playbook需要使用ansible-playbook命令,按照如下方法运行playbook
LS-MacBook-Pro:ansible-study wangzhen$ ansible-playbook web-notls.yml[DEPRECATION WARNING]: Instead of sudo/sudo_user, use become/become_user and make sure become_method is 'sudo' (default).This feature will be removed in a future release. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.PLAY [Configure webserver with nginx] **********************************************************************************************************************TASK [Gathering Facts] *************************************************************************************************************************************ok: [testserver]TASK [Nginx Install rpm] ***********************************************************************************************************************************ok: [testserver]TASK [Nginx install nginx] *********************************************************************************************************************************ok: [testserver]TASK [copy nginx config file] ******************************************************************************************************************************ok: [testserver]TASK [copy index.html] *************************************************************************************************************************************changed: [testserver]TASK [restart nginx] ***************************************************************************************************************************************changed: [testserver]PLAY RECAP *************************************************************************************************************************************************testserver : ok=6 changed=2 unreachable=0 failed=0
测试nginx
阅读全文
0 0
- 使用Ansible部署Nginx
- ansible-playbook批量部署nginx
- Ansible一键部署Flask(nginx+Uwsgi)
- ansible 自动编译部署 nginx详解
- 使用 Ansible 安装部署 TiDB
- ansible使用playbook安装nginx
- Ansible部署
- Django使用nginx部署
- 使用原子主机、Ansible 和 Cockpit 部署容器
- 使用原子主机、Ansible 和 Cockpit 部署容器
- 使用原子主机、Ansible 和 Cockpit 部署容器
- 在Ubuntu 14.04上使用Ansible部署PHP应用
- Ansible自动化运维工具部署及使用
- ansible使用
- ansible使用
- OpenStack-Ansible自动化部署
- ansible安装部署
- ansible自动化部署
- Redis-AOF持久化
- Codeforces Round #421 A. Mister B and Book Reading
- Web 请求过程
- Github没有记录Contributions的原因及解决方案
- 每日一题——栈实现队列,队列实现栈
- 使用Ansible部署Nginx
- Spring源码(一) 源码转换eclipse工程
- 【Java Utility】Jsoup网页爬虫工具--设置Element的HTML内容【十二】
- Codeforces Round #422 A. I'm bored with life
- mysql学生选课
- 【JavaScript的条件操作符】
- 探索ES6 Iterator(遍历器)
- 栈的应用
- Struts framework的工作原理和组件