ansible-07-实战部署nginx
Posted shark_西瓜甜
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ansible-07-实战部署nginx相关的知识,希望对你有一定的参考价值。
- name: 部署 nginx
hosts: node1
gather_facts: no
vars:
main_conf: nginx.conf.j2
sub_conf: default.conf
tasks:
- name: 传输仓库文件
copy:
src: nginx.repo
dest: /etc/yum.repos.d/nginx.repo
- name: 安装 nginx
yum: name=nginx state=present
- name: 利用模板文件,设置主配置文件
template:
src: "{{ main_conf }}"
dest: /etc/nginx/nginx.conf
tags: update
# 触发任务
notify: reload nginx server
- name: 子配置文件
copy:
src: "{{ sub_conf }}"
dest: /etc/nginx/conf.d/
tags: update
notify: reload nginx server
- name: check nginx syntax
shell: /usr/sbin/nginx -t
register: nginxsyntax
tags: update
- name: 启动 nginx 服务
when: nginxsyntax.rc == 0
systemd: name=nginx state=started
handlers:
- name: reload nginx server
when:
- nginxsyntax.rc == 0
systemd: name=nginx state=reloaded
以上是关于ansible-07-实战部署nginx的主要内容,如果未能解决你的问题,请参考以下文章