Ansible安裝Nginx

1、要作什麼先把思惟導圖畫出來
Ansible安裝Nginxhtml

Ansible安裝Nginx
2、接下來咱們開始根據本身的思惟去寫東西
```

(base) [root@bogon ansible]# cat site.yaml

  • hosts: ceshi
    roles:
    • nginx
(base) [root@bogon nginx]# cat files/index.html 
user ansible install nginx
(base) [root@bogon nginx]# cat handlers/main.yaml 
---
- name: restart nginx
  service: name=nginx state=restarted
(base) [root@bogon nginx]# cat tasks/main.yaml 

---
- name: install nginx packages
  yum: name={{ item }} state=latest
  with_items:
    - epel-release
    - nginx

- name: copy nginx.conf template
  template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf
  notify: restart nginx

- name: copy index.html
  copy: src=index.html dest=/usr/share/nginx/html/index.html

- name: make sure nginx service running
  service: name=nginx state=started
(base) [root@bogon nginx]# cat templates/nginx.conf.j2 
在隨便一個地方複製粘貼過來nginx.conf一份便可修更名字爲nginx.conf.j2,修改nginx.conf.j2文件中的worker_connectios定義爲變量 以下
events {
    worker_connections {{worker_connections}};
}
(base) [root@bogon nginx]# cat vars/main.yaml 
worker_connections: 10240

而後執行:
Ansible安裝Nginx
這裏的主機在hosts文件定義:hosts文件和入口文件平級,而後在瀏覽器訪問
Ansible安裝Nginx
nginx驗證成功ios

3、問題1:若是安裝的時候碰到這個問題
Ansible安裝Nginx
不要亂百度去了下邊就是解決這個問題的關鍵,上邊提示install nginx packages錯誤那就是執行with_items安裝的時候出錯了,在目標服務器安裝一下源就行了
yum install epel-release
到此問題解決接下來在執行一遍就能夠安裝成功。nginx

自學ansible跟着我: 拎壺沖沖衝瀏覽器

相關文章
相關標籤/搜索