pull/199/head
Szymon Cader 4 years ago
parent 606592e05e
commit 32b172233e
  1. 36
      .travis.yml
  2. 6
      molecule/default/converge.yml
  3. 8
      molecule/default/molecule.yml
  4. 6
      tasks/vhosts.yml
  5. 69
      templates/django-vhost.j2

@ -1,28 +1,38 @@
---
dist: bionic
language: python
services: docker
python: "3.8"
# Use the new container infrastructure
sudo: false
env:
global:
- ROLE_NAME: nginx
matrix:
- MOLECULE_DISTRO: centos7
- MOLECULE_DISTRO: ubuntu1804
- MOLECULE_DISTRO: ubuntu1604
- MOLECULE_DISTRO: debian9
- MOLECULE_DISTRIBUTION: ubuntu18
- MOLECULE_DISTRIBUTION: ubuntu20
- MOLECULE_DISTRIBUTION: debian8
- MOLECULE_DISTRIBUTION: debian9
- MOLECULE_DISTRIBUTION: debian10
# Install ansible
addons:
apt:
packages:
- python-pip
install:
# Install test dependencies.
- pip install molecule yamllint ansible-lint docker
- mv "$PWD" "${PWD%/*}/$ROLE_NAME"
# Install ansible
- pip install ansible molecule docker testinfra pytest pytest-xdist
# Check ansible version
- ansible --version
before_script:
# Use actual Ansible Galaxy role name for the project directory.
- cd ../
- mv ansible-role-$ROLE_NAME geerlingguy.$ROLE_NAME
- cd geerlingguy.$ROLE_NAME
- printf '[defaults]\nroles_path=../' >ansible.cfg
script:
# Run tests.
# Basic role syntax check
- molecule test
notifications:

@ -6,14 +6,14 @@
nginx_use_ppa: true
nginx_remove_default_vhost: true
nginx_vhosts:
- server_name: "test.dev"
- server_name: "localhost"
root: "/var/www/test"
pre_tasks:
- name: Update apt cache.
- name: Update apt cache
apt: update_cache=yes cache_valid_time=600
when: ansible_os_family == 'Debian'
changed_when: false
roles:
- role: geerlingguy.nginx
- role: nginx

@ -5,11 +5,11 @@ driver:
name: docker
lint: |
set -e
yamllint .
ansible-lint
yamllint . -d "{extends: default, ignore: .github}"
ansible-lint -r .
platforms:
- name: instance
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
- name: ${MOLECULE_DISTRIBUTION:-debian10}
image: "nekeal/${MOLECULE_DISTRIBUTION:-debian10}-ansible-systemd:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro

@ -15,7 +15,8 @@
- name: Add managed vhost config files.
template:
src: "{{ item.template|default(nginx_vhost_template) }}"
dest: "{{ nginx_vhost_path }}/{{ item.filename|default(item.server_name.split(' ')[0] ~ '.conf') }}"
dest: "{{ nginx_vhost_path }}/{{ item.filename
| default(item.server_name.split(' ')[0] ~ '.conf') }}"
force: true
owner: root
group: "{{ root_group }}"
@ -28,7 +29,8 @@
- name: Remove managed vhost config files.
file:
path: "{{ nginx_vhost_path }}/{{ item.filename|default(item.server_name.split(' ')[0] ~ '.conf') }}"
path: "{{ nginx_vhost_path }}/{{ item.filename |
default(item.server_name.split(' ')[0] ~ '.conf') }}"
state: absent
when: item.state|default('present') == 'absent'
with_items: "{{ nginx_vhosts }}"

@ -0,0 +1,69 @@
# {{ ansible_managed }}
upstream {{ item.upstream.name }} {
server {{ item.upstream.server }}
}
server {
listen 80;
{% if item.enable_https %}
listen 443 ssl {% if item.enable_http2 %}http2{% endif %};
{% endif %}
server_name {% for server_name in item.server_names %}{{ server_name }} {% endfor %};
{% if item.access_log %}
access_log /var/log/nginx/{{ item.access_log }}.access.log;
{% endif %}
{% if item.error_log %}
error_log /var/log/nginx/{{ app_name }}.error.log;
{% endif %}
{% if item.enable_https %}
if ($scheme = http) {
return 301 https://$host$request_uri;
}
{% endif %}
ssl_certificate {{ item.certificate }};
ssl_certificate_key {{ item.private_key }};
ssl_trusted_certificate {{ item.certificate }};
{% if item.error_page is defined %}
error_page {{ item.error_page }};
{% endif %}
{% if item.static_root %}
location /static/ {
alias {{ item.static_root }};
}
{% endif %}
{% if item.media_root %}
location /media/ {
alias {{ item.media_root }};
}
{% endif %}
{% for location in item.additional_locations | default([]) %}
location {{ location.path }} {
alias {{ location.alias }};
}
{% endfor %}
{% if enable_default_cache %}
location ~* /static/.*\.(js|css)$ {
root {{ directories.project }};
expires 2d;
add_header Cache-Control "public, no-transform";
}
{% endif %}
location / {
proxy_pass {{ item.upstream }};
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
}