为什么要写这个脚本?因为加入有些主机创建的用户已存在就会报错
[root@cml1tasks]# cat /opt/create_users.sh
#!/bin/bash
a=`cat/etc/passwd | grep nginx | wc -l`
if [ $a == 0];then
useradd nginx
fi
6、第二行copy对应file目录:
[root@cml1nginx_install]# cd files/
[root@cml1files]# ls
nginx-1.12.0.tar.gz
7、template这一行对应的是template这个目录和主服务端定义的变量:
[root@cml1nginx_install]# cd templates/
[root@cml1templates]# ls
nginx.conf
[root@cml1templates]# cat nginx.conf
user nginx;
worker_processes {{ ansible_processor_vcpus }};
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user[$time_local] "$request" '
# '$status $body_bytes_sent"$http_referer" '
# '"$http_user_agent""$http_x_forwarded_for"';
log_format xiaoluo '$remote_addr -$remote_user [$time_local] '
'"$request" $status$body_bytes_sent '
'"$http_referer" "$http_user_agent" ';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen {{ ngxport }};
server_name wwwNaNl.com
access_log logs/wwwNaNl.com xiaoluo;
#location / {
# proxy_pass ;
#}
#error_page 404 /404.html;
# redirect server error pages to thestatic page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apachelistening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass ;
#}
# pass the PHP scripts to FastCGIserver listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /web;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME$document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, ifApache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
include vhosts/*.conf;
}##需要注意的就是模板变量(客户端自动采集)、和在服务端定义的变量{{ngx_port}}
8、在vars定义变量:
[root@cml1nginx_install]# cd vars/
[root@cml1vars]# cat main.yml
ngxport:"8080"
9、定义触发器:
[root@cml1nginx_install]# cd handlers/
[root@cml1handlers]# cat main.yml
- name: startnginx service
shell: /usr/loal/nginx/sbin/nginx