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

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

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

@ -15,7 +15,8 @@
- name: Add managed vhost config files. - name: Add managed vhost config files.
template: template:
src: "{{ item.template|default(nginx_vhost_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 force: true
owner: root owner: root
group: "{{ root_group }}" group: "{{ root_group }}"
@ -28,7 +29,8 @@
- name: Remove managed vhost config files. - name: Remove managed vhost config files.
file: 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 state: absent
when: item.state|default('present') == 'absent' when: item.state|default('present') == 'absent'
with_items: "{{ nginx_vhosts }}" 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;
}
}