Skip to content
This repository was archived by the owner on Feb 13, 2023. It is now read-only.

Commit 576164d

Browse files
committed
Fixes #1329: Update nginx role to latest version.
1 parent bd6ba69 commit 576164d

File tree

15 files changed

+142
-80
lines changed

15 files changed

+142
-80
lines changed

provisioning/requirements.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
- src: geerlingguy.mysql
3939
version: 2.7.2
4040
- src: geerlingguy.nginx
41-
version: 2.0.0
41+
version: 2.2.0
4242
- src: geerlingguy.nodejs
4343
version: 4.1.0
4444
- src: geerlingguy.php
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.retry
2+
tests/test.sh

provisioning/roles/geerlingguy.nginx/.travis.yml

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,28 @@ services: docker
33

44
env:
55
- distro: centos7
6-
init: /usr/lib/systemd/systemd
7-
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
86
- distro: ubuntu1604
9-
init: /lib/systemd/systemd
10-
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
117
- distro: ubuntu1404
12-
init: /sbin/init
13-
run_opts: ""
148
- distro: ubuntu1204
15-
init: /sbin/init
16-
run_opts: ""
17-
18-
before_install:
19-
# Pull container.
20-
- 'docker pull geerlingguy/docker-${distro}-ansible:latest'
219

2210
script:
23-
- container_id=$(mktemp)
24-
# Run container in detached state.
25-
- 'docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} geerlingguy/docker-${distro}-ansible:latest "${init}" > "${container_id}"'
11+
# Configure test script so we can run extra tests after playbook is run.
12+
- export container_id=$(date +%s)
13+
- export cleanup=false
2614

27-
# Ansible syntax check.
28-
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --syntax-check'
15+
# Download test shim.
16+
- wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/
17+
- chmod +x ${PWD}/tests/test.sh
2918

30-
# Test role.
31-
- 'docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml'
19+
# Run tests.
20+
- ${PWD}/tests/test.sh
3221

33-
# Test role idempotence.
34-
- idempotence=$(mktemp)
35-
- docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml | tee -a ${idempotence}
36-
- >
37-
tail ${idempotence}
38-
| grep -q 'changed=0.*failed=0'
39-
&& (echo 'Idempotence test: pass' && exit 0)
40-
|| (echo 'Idempotence test: fail' && exit 1)
22+
# Setup test site.
23+
- 'docker exec ${container_id} mkdir -p /var/www/test'
24+
- 'docker exec ${container_id} bash -c "echo Success >| /var/www/test/index.html"'
4125

42-
# Check if nginx is running.
43-
# TODO
26+
# Make sure virtualhost exists.
27+
- 'docker exec --tty ${container_id} env TERM=xterm curl http://test.dev/ | grep "Success"'
4428

4529
notifications:
4630
webhooks: https://galaxy.ansible.com/api/v1/notifications/
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2017 Jeff Geerling
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
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, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

provisioning/roles/geerlingguy.nginx/README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-nginx.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-role-nginx)
44

5-
Installs Nginx on RedHat/CentOS or Debian/Ubuntu Linux, or FreeBSD servers.
5+
Installs Nginx on RedHat/CentOS or Debian/Ubuntu Linux, FreeBSD or OpenBSD servers.
66

7-
This role installs and configures the latest version of Nginx from the Nginx yum repository (on RedHat-based systems) or via apt (on Debian-based systems) or pkgng (on FreeBSD systems). You will likely need to do extra setup work after this role has installed Nginx, like adding your own [virtualhost].conf file inside `/etc/nginx/conf.d/`, describing the location and options to use for your particular website.
7+
This role installs and configures the latest version of Nginx from the Nginx yum repository (on RedHat-based systems) or via apt (on Debian-based systems) or pkgng (on FreeBSD systems) or pkg_add (on OpenBSD systems). You will likely need to do extra setup work after this role has installed Nginx, like adding your own [virtualhost].conf file inside `/etc/nginx/conf.d/`, describing the location and options to use for your particular website.
88

99
## Requirements
1010

@@ -16,7 +16,7 @@ Available variables are listed below, along with default values (see `defaults/m
1616

1717
nginx_vhosts: []
1818

19-
A list of vhost definitions (server blocks) for Nginx virtual hosts. If left empty, you will need to supply your own virtual host configuration. See the commented example in `defaults/main.yml` for available server options. If you have a large number of customizations required for your server definition(s), you're likely better off managing the vhost configuration file yourself, leaving this variable set to `[]`.
19+
A list of vhost definitions (server blocks) for Nginx virtual hosts. Each entry will create a separate config file named by `server_name`. If left empty, you will need to supply your own virtual host configuration. See the commented example in `defaults/main.yml` for available server options. If you have a large number of customizations required for your server definition(s), you're likely better off managing the vhost configuration file yourself, leaving this variable set to `[]`.
2020

2121
nginx_vhosts:
2222
- listen: "80 default_server"
@@ -26,6 +26,7 @@ A list of vhost definitions (server blocks) for Nginx virtual hosts. If left emp
2626
error_page: ""
2727
access_log: ""
2828
error_log: ""
29+
state: "present"
2930
extra_parameters: |
3031
location ~ \.php$ {
3132
fastcgi_split_path_info ^(.+\.php)(/.+)$;
@@ -43,17 +44,13 @@ Please take note of the indentation in the above block. The first line should be
4344

4445
Whether to remove the 'default' virtualhost configuration supplied by Nginx. Useful if you want the base `/` URL to be directed at one of your own virtual hosts configured in a separate .conf file.
4546

46-
nginx_vhosts_filename: "vhosts.conf"
47-
48-
The filename to use to store vhosts configuration. If you run the role multiple times (e.g. include the role with `with_items`), you can change the name for each run, effectively creating a separate vhosts file per vhost configuration.
49-
5047
nginx_upstreams: []
5148

5249
If you are configuring Nginx as a load balancer, you can define one or more upstream sets using this variable. In addition to defining at least one upstream, you would need to configure one of your server blocks to proxy requests through the defined upstream (e.g. `proxy_pass http://myapp1;`). See the commented example in `defaults/main.yml` for more information.
5350

5451
nginx_user: "nginx"
5552

56-
The user under which Nginx will run. Defaults to `nginx` for RedHat, and `www-data` for Debian.
53+
The user under which Nginx will run. Defaults to `nginx` for RedHat, `www-data` for Debian and `www` on FreeBSD and OpenBSD.
5754

5855
nginx_worker_processes: "{{ ansible_processor_vcpus|default(ansible_processor_count) }}"
5956
nginx_worker_connections: "1024"

provisioning/roles/geerlingguy.nginx/defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ nginx_extra_http_options: ""
5050
# proxy_set_header Host $http_host;
5151

5252
nginx_remove_default_vhost: false
53-
nginx_vhosts_filename: "vhosts.conf"
5453
nginx_vhosts: []
5554
# Example vhost below, showing all available options:
5655
# - listen: "80 default_server" # default: "80 default_server"
@@ -63,6 +62,7 @@ nginx_vhosts: []
6362
# access_log: ""
6463
# error_log: ""
6564
# extra_parameters: "" # Can be used to add extra config blocks (multiline).
65+
# state: "absent" # To remove the vhost configuration.
6666

6767
nginx_upstreams: []
6868
# - name: myapp1

provisioning/roles/geerlingguy.nginx/meta/main.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ dependencies: []
33

44
galaxy_info:
55
author: geerlingguy
6-
description: Nginx installation for Linux and FreeBSD.
6+
description: Nginx installation for Linux, FreeBSD and OpenBSD.
77
company: "Midwestern Mac, LLC"
88
license: "license (BSD, MIT)"
99
min_ansible_version: 1.8
@@ -25,6 +25,10 @@ galaxy_info:
2525
- 10.1
2626
- 10.0
2727
- 9.3
28+
- name: OpenBSD
29+
versions:
30+
- 5.9
31+
- 6.0
2832
galaxy_tags:
2933
- development
3034
- web

provisioning/roles/geerlingguy.nginx/tasks/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
- include: setup-FreeBSD.yml
2222
when: ansible_os_family == 'FreeBSD'
2323

24+
- include: setup-OpenBSD.yml
25+
when: ansible_os_family == 'OpenBSD'
26+
2427
# Vhost configuration.
2528
- include: vhosts.yml
2629

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- name: Ensure nginx is installed.
3+
openbsd_pkg:
4+
name: "{{ nginx_package_name }}"
5+
state: present
6+
7+
- name: Create logs directory.
8+
file:
9+
path: /var/log/nginx
10+
state: directory

provisioning/roles/geerlingguy.nginx/tasks/vhosts.yml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,28 @@
1212
state: directory
1313
notify: reload nginx
1414

15-
- name: Add managed vhost config file (if any vhosts are configured).
15+
- name: Add managed vhost config files.
1616
template:
17-
src: vhosts.j2
18-
dest: "{{ nginx_vhost_path }}/{{ nginx_vhosts_filename }}"
17+
src: vhost.j2
18+
dest: "{{ nginx_vhost_path }}/{{ item.server_name.split(' ')[0] }}.conf"
19+
force: yes
20+
owner: root
21+
group: root
1922
mode: 0644
20-
when: nginx_vhosts|length > 0
23+
when: item.state|default('present') != 'absent'
24+
with_items: "{{ nginx_vhosts }}"
2125
notify: reload nginx
2226

23-
- name: Remove managed vhost config file (if no vhosts are configured).
27+
- name: Remove managed vhost config files.
2428
file:
25-
path: "{{ nginx_vhost_path }}/{{ nginx_vhosts_filename }}"
29+
path: "{{ nginx_vhost_path }}/{{ item.server_name.split(' ')[0] }}.conf"
30+
state: absent
31+
when: item.state|default('present') == 'absent'
32+
with_items: "{{ nginx_vhosts }}"
33+
notify: reload nginx
34+
35+
- name: Remove legacy vhosts.conf file.
36+
file:
37+
path: "{{ nginx_vhost_path }}/vhosts.conf"
2638
state: absent
27-
when: nginx_vhosts|length == 0
2839
notify: reload nginx

0 commit comments

Comments
 (0)