Skip to content

Commit

Permalink
Merge pull request #13 from hispanico/enable-http2-over-https
Browse files Browse the repository at this point in the history
Enable http2 over https and switch to molecule role test
  • Loading branch information
hispanico authored Dec 27, 2019
2 parents e5d9f1f + 0bdee7e commit bc17d52
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 68 deletions.
58 changes: 22 additions & 36 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,32 @@
---
os: linux
language: python
python: "2.7"

sudo: required
dist: xenial

# Install ansible
addons:
apt:
packages:
- python-pip
services: docker

env:
global:
- ROLE_NAME: nginx-revproxy
jobs:
# - MOLECULE_DISTRO: centos7
- MOLECULE_DISTRO: ubuntu1604
- MOLECULE_DISTRO: ubuntu1804
- MOLECULE_DISTRO: debian9
- MOLECULE_DISTRO: debian10

install:
# Install ansible
- pip install ansible
# Install test dependencies.
- pip install molecule docker

# Check ansible version
- ansible --version

# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg
before_script:
# Use actual Ansible Galaxy role name for the project directory.
- cd ../
- mv ansible-$ROLE_NAME hispanico.$ROLE_NAME
- cd hispanico.$ROLE_NAME

script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check

# Run the role/playbook with ansible-playbook
- ansible-playbook tests/test.yml -i tests/inventory --connection=local --become

# Run the role/playbook again, checking to make sure it's idempotent
- >
ansible-playbook tests/test.yml -i tests/inventory --connection=local --become
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
# Check for role is done
- sudo service nginx status
- sudo netstat -ntulp |grep nginx
- sudo ls /etc/nginx/sites-enabled/
- for i in $(sudo ls /etc/nginx/sites-enabled/); do echo $i;echo "------------------------------"; sudo cat /etc/nginx/sites-enabled/$i; echo "------------------------------";echo ""; done

# Run tests.
- molecule test
- pip install https://github.com/openwisp/openwisp-utils/tarball/master

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
4 changes: 2 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ nginx_revproxy_sites: # List of sites to
- example.com
- www.example.com
upstreams: # List of Upstreams
- { backend_address: 192.168.0.100, backend_port: 80 }
- { backend_address: 192.168.0.101, backend_port: 8080 }
- {backend_address: 192.168.0.100, backend_port: 80}
- {backend_address: 192.168.0.101, backend_port: 8080}
ssl: true # Set to True if you want to redirect http to https
hsts_max_age: 63072000 # Set HSTS header with max-age defined
letsencrypt: false # Set to True if you want use letsencrypt
Expand Down
26 changes: 15 additions & 11 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---

galaxy_info:
author: Hispanico
description: Manage Nginx as Reverse Proxy
Expand All @@ -6,18 +8,20 @@ galaxy_info:
min_ansible_version: 2.4

platforms:
- name: Ubuntu
versions:
- trusty
- xenial
- name: Debian
versions:
- all
- name: Ubuntu
versions:
- all

galaxy_tags:
- development
- web
- nginx
- reverse
- proxy
- load
- balancer
- development
- web
- nginx
- reverse
- proxy
- load
- balancer

dependencies: []
31 changes: 31 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
options:
config-file: molecule/default/yaml-lint.yml
enabled: true
platforms:
- name: "${ROLE_NAME}-${MOLECULE_DISTRO:-centos7}"
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- /var/lib/docker
privileged: true
pre_build_image: true
provisioner:
name: ansible
lint:
name: ansible-lint
playbooks:
converge: ${MOLECULE_PLAYBOOK:-playbook.yml}
scenario:
name: default
verifier:
name: testinfra
lint:
name: flake8
26 changes: 26 additions & 0 deletions molecule/default/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: Converge
hosts: all
become: true

pre_tasks:
- name: Install cron (RedHat).
yum:
name: cronie
state: present
when: ansible_os_family == 'RedHat'

- name: Install cron (Debian).
apt:
name: cron
state: present
when: ansible_distribution == 'Debian'

- name: Update apt cache.
apt:
update_cache: true
cache_valid_time: 600
when: ansible_distribution == 'Ubuntu'

roles:
- role: hispanico.nginx-revproxy
6 changes: 6 additions & 0 deletions molecule/default/yaml-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
extends: default
rules:
line-length:
max: 150
level: warning
2 changes: 1 addition & 1 deletion tasks/letsencrypt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- name: Get Active Sites
command: ls -1 /etc/nginx/sites-enabled/
changed_when: "active.stdout_lines != nginx_revproxy_sites.keys()|sort()"
check_mode: no
check_mode: false
register: active
tags:
- lesencrypt
Expand Down
10 changes: 5 additions & 5 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
- name: Install python-passlib for Python 3 hosts
apt:
name:
- "python3-passlib"
- "python3-passlib"
state: present
tags:
- nginxrevproxy
Expand All @@ -32,7 +32,7 @@
- name: Install python-passlib for Python 2 hosts
apt:
name:
- "python-passlib"
- "python-passlib"
state: present
tags:
- nginxrevproxy
Expand Down Expand Up @@ -99,7 +99,7 @@
- name: Get Active Sites
command: ls -1 /etc/nginx/sites-enabled/
changed_when: "active.stdout_lines != nginx_revproxy_sites.keys()|sort()"
check_mode: no
check_mode: false
register: active
tags:
- nginxrevproxy
Expand Down Expand Up @@ -150,7 +150,7 @@
state: directory
owner: www-data
group: www-data
recurse: yes
recurse: true
with_dict: "{{ nginx_revproxy_sites }}"
notify: Reload Nginx
when:
Expand All @@ -161,7 +161,7 @@
- name: Get WebRoot Sites
command: ls -1 /var/www/
changed_when: "webroot.stdout_lines != nginx_revproxy_sites.keys()|sort()"
check_mode: no
check_mode: false
register: webroot
tags:
- nginxrevproxy
Expand Down
9 changes: 5 additions & 4 deletions templates/reverseproxy_ssl.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ server {
}

server {
listen {{ item.value.listen_ssl | default(443) }} ssl default_server;
listen [::]:{{ item.value.listen_ssl | default(443) }} ssl default_server;
listen {{ item.value.listen_ssl | default(443) }} ssl http2 default_server;
listen [::]:{{ item.value.listen_ssl | default(443) }} ssl http2 default_server;
server_name _;
return 444;

Expand All @@ -33,6 +33,7 @@ server {
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
}

{% else %}
upstream {{ item.key }}_backend {
{% for upstream in item.value.upstreams %}
Expand All @@ -58,8 +59,8 @@ server {
}

server {
listen {{ item.value.listen_ssl | default(443) }} ssl;
listen [::]:{{ item.value.listen_ssl | default(443) }} ssl;
listen {{ item.value.listen_ssl | default(443) }} ssl http2;
listen [::]:{{ item.value.listen_ssl | default(443) }} ssl http2;
server_name {{ item.value.domains | join(' ') }};

{% if item.value.hsts_max_age is defined %}
Expand Down
4 changes: 2 additions & 2 deletions templates/reverseproxy_ssl_letsencrypt.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ server {
}

server {
listen {{ item.value.listen_ssl | default(443) }} ssl;
listen [::]:{{ item.value.listen_ssl | default(443) }} ssl;
listen {{ item.value.listen_ssl | default(443) }} ssl http2;
listen [::]:{{ item.value.listen_ssl | default(443) }} ssl http2;
server_name {{ item.value.domains | join(' ') }};

{% if item.value.hsts_max_age is defined %}
Expand Down
1 change: 0 additions & 1 deletion tests/inventory

This file was deleted.

6 changes: 0 additions & 6 deletions tests/test.yml

This file was deleted.

0 comments on commit bc17d52

Please sign in to comment.