Skip to content

Commit 40ab5b4

Browse files
author
Pablo Castillo
committed
Nginx Role:
* Removed old daemon script to be replaced by upstart script * Removed old default SSL Server block * Updated Readme * Adding Version number to meta file * Replaced tags with when statements for better control of running tasks * Added SSL configurations for better SSL performance and security * Added License * Seperated tasks into specific yaml files * Added a series of new server block files for better customization * Added Test suite for Circle integration * Added default vars to role * Added Sudoers tasks * Added Logrotate task
1 parent e4da6c5 commit 40ab5b4

24 files changed

+325
-279
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 Crush & Lovely, Pablo Castillo
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Ansible Role For NGINX
22

3-
[![Build Status](http://img.shields.io/travis/crushlovely/ansible-nginx.svg?style=flat)](https://travis-ci.org/crushlovely/ansible-nginx)
3+
[[![Build Status](https://img.shields.io/circleci/project/crushlovely/ansible-nginx.svg?style=flat)](https://github.com/crushlovely/ansible-nginx)
44
[![Current Version](http://img.shields.io/github/release/crushlovely/ansible-nginx.svg?style=flat)](https://galaxy.ansible.com/list#/roles/1180)
55

66
This Ansible role that installs `nginx` and its dependencies:
@@ -14,24 +14,24 @@ This Ansible role that installs `nginx` and its dependencies:
1414
* `zlib1g`
1515
* `zlib1g-dev`
1616

17-
This role requires self-signed certs placed in `files/ssl` or third-party certs placed in `{{ app_name }}/files/ssl/` (found in the root of the ansible roles directory).
17+
This role requires self-signed certs placed in `files/ssl` or third-party certs placed in `{{ app_name }}/files/ssl/` (found in the root of the ansible roles directory). This role also has the option to install Nginx with the passenger module.
1818

19-
Finally it sets the default timezone for the server. We use this as the base image for all our Ruby and Node.js applications.
2019

2120
## Installation
2221

2322
``` bash
24-
$ ansible-galaxy install crushlovely.nginx
23+
$ ansible-galaxy install crushlovely.nginx, v1.0.0
2524
```
2625

2726
## Variables
2827

2928
``` yaml
30-
nginx_version: 1.6.2
3129
app_name: **name of your app**
32-
upstream_port: 8080
33-
domains:
34-
- "domain.com"
30+
nginx:
31+
version: 1.6.2
32+
upstream_port: 8080
33+
domains:
34+
- "domain.com"
3535
```
3636
3737
## Usage
@@ -41,7 +41,7 @@ Once this role is installed on your system, include it in the roles list of your
4141
``` yaml
4242
- hosts: localhost
4343
roles:
44-
- { role: crushlovely.nginx, ssl: 'yes' }
44+
- { role: crushlovely.nginx, nginx.ssl: 'true', nginx.passenger: 'true', nginx.custom: 'true' }
4545
```
4646
You can also add a vars folder to your project folder and have your variables served by adding them to a file and calling it in your playbook.
4747

circle.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
machine:
3+
python:
4+
version: 2.7.9
5+
ruby:
6+
version: 2.1.3
7+
dependencies:
8+
pre:
9+
- sudo apt-get update -qq
10+
- sudo apt-get install -qq python-apt python-pycurl aptitude python-software-properties python-pip python-dev git
11+
- sudo apt-get update -qq
12+
- gem install rake
13+
- sudo gem install rake
14+
15+
# Install Ansible.
16+
- pip install ansible==1.9.0.1
17+
18+
# Add ansible.cfg to pick up roles path.
19+
- "printf '[defaults]\nroles_path = ../' > ansible.cfg"
20+
21+
test:
22+
override:
23+
# Get nginx role
24+
- ansible-galaxy install -f https://github.com/crushlovely/ansible-nginx.git,remotes/origin/$CIRCLE_BRANCH -p ./tests/roles/
25+
26+
# Check the role/playbook's syntax.
27+
- ansible-playbook --syntax-check -i tests/inventory tests/test.yml
28+
29+
# Check the role/playbook's syntax.
30+
- ansible-playbook -i tests/inventory tests/test.yml:
31+
timeout: 900
32+
33+
# Idempotence Test
34+
- "ansible-playbook -i tests/inventory tests/test.yml | grep -q 'changed=3.*failed=0' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1)"

defaults/main.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
app_name: test
3+
app_path: /srv/test/public
4+
ssl: 'false'
5+
passenger: 'true'
6+
updates: 'true'
7+
custom: 'true'
8+
nginx:
9+
version: 1.6.2
10+
upstream_port: 5000
11+
user: ubuntu
12+
group: ubuntu
13+
passenger:
14+
version: 5.0.6
15+
prestart: http://test.com
16+
domains: test.com
17+
server_env: production

files/nginx

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/var/log/nginx/*.log {
2+
weekly
3+
missingok
4+
rotate 52
5+
compress
6+
delaycompress
7+
notifempty
8+
create 0640 www-data adm
9+
sharedscripts
10+
prerotate
11+
if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
12+
run-parts /etc/logrotate.d/httpd-prerotate; \
13+
fi \
14+
endscript
15+
postrotate
16+
[ -s /run/nginx.pid ] && kill -USR1 `cat /run/nginx.pid`
17+
endscript
18+
}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
#!upstart
22
description "Upstart Script for a NGINX process"
3-
author "Philipp Klose & Pablo Castillo"
3+
author "Philipp Klose"
44

55
start on (filesystem and net-device-up IFACE=lo)
66
stop on runlevel [!2345]
77

88
env DAEMON=/usr/sbin/nginx
9-
env PID=/opt/nginx/logs/nginx.pid
9+
env PID=/var/run/nginx.pid
1010

1111
expect fork
1212
respawn
1313
respawn limit 10 5
1414
#oom never
1515

1616
pre-start script
17+
/bin/bash <<EOT
1718
$DAEMON -t
1819
if [ $? -ne 0 ]
1920
then exit $?
2021
fi
22+
EOT
2123
end script
2224

23-
exec $DAEMON
25+
exec $DAEMON
26+
27+
pre-stop script
28+
/bin/bash <<EOT
29+
exec start-stop-daemon --stop --pidfile $PID --name nginx --exec $DAEMON --signal QUIT
30+
EOT
31+
end script

files/passenger-path.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export PATH=:/opt/passenger/bin:$PATH

files/sudoers

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# This file MUST be edited with the 'visudo' command as root.
3+
#
4+
# Please consider adding local content in /etc/sudoers.d/ instead of
5+
# directly modifying this file.
6+
#
7+
# See the man page for details on how to write a sudoers file.
8+
#
9+
Defaults env_reset
10+
Defaults mail_badpass
11+
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/passenger/bin"
12+
13+
# Host alias specification
14+
15+
# User alias specification
16+
17+
# Cmnd alias specification
18+
19+
# User privilege specification
20+
root ALL=(ALL:ALL) ALL
21+
22+
# Members of the admin group may gain root privileges
23+
%admin ALL=(ALL) ALL
24+
25+
# Allow members of group sudo to execute any command
26+
%sudo ALL=(ALL:ALL) ALL
27+
28+
# See sudoers(5) for more information on "#include" directives:
29+
30+
#includedir /etc/sudoers.d

meta/main.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ galaxy_info:
88
platforms:
99
- name: Ubuntu
1010
versions:
11-
- precise
11+
- Precise
12+
- Trusty
1213
categories:
1314
- development
1415
- web
1516
- system
1617
dependencies: []
18+
version: 1.0.0

tasks/custom.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
- name: Create Sites Enabled Directory
3+
file: path=/etc/nginx/sites-enabled state=directory owner=root group=root
4+
sudo: yes
5+
6+
- name: Apply defaultserver conf file
7+
template: src=defaultserver.j2 dest=/etc/nginx/sites-enabled/zzzzzdefaultserver owner=root group=root
8+
sudo: yes
9+
10+
- name: Apply site conf file
11+
template: src=site.com.j2 dest=/etc/nginx/sites-enabled/{{ app_name }} owner=root group=root
12+
sudo: yes
13+
when: passenger == "false"
14+
15+
- name: Apply Passenger site conf file
16+
template: src=passenger.site.j2 dest=/etc/nginx/sites-enabled/{{ app_name }} owner=root group=root
17+
sudo: yes
18+
when: passenger == "true"
19+
20+
- name: Custom Config template placement
21+
template: src=passenger.conf.j2 dest=/etc/nginx/conf.d/passenger.conf owner=root group=root
22+
sudo: yes
23+
when: passenger == "true"

0 commit comments

Comments
 (0)