利用playbook安装和卸载nginx

Posted y_zilong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了利用playbook安装和卸载nginx相关的知识,希望对你有一定的参考价值。

 安装nginx

[root@cent7_yzil ansible]# cat install_nginx.yml 
---
# install nginx
- hosts: webservers
  remote_user: root
  gather_facts: no

  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
     - 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
[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]# 

 

以上是关于利用playbook安装和卸载nginx的主要内容,如果未能解决你的问题,请参考以下文章

使用playbook安装nginx

使用playbook实现一键安装nginx+PHP

Ansible使用playbook批量安装Nginx

playbook实现nginx安装

ansible-playbook 远程安装nginx

ansible的playbook进行yum批量安装nginx最新版本