安装包nginx官网下载http://nginx.org/
[[email protected] roles]# cat site.yml
[[email protected] roles]# cat nginx/tasks/main.yml
yum: name={{ packages }} state=present
- name: Add Copy Nginx Packages
copy: src=/etc/ansible/roles/nginx/templates/nginx-1.14.2.tar.gz dest=/software/src
shell: cd /software/src;tar -xvf nginx-1.14.2.tar.gz
- name: Add Nginx_module Server
copy: src=/etc/ansible/roles/nginx/templates/nginx-module-vts.tar.gz dest=/software/src
shell: cd /software/src;tar -xvf nginx-module-vts.tar.gz -C /software/
shell: cd /software/src/nginx-1.14.2;./configure --user=www --group=www --with-http_ssl_module --add-module=/software/nginx-module-vts --with-http_stub_status_module --prefix=/software/nginx-1.14.2/;make&& make install
file: src={{ "/software/nginx-1.14.2" }} dest={{ "/software/nginx" }} state=link owner=www group=www
- name: Create Configure Directory
path: /software/nginx/conf/vhosts/
- name: Configure Nginx Server
template: src=/etc/ansible/roles/nginx/templates/nginx.conf.j2 dest=/software/nginx/conf/nginx.conf
shell: cp /software/nginx/sbin/nginx /bin/
- check_nginx.stdout.find( 'successful' )
copy: src=/etc/ansible/roles/nginx/templates/nginx dest=/etc/init.d/
shell: cd /etc/init.d/;chkconfig nginx on
systemd: name=nginx state=started enabled=yes
[[email protected] roles]# cat nginx/templates/nginx
CONFIGFILE=$PATH/conf/$NAME.conf
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
$DAEMON -s stop || echo -n "nginx not running"
$DAEMON -s reload || echo -n "nginx can't reload"
echo -n "Starting $DESC: $NAME"
echo -n "Stopping $DESC: $NAME"
echo -n "Reloading $DESC configuration..."
echo -n "Restarting $DESC: $NAME"