安装nginx:
[root@cent7_yzil ansible]# cat install_nginx.yml
---
# install nginx
- hosts: webserversremote_user: rootgather_facts: noforce_handlers: yes #无论task中的任何一个task失败,仍强制调用handlerstasks:- name: add group nginxgroup: name=nginx state=present- name: add user nginxuser: name=nginx state=present group=nginx- name: install nginxyum: name=nginx state=present- name: config filecopy: src=files/nginx.conf dest=/etc/nginx/nginx.conftags:conf #设置便签 notify: restart nginx service- name: web pagecopy: src=files/index.html dest=/usr/share/nginx/html/index.html- name: start nginxservice: name=nginx state=started enabled=yeshandlers:- name: restart nginx serviceservice: 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
hello world!
[root@cent7_yzil ansible]#
卸载nginx:
[root@cent7_yzil ansible]# cat remove_nginx.yml
---
# remove nginx
- hosts: webserversgather_facts: notasks:- name: stop nginxservice: name=nginx state=stopped enabled=no- name: remove nginxyum: name=nginx state=absent- name: remove user nginxuser: name=nginx state=absent- name: remove group nginxgroup: name=nginx state=absent- name: config filefile: path=files/nginx.conf state=absent- name: web pagefile: path=/usr/share/nginx/html/index.html state=absent[root@cent7_yzil ansible]#
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!