利用playbook安装和卸载nginx

 安装nginx:

[root@cent7_yzil ansible]# cat install_nginx.yml 
---
# install nginx
- hosts: webservers
  remote_user: root
  gather_facts: no
  force_handlers: yes       #无论task中的任何一个task失败,仍强制调用handlers

  tasks:
     - name: add group nginx
       group: name=nginx state=present
     - name: add user nginx
       user: name=nginx state=present group=nginx
     - name: install nginx
       yum: name=nginx state=present
     - name: config file
       copy: src=files/nginx.conf dest=/etc/nginx/nginx.conf
       tags:conf                #设置便签 
       notify: restart nginx service
     - name: web page
       copy: src=files/index.html dest=/usr/share/nginx/html/index.html
     - name: start nginx
       service: name=nginx state=started enabled=yes

   handlers:
     - name: restart nginx service
       service: name=nginx state=restarted

[root@cent7_yzil ansible]#
[root@cent7_yzil ~]# yum install nginx
[root@cent7_yzil ~]# rpm -ql nginx

/etc/nginx/nginx.conf     #nginx配置文件所在的路径

[root@cent7_yzil ansible]# cp /etc/nginx/nginx.conf files/
[root@cent7_yzil ansible]# vi files/index.html
[root@cent7_yzil ansible]# cat files/index.html 
<h1>
hello world!
</h1>
[root@cent7_yzil ansible]# 

 卸载nginx:

[root@cent7_yzil ansible]# cat remove_nginx.yml 
---
# remove nginx
- hosts: webservers
  gather_facts: no

  tasks:
    - name: stop nginx
      service: name=nginx state=stopped enabled=no
    - name: remove nginx
      yum: name=nginx state=absent
    - name: remove user nginx
      user: name=nginx state=absent
    - name: remove group nginx
      group: name=nginx state=absent
    - name: config file
      file: path=files/nginx.conf state=absent
    - name: web page
      file: path=/usr/share/nginx/html/index.html state=absent
    

[root@cent7_yzil ansible]# 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

y_zilong

一分钱的肯定

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值