- 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
最新推荐文章于 2024-07-17 15:51:59 发布