Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: HanXHX/ansible-nginx
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.4.1
Choose a base ref
...
head repository: HanXHX/ansible-nginx
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
Showing with 2,141 additions and 1,325 deletions.
  1. +4 −0 .ansible-lint
  2. +43 −0 .github/workflows/ci.yml
  3. +17 −0 .github/workflows/galaxy.yml
  4. +43 −0 .github/workflows/molecule.yml
  5. +2 −0 .gitignore
  6. +0 −57 .travis.yml
  7. +6 −0 .yamllint.yml
  8. +41 −13 README.md
  9. +18 −14 Vagrantfile
  10. +16 −2 defaults/main.yml
  11. +0 −5 doc/auth.md
  12. +0 −6 doc/freebsd.md
  13. +6 −7 doc/php.md
  14. +87 −18 doc/site.md
  15. +31 −7 doc/ssl.md
  16. +0 −2 doc/upstream.md
  17. +50 −2 filter_plugins/nginx.py
  18. +1 −16 filter_plugins/php.py
  19. +6 −34 handlers/main.yml
  20. +30 −19 meta/main.yml
  21. +19 −0 molecule/_shared/Dockerfile.j2
  22. +39 −0 molecule/_shared/base.yml
  23. +20 −0 molecule/_shared/converge.yml
  24. +19 −0 molecule/_shared/file/test.crt
  25. +28 −0 molecule/_shared/file/test.key
  26. +15 −0 molecule/_shared/prepare.yml
  27. +7 −0 molecule/_shared/requirements.yml
  28. +16 −0 molecule/_shared/templates/custom_template.conf.j2
  29. +259 −0 molecule/_shared/vars/misc.yml
  30. +19 −0 molecule/_shared/verify.yml
  31. +13 −0 molecule/debian-10/molecule.yml
  32. +13 −0 molecule/debian-11/molecule.yml
  33. +13 −0 molecule/debian-12/molecule.yml
  34. 0 molecule/default/.gitkeep
  35. +20 −0 molecule/ubuntu-20.04/molecule.yml
  36. +13 −0 molecule/ubuntu-22.04/molecule.yml
  37. +4 −0 requirements.yml
  38. +26 −13 tasks/config.yml
  39. +9 −9 tasks/htpasswd.yml
  40. +27 −0 tasks/install/Debian.yml
  41. +19 −19 tasks/{install_FreeBSD.yml → install/FreeBSD.yml}
  42. +36 −0 tasks/install/acme.yml
  43. +8 −0 tasks/install/main.yml
  44. +0 −67 tasks/install_Debian.yml
  45. +15 −15 tasks/main.yml
  46. +21 −8 tasks/prepare.yml
  47. +48 −29 tasks/site.yml
  48. +93 −53 tasks/ssl/acme.yml
  49. +4 −4 tasks/ssl/main.yml
  50. +64 −31 tasks/ssl/standard.yml
  51. +14 −15 tasks/upstream.yml
  52. +18 −0 templates/etc/nginx/conf.d/FAKESITE.conf.j2
  53. +1 −1 templates/etc/nginx/conf.d/_upstream.conf.j2
  54. +13 −4 templates/etc/nginx/conf.d/php.conf.j2
  55. +15 −8 templates/etc/nginx/helper/ssl-legacy.j2
  56. +12 −7 templates/etc/nginx/helper/ssl-strong.j2
  57. +3 −2 templates/etc/nginx/nginx.conf.j2
  58. +0 −33 templates/etc/nginx/sites-available/_backuppc.j2
  59. +73 −39 templates/etc/nginx/sites-available/_base.j2
  60. +0 −59 templates/etc/nginx/sites-available/_nagios3.j2
  61. +2 −14 templates/etc/nginx/sites-available/_php.j2
  62. +1 −2 templates/etc/nginx/sites-available/_php_index.j2
  63. +2 −3 templates/etc/nginx/sites-available/_php_index2.j2
  64. +27 −0 templates/etc/nginx/sites-available/_symfony.j2
  65. +252 −0 tests/group_vars/all.yml
  66. +0 −19 tests/includes/post_Debian.yml
  67. +0 −32 tests/includes/post_FreeBSD.yml
  68. +262 −0 tests/includes/post_common.yml
  69. +56 −73 tests/includes/pre_Debian.yml
  70. +22 −21 tests/includes/pre_FreeBSD.yml
  71. +46 −5 tests/includes/pre_common.yml
  72. +16 −0 tests/templates/custom_template.conf.j2
  73. +11 −526 tests/test.yml
  74. +2 −5 vars/Debian.yml
  75. +2 −4 vars/FreeBSD.yml
  76. +3 −3 vars/main.yml
4 changes: 4 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

enable_list:
- fqcn-builtins
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---

name: ci
'on':
pull_request:
push:
branches:
- master

jobs:

yaml-lint:
name: YAML Lint
runs-on: ubuntu-latest
steps:

- name: Fetch code
uses: actions/checkout@v3

- name: Set up Python 3.
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install test dependencies.
run: pip3 install yamllint

- name: Lint code.
run: |
yamllint .
ansible-lint:
name: Ansible Lint
runs-on: ubuntu-latest

steps:
- name: Fetch code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Run ansible-lint
uses: ansible/ansible-lint-action@v6.15.0
17 changes: 17 additions & 0 deletions .github/workflows/galaxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---

name: Deploy on Ansible Galaxy

'on':
- push

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: galaxy
uses: robertdebock/galaxy-action@1.2.0
with:
galaxy_api_key: ${{ secrets.galaxy_api_key }}
43 changes: 43 additions & 0 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---

name: Molecule

'on':
pull_request:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
scenario:
- debian-10
- debian-11
- debian-12
- ubuntu-22.04
allowed-to-fail:
- false
include:
- scenario: ubuntu-20.04
allowed-to-fail: true

steps:
- name: Checkout
uses: actions/checkout@v3
with:
path: "${{ github.repository }}"

- name: Molecule
uses: gofrolist/molecule-action@v2.3.19
with:
molecule_options: --base-config molecule/_shared/base.yml
molecule_args: --scenario-name ${{ matrix.scenario }}
molecule_working_dir: "HanXHX/ansible-nginx"
continue-on-error: ${{ matrix.allowed-to-fail }}

- name: Fake command
run: echo "End of job"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -2,3 +2,5 @@
*.swp
*.retry
*.pyc
/tests/hanxhx.php
/.idea
57 changes: 0 additions & 57 deletions .travis.yml

This file was deleted.

6 changes: 6 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

extends: default

rules:
line-length: disable
54 changes: 41 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Nginx for Debian/FreeBSD Ansible role
=====================================

[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.nginx-blue.svg)](https://galaxy.ansible.com/HanXHX/nginx/) [![Build Status](https://travis-ci.org/HanXHX/ansible-nginx.svg?branch=master)](https://travis-ci.org/HanXHX/ansible-nginx)
[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.nginx-blue.svg)](https://galaxy.ansible.com/HanXHX/nginx/) ![GitHub Workflow Status (master branch)](https://img.shields.io/github/actions/workflow/status/hanxhx/ansible-nginx/molecule.yml?branch=master)

Install and configure Nginx on Debian/FreeBSD.

@@ -20,17 +20,23 @@ Features:

Supported OS:

| OS | Working | Stable (active support) |
| ------------------ | ------- | ----------------------- |
| Debian Jessie (8) | Yes | Yes |
| Debian Stretch (9) | Yes | Yes |
| FreeBSD 11 | Yes | No |
| FreeBSD 12 | Yes | No |
| OS | Working | Stable (active support) |
|----------------------|---------|------------------------------------------------------------------------------------------------------|
| Debian Jessie (8) | Yes | Check latest supported version ([1.5.0](https://github.com/HanXHX/ansible-nginx/releases/tag/1.5.0)) |
| Debian Stretch (9) | Yes | Check latest supported version ([1.9.0](https://github.com/HanXHX/ansible-nginx/releases/tag/1.9.0)) |
| Debian Buster (10) | Yes | Yes |
| Debian Bullseye (11) | Yes | Yes |
| Debian Bookworm (12) | Yes | Not yet :) |
| FreeBSD 11 | NA | No |
| FreeBSD 12 | NA | No |
| Ubuntu 20.04 | Yes | Yes |
| Ubuntu 22.04 | Yes | Yes |

Requirements
------------

None. If you set true to `nginx_backports`, you must install backports repository before lauching this role.
- Ansible >=2.11
- If you set true to `nginx_backports`, you must install backports repository before lauching this role.

Role Variables
--------------
@@ -54,6 +60,7 @@ FreeBSD:
- `nginx_error_log_level`: default log level
- `nginx_auto_config_httpv2`: boolean, auto configure HTTP2 where possible
- `nginx_fastcgi_fix_realpath`: boolean, use realpath for fastcgi (fix problems with symlinks and PHP opcache)
- `nginx_default_hsts`: string, default header sent for HSTS

### Nginx Configuration

@@ -62,13 +69,14 @@ FreeBSD:
- `nginx_pid`: daemon pid file
- `nginx_events_*`: all variables in events block
- `nginx_http_*`: all variables in http block
- `nginx_custom_core`: instructions list (for core, will put data in `/etc/nginx/nginx.conf`)
- `nginx_custom_http`: instructions list (will put data in `/etc/nginx/conf.d/custom.conf`)
- `nginx_module_packages`: package list module to install (Debian)
- `nginx_load_modules`: module list to load (full path), should be used only on FreeBSD

### Misc

- `nginx_debug_role`: set _true_ if you need to see output of no\_log tasks
- `nginx_debug_role`: set _true_ if you need to see output of no\_log tasks

About modules
-------------
@@ -95,14 +103,34 @@ Fine configuration
Note
----

- Active support for Debian.
- FreeBSD support is experimental (no Travis). I only test (for the moment) 10.2 (but it can work on other versions).
- I don't manage BackupPC for FreeBSD (PR welcome).
- Active support for Debian/Ubuntu.
- FreeBSD support is experimental. I only test (for the moment) 10.2 (but it can work on other versions).

Dependencies
------------

None
See: [requirements.yml](requirements.yml).


If you need to dev this role locally on Vagrant
------------------------------------------------

Before use vagrant, run once:

```commandline
ansible-galaxy install -p ./tests/ HanXHX.php,master
```

If you need to dev this role locally with molecule
--------------------------------------------------

Check available scenarios in [molecule](molecule) directory.

With `debian-12` scenario:

```commandline
molecule -v -c molecule/_shared/base.yml verify -s debian-12
```

Example Playbook
----------------
32 changes: 18 additions & 14 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -6,24 +6,18 @@
Vagrant.configure("2") do |config|

vms_debian = [
{ :name => "debian-jessie", :box => "debian/jessie64", :vars => { "nginx_php": [{"version": "5.6"}] }},
{ :name => "debian-jessie-backports", :box => "debian/jessie64", :vars => { "nginx_php": [{"version": "5.6"}], "nginx_backports": true }},
{ :name => "debian-jessie-dotdeb", :box => "debian/jessie64", :vars => { "nginx_php": [{"version": "7.0"}, {"version": "5.6", "upstream_name": "legacy"} ], "dotdeb": true }},
{ :name => "debian-stretch", :box => "debian/stretch64", :vars => { "nginx_php": [{"version": "7.0"}] }},
{ :name => "debian-stretch-sury", :box => "debian/stretch64", :vars => { "nginx_php": [{"version": "7.1"}], "sury": true }}
{ :name => "debian-buster", :box => "debian/buster64", :vars => {} },
{ :name => "debian-bullseye", :box => "debian/bullseye64", :vars => {} }
]

vms_freebsd = [
{ :name => "freebsd-11", :box => "freebsd/FreeBSD-11.1-STABLE", :vars => {} },
{ :name => "freebsd-12", :box => "freebsd/FreeBSD-12.0-CURRENT", :vars => {} }
{ :name => "freebsd-11", :box => "freebsd/FreeBSD-11.3-STABLE", :vars => {} },
{ :name => "freebsd-12", :box => "freebsd/FreeBSD-12.1-STABLE", :vars => {} }
]

conts = [
{ :name => "docker-debian-jessie", :docker => "hanxhx/vagrant-ansible:debian8", :vars => { "nginx_php" => [{"version" => "5.6"}] }},
{ :name => "docker-debian-jessie-backports", :docker => "hanxhx/vagrant-ansible:debian8", :vars => { "nginx_php": [{"version": "5.6"}], "nginx_backports": true }},
{ :name => "docker-debian-jessie-dotdeb", :docker => "hanxhx/vagrant-ansible:debian8", :vars => { "nginx_php": [{"version": "7.0"}, {"version": "5.6", "upstream_name": "legacy"} ], "dotdeb": true }},
{ :name => "docker-debian-stretch", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "nginx_php": [{"version": "7.0"}] }},
{ :name => "docker-debian-stretch-sury", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "nginx_php": [{"version": "7.1"}], "sury": true }}
{ :name => "docker-debian-buster", :docker => "hanxhx/vagrant-ansible:debian10", :vars => {} },
{ :name => "docker-debian-bullseye", :docker => "hanxhx/vagrant-ansible:debian11", :vars => {} },
]

config.vm.network "private_network", type: "dhcp"
@@ -36,11 +30,16 @@ Vagrant.configure("2") do |config|
d.remains_running = true
d.has_ssh = true
end

if opts[:name].include? "bullseye"
m.vm.provision "shell", inline: "[ -f '/root/first_provision' ] || (apt-get update -qq && apt-get -y dist-upgrade && touch /root/first_provision)"
end

m.vm.provision "ansible" do |ansible|
ansible.playbook = "tests/test.yml"
ansible.verbose = 'vv'
ansible.become = true
ansible.extra_vars = opts[:vars].merge({ "nginx_debug_role": true })
ansible.extra_vars = opts[:vars].merge({ "nginx_debug_role": true, is_docker: true })
end
end
end
@@ -52,6 +51,11 @@ Vagrant.configure("2") do |config|
v.cpus = 1
v.memory = 256
end

if opts[:name].include? "bullseye"
m.vm.provision "shell", inline: "[ -f '/root/first_provision' ] || (apt-get update -qq && apt-get -y dist-upgrade && touch /root/first_provision)"
end

m.vm.provision "ansible" do |ansible|
ansible.playbook = "tests/test.yml"
ansible.verbose = 'vv'
@@ -70,7 +74,7 @@ Vagrant.configure("2") do |config|
v.cpus = 2
v.memory = 512
end
m.vm.provision "shell", inline: "pkg install -y python bash"
m.vm.provision "shell", inline: "[ -e /usr/local/bin/bash ] || pkg install -y python bash"
m.vm.provision "ansible" do |ansible|
ansible.playbook = "tests/test.yml"
ansible.verbose = 'vv'
18 changes: 16 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -14,18 +14,19 @@ nginx_log_dir: '/var/log/nginx'
nginx_resolver_hosts: ['8.8.8.8', '8.8.4.4']
nginx_resolver_valid: '300s'
nginx_resolver_timeout: '5s'
nginx_error_log_level: 'warn' # http://nginx.org/en/docs/ngx_core_module.html#error_log
nginx_error_log_level: 'warn' # http://nginx.org/en/docs/ngx_core_module.html#error_log
nginx_auto_config_httpv2: true
nginx_default_site: null
nginx_default_site_ssl: null
nginx_fastcgi_fix_realpath: true
nginx_default_hsts: 'max-age=63072000; includeSubDomains'

#
# Nginx directories
#
nginx_htpasswd_dir: '{{ nginx_etc_dir }}/htpasswd'
nginx_ssl_dir: '{{ nginx_etc_dir }}/ssl'
nginx_helper_dir: '{{ nginx_etc_dir}}/helper'
nginx_helper_dir: '{{ nginx_etc_dir }}/helper'

#
# Load upstream
@@ -83,6 +84,19 @@ nginx_http_gzip_disable: '"msie6"'
# Custom global configuration
#
nginx_custom_http: []
nginx_custom_core: []

#
# Nginx default
#
nginx_default_listen:
- '80'
- '[::]:80'
nginx_default_listen_ssl:
- '443'
- '[::]:443'
nginx_default_listen_proxy_protocol: []
nginx_default_listen_proxy_protocol_ssl: []

#
# Sites
Loading