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跟着我: 拎壶冲冲冲浏览器