Nginx with Ansible

Ansible deployment server

======================================================================

[root@aserver ~]# ansible –version
ansible 2.2.0.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
======================================================================
[root@aserver ~]# mkdir -p ansible-nginx/tasks/

[root@aserver ~]# touch ansible-nginx/deploy.yml

[root@aserver ~]# touch ansible-nginx/tasks/install_nginx.yml

[root@aserver ~]# tree ansible-nginx/
ansible-nginx/
|– deploy.yml
`– tasks
`– install_nginx.yml

[root@aserver ~]# vim $HOME/ansible-nginx/deploy.yml
– hosts: nginx
tasks:
– include: ‘tasks/install_nginx.yml’

[root@aserver ~]# vim /etc/ansible/hosts
[nginx]
bserver.example.org

[root@aserver ~]# vim ansible-nginx/tasks/install_nginx.yml
– name: NGINX | Installing NGINX repo rpm
yum:
name: http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

– name: NGINX | Installing NGINX
yum:
name: nginx
state: latest

– name: NGINX | Starting NGINX
service:
name: nginx
state: started
======================================================================
[root@aserver ~]# ansible-playbook ansible-nginx/deploy.yml

PLAY [nginx] *******************************************************************

TASK [setup] *******************************************************************
ok: [bserver.example.org]

TASK [NGINX | Installing NGINX repo rpm] ***************************************
changed: [bserver.example.org]

TASK [NGINX | Installing NGINX] ************************************************
changed: [bserver.example.org]

TASK [NGINX | Starting NGINX] **************************************************
changed: [bserver.example.org]

PLAY RECAP *********************************************************************
bserver.example.org : ok=4 changed=3 unreachable=0 failed=0
======================================================================
[root@aserver ~]# curl -Is bserver.example.org
HTTP/1.1 200 OK
Server: nginx/1.10.2
Date: Wed, 16 Nov 2016 10:49:38 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 18 Oct 2016 16:37:29 GMT
Connection: keep-alive
ETag: “58064fc9-264”
Accept-Ranges: bytes
=================================================

                             On remote server

[root@bserver ~]# netstat -tlpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2958/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 963/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2052/master
tcp6 0 0 :::22 :::* LISTEN 963/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2052/master
===========================================================
[root@bserver ~]# service nginx status
Redirecting to /bin/systemctl status nginx.service
● nginx.service – nginx – high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2016-11-16 05:47:36 EST; 12min ago
Docs: http://nginx.org/en/docs/
Process: 2956 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Process: 2954 ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Main PID: 2958 (nginx)
CGroup: /system.slice/nginx.service
├─2958 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
└─2959 nginx: worker process

Nov 16 05:47:36 bserver.example.org systemd[1]: Starting nginx – high performance web server…
Nov 16 05:47:36 bserver.example.org nginx[2954]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Nov 16 05:47:36 bserver.example.org nginx[2954]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Nov 16 05:47:36 bserver.example.org systemd[1]: Failed to read PID from file /run/nginx.pid: Invalid argument
Nov 16 05:47:36 bserver.example.org systemd[1]: Started nginx – high performance web server.
===========================================================
[root@bserver ~]# service nginx stop
Redirecting to /bin/systemctl stop nginx.service

[root@bserver ~]# service nginx status
Redirecting to /bin/systemctl status nginx.service
● nginx.service – nginx – high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: http://nginx.org/en/docs/

Nov 16 05:47:36 bserver.example.org systemd[1]: Starting nginx – high performance web server…
Nov 16 05:47:36 bserver.example.org nginx[2954]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Nov 16 05:47:36 bserver.example.org nginx[2954]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Nov 16 05:47:36 bserver.example.org systemd[1]: Failed to read PID from file /run/nginx.pid: Invalid argument
Nov 16 05:47:36 bserver.example.org systemd[1]: Started nginx – high performance web server.
Nov 16 06:00:50 bserver.example.org systemd[1]: Stopping nginx – high performance web server…
Nov 16 06:00:50 bserver.example.org systemd[1]: Stopped nginx – high performance web server.
===========================================================

 Ansible deployment server

 [root@aserver ~]# ansible-playbook ansible-nginx/deploy.yml

PLAY [nginx] *******************************************************************

TASK [setup] *******************************************************************
ok: [bserver.example.org]

TASK [NGINX | Installing NGINX repo rpm] ***************************************
ok: [bserver.example.org]

TASK [NGINX | Installing NGINX] ************************************************
ok: [bserver.example.org]

TASK [NGINX | Starting NGINX] **************************************************
changed: [bserver.example.org]

PLAY RECAP *********************************************************************
bserver.example.org : ok=4 changed=1 unreachable=0 failed=0

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s