1、要作什麼先把思惟導圖畫出來html
(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
而後執行:
這裏的主機在hosts文件定義:hosts文件和入口文件平級,而後在瀏覽器訪問
nginx驗證成功ios
3、問題1:若是安裝的時候碰到這個問題
不要亂百度去了下邊就是解決這個問題的關鍵,上邊提示install nginx packages錯誤那就是執行with_items安裝的時候出錯了,在目標服務器安裝一下源就行了yum install epel-release
到此問題解決接下來在執行一遍就能夠安裝成功。nginx
自學ansible跟着我: 拎壺沖沖衝瀏覽器