mirror of
https://github.com/HanXHX/ansible-nginx.git
synced 2026-02-28 09:22:10 +07:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb5e00d6f5 | ||
|
|
cf010e4a4b | ||
|
|
39d3f5f06a | ||
|
|
247f849b86 | ||
|
|
a03a656b18 | ||
|
|
1239219d90 | ||
|
|
4f94fc2211 | ||
|
|
e89a154bb5 | ||
|
|
c9bda9e95a | ||
|
|
4efc975770 | ||
|
|
20d04015c1 |
@@ -1,8 +1,10 @@
|
|||||||
env:
|
env:
|
||||||
- PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.6,<2.7'
|
- PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.6,<2.7'
|
||||||
- PLATFORM='docker-debian-stretch-sury' ANSIBLE_VERSION='ansible>=2.6,<2.7'
|
- PLATFORM='docker-debian-stretch-sury' ANSIBLE_VERSION='ansible>=2.6,<2.7'
|
||||||
|
- PLATFORM='docker-debian-buster' ANSIBLE_VERSION='ansible>=2.6,<2.7'
|
||||||
- PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.7,<2.8'
|
- PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.7,<2.8'
|
||||||
- PLATFORM='docker-debian-stretch-sury' ANSIBLE_VERSION='ansible>=2.7,<2.8'
|
- PLATFORM='docker-debian-stretch-sury' ANSIBLE_VERSION='ansible>=2.7,<2.8'
|
||||||
|
- PLATFORM='docker-debian-buster' ANSIBLE_VERSION='ansible>=2.7,<2.8'
|
||||||
|
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
@@ -13,6 +15,7 @@ sudo: required
|
|||||||
dist: trusty
|
dist: trusty
|
||||||
|
|
||||||
language: python
|
language: python
|
||||||
|
python: 2.7
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- docker
|
- docker
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ Supported OS:
|
|||||||
| ------------------ | ------- | ----------------------- |
|
| ------------------ | ------- | ----------------------- |
|
||||||
| Debian Jessie (8) | Yes | Check latest supported version ([1.5.0](https://github.com/HanXHX/ansible-nginx/releases/tag/1.5.0)) |
|
| 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 | Yes |
|
| Debian Stretch (9) | Yes | Yes |
|
||||||
|
| Debian Buster (10) | Yes | No |
|
||||||
| FreeBSD 11 | Yes | No |
|
| FreeBSD 11 | Yes | No |
|
||||||
| FreeBSD 12 | Yes | No |
|
| FreeBSD 12 | Yes | No |
|
||||||
|
|
||||||
|
|||||||
8
Vagrantfile
vendored
8
Vagrantfile
vendored
@@ -7,7 +7,8 @@ Vagrant.configure("2") do |config|
|
|||||||
|
|
||||||
vms_debian = [
|
vms_debian = [
|
||||||
{ :name => "debian-stretch", :box => "debian/stretch64", :vars => { "nginx_php": [{"version": "7.0"}] }},
|
{ :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-stretch-sury", :box => "debian/stretch64", :vars => { "nginx_php": [{"version": "7.1"}], "sury": true }},
|
||||||
|
{ :name => "debian-buster", :box => "debian/buster64", :vars => { "nginx_php": [{"version": "7.3"}] }}
|
||||||
]
|
]
|
||||||
|
|
||||||
vms_freebsd = [
|
vms_freebsd = [
|
||||||
@@ -17,7 +18,8 @@ Vagrant.configure("2") do |config|
|
|||||||
|
|
||||||
conts = [
|
conts = [
|
||||||
{ :name => "docker-debian-stretch", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "nginx_php": [{"version": "7.0"}] }},
|
{ :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-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 => { "nginx_php": [{"version": "7.3"}] }},
|
||||||
]
|
]
|
||||||
|
|
||||||
config.vm.network "private_network", type: "dhcp"
|
config.vm.network "private_network", type: "dhcp"
|
||||||
@@ -34,7 +36,7 @@ Vagrant.configure("2") do |config|
|
|||||||
ansible.playbook = "tests/test.yml"
|
ansible.playbook = "tests/test.yml"
|
||||||
ansible.verbose = 'vv'
|
ansible.verbose = 'vv'
|
||||||
ansible.become = true
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
Auth Basic management
|
Auth Basic management
|
||||||
=====================
|
=====================
|
||||||
|
|
||||||
IMPORTANT
|
|
||||||
---------
|
|
||||||
|
|
||||||
If you use this feature with Debian Stretch, you *MUST* use ansible >= 2.3.2! See: [https://github.com/HanXHX/ansible-nginx/issues/28](#28).
|
|
||||||
|
|
||||||
Description
|
Description
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
|
|||||||
@@ -10,11 +10,29 @@ def nginx_site_name(site):
|
|||||||
else:
|
else:
|
||||||
return site['name']
|
return site['name']
|
||||||
|
|
||||||
|
def nginx_ssl_dir(pair, ssl_dir):
|
||||||
|
return ssl_dir + '/' + nginx_site_filename(pair)
|
||||||
|
|
||||||
|
def nginx_key_path(pair, ssl_dir):
|
||||||
|
if pair.has_key('dest_key'):
|
||||||
|
return pair['dest_key']
|
||||||
|
else:
|
||||||
|
return nginx_ssl_dir(pair, ssl_dir) + '/' + nginx_site_filename(pair) + '.key'
|
||||||
|
|
||||||
|
def nginx_cert_path(pair, ssl_dir):
|
||||||
|
if pair.has_key('dest_cert'):
|
||||||
|
return pair['dest_cert']
|
||||||
|
else:
|
||||||
|
return nginx_ssl_dir(pair, ssl_dir) + '/' + nginx_site_filename(pair) + '.crt'
|
||||||
|
|
||||||
class FilterModule(object):
|
class FilterModule(object):
|
||||||
''' Nginx module '''
|
''' Nginx module '''
|
||||||
|
|
||||||
def filters(self):
|
def filters(self):
|
||||||
return {
|
return {
|
||||||
'nginx_site_filename': nginx_site_filename,
|
'nginx_site_filename': nginx_site_filename,
|
||||||
'nginx_site_name': nginx_site_name
|
'nginx_site_name': nginx_site_name,
|
||||||
|
'nginx_ssl_dir': nginx_ssl_dir,
|
||||||
|
'nginx_key_path': nginx_key_path,
|
||||||
|
'nginx_cert_path': nginx_cert_path
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,11 @@
|
|||||||
def php_default_upstream_socket(php_version):
|
def php_default_upstream_socket(php_version):
|
||||||
if php_version == '5.6':
|
return '/run/php/php%s-fpm.sock' % php_version
|
||||||
return '/run/php5-fpm.sock'
|
|
||||||
else:
|
|
||||||
return '/run/php/php%s-fpm.sock' % php_version
|
|
||||||
|
|
||||||
def php_default_upstream_name(php_version):
|
def php_default_upstream_name(php_version):
|
||||||
return 'default_php_%s' % php_version
|
return 'default_php_%s' % php_version
|
||||||
|
|
||||||
def php_fpm_service(php_version):
|
def php_fpm_service(php_version):
|
||||||
if php_version == '5.6':
|
return 'php%s-fpm' % php_version
|
||||||
return 'php5-fpm'
|
|
||||||
else:
|
|
||||||
return 'php%s-fpm' % php_version
|
|
||||||
|
|
||||||
class FilterModule(object):
|
class FilterModule(object):
|
||||||
''' PHP module '''
|
''' PHP module '''
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ galaxy_info:
|
|||||||
- name: Debian
|
- name: Debian
|
||||||
versions:
|
versions:
|
||||||
- stretch
|
- stretch
|
||||||
|
- buster
|
||||||
- name: FreeBSD
|
- name: FreeBSD
|
||||||
versions:
|
versions:
|
||||||
- 11.0
|
- 11.0
|
||||||
@@ -25,4 +26,3 @@ galaxy_info:
|
|||||||
- nginx
|
- nginx
|
||||||
- cdn
|
- cdn
|
||||||
dependencies: []
|
dependencies: []
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,19 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
|
- name: SET_FACT | Bypass https://github.com/ansible/ansible/issues/19874
|
||||||
|
set_fact:
|
||||||
|
ansible_distribution_release: 'buster'
|
||||||
|
when: ansible_facts.distribution_major_version == "buster/sid"
|
||||||
|
|
||||||
- name: APT | Update cache
|
- name: APT | Update cache
|
||||||
apt:
|
apt:
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
cache_valid_time: 3600
|
cache_valid_time: 3600
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: APT | Force OpenSSL from backports (fix dependency break)
|
|
||||||
apt:
|
|
||||||
pkg: openssl
|
|
||||||
state: latest
|
|
||||||
default_release: "{{ ansible_distribution_release + '-backports' }}"
|
|
||||||
when: nginx_backports
|
|
||||||
|
|
||||||
- name: APT | Install nginx and dependencies
|
- name: APT | Install nginx and dependencies
|
||||||
apt:
|
apt:
|
||||||
pkg: "{{ nginx_apt_package }}"
|
pkg: "{{ nginx_apt_package }}"
|
||||||
state: present
|
|
||||||
default_release: "{{ ansible_distribution_release + '-backports' if nginx_backports else ansible_distribution_release }}"
|
default_release: "{{ ansible_distribution_release + '-backports' if nginx_backports else ansible_distribution_release }}"
|
||||||
|
|
||||||
- name: APT | Install nginx modules
|
- name: APT | Install nginx modules
|
||||||
@@ -45,9 +42,10 @@
|
|||||||
repo: 'https://github.com/Neilpang/acme.sh.git'
|
repo: 'https://github.com/Neilpang/acme.sh.git'
|
||||||
dest: '{{ nginx_acmesh_git_dir }}'
|
dest: '{{ nginx_acmesh_git_dir }}'
|
||||||
update: no
|
update: no
|
||||||
|
version: master
|
||||||
|
|
||||||
- name: SHELL | Install acme.sh
|
- name: COMMAND | Install acme.sh
|
||||||
shell: ./acme.sh --install --home {{ nginx_acmesh_dir }} --cert-home {{ nginx_acmesh_dir }}
|
command: ./acme.sh --install --home "{{ nginx_acmesh_dir }}"
|
||||||
args:
|
args:
|
||||||
chdir: "{{ nginx_acmesh_git_dir }}"
|
chdir: "{{ nginx_acmesh_git_dir }}"
|
||||||
creates: "{{ nginx_acmesh_dir }}"
|
creates: "{{ nginx_acmesh_dir }}"
|
||||||
|
|||||||
@@ -7,14 +7,24 @@
|
|||||||
register: nginx_version
|
register: nginx_version
|
||||||
changed_when: false
|
changed_when: false
|
||||||
check_mode: no
|
check_mode: no
|
||||||
|
tags:
|
||||||
|
- skip_ansible_lint
|
||||||
|
|
||||||
- name: SHELL | Get module list
|
- name: SHELL | Get module list
|
||||||
shell: nginx -V 2>&1 | tr -- - '\n' | grep -A 1 with | grep _module | sed -r 's/_module//g; s/\s+//g' | sort
|
shell: |
|
||||||
|
nginx -V 2>&1 |
|
||||||
|
tr -- - '\n' |
|
||||||
|
grep -A 1 with |
|
||||||
|
grep _module |
|
||||||
|
sed -r 's/_module//g; s/\s+//g' |
|
||||||
|
sort
|
||||||
args:
|
args:
|
||||||
executable: /bin/sh
|
executable: /bin/sh
|
||||||
register: shell_modules
|
register: shell_modules
|
||||||
changed_when: false
|
changed_when: false
|
||||||
check_mode: no
|
check_mode: no
|
||||||
|
tags:
|
||||||
|
- skip_ansible_lint
|
||||||
|
|
||||||
- name: SET_FACT | Save modules
|
- name: SET_FACT | Save modules
|
||||||
set_fact:
|
set_fact:
|
||||||
|
|||||||
@@ -75,7 +75,7 @@
|
|||||||
|
|
||||||
- name: FILE | Disable sites
|
- name: FILE | Disable sites
|
||||||
file:
|
file:
|
||||||
path: "{{ nginx_etc_dir}}/sites-enabled/{{ item | nginx_site_filename }}"
|
path: "{{ nginx_etc_dir }}/sites-enabled/{{ item | nginx_site_filename }}"
|
||||||
state: absent
|
state: absent
|
||||||
loop: "{{ nginx_sites }}"
|
loop: "{{ nginx_sites }}"
|
||||||
notify: ['reload nginx', 'restart nginx freebsd']
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
|
|||||||
@@ -17,56 +17,82 @@
|
|||||||
loop: "{{ acme_installed_certs.results }}"
|
loop: "{{ acme_installed_certs.results }}"
|
||||||
when: item.skipped is not defined and not item.stat.exists
|
when: item.skipped is not defined and not item.stat.exists
|
||||||
|
|
||||||
- name: TEMPLATE | Create fake site
|
- name: BLOCK | Start acme
|
||||||
template:
|
block:
|
||||||
src: "etc/nginx/conf.d/FAKESITE.conf.j2"
|
|
||||||
dest: "{{ nginx_etc_dir }}/conf.d/FAKESITE_{{ item | nginx_site_name }}.conf"
|
|
||||||
loop: "{{ acme_create }}"
|
|
||||||
register: fake_site
|
|
||||||
|
|
||||||
- name: FILE | Delete current site if needed
|
- name: TEMPLATE | Create fake site
|
||||||
file:
|
template:
|
||||||
path: "{{ nginx_etc_dir }}/sites-enabled/{{ item | nginx_site_name }}"
|
src: "etc/nginx/conf.d/FAKESITE.conf.j2"
|
||||||
state: absent
|
dest: "{{ nginx_etc_dir }}/conf.d/FAKESITE_{{ item | nginx_site_name }}.conf"
|
||||||
loop: "{{ acme_create }}"
|
loop: "{{ acme_create }}"
|
||||||
when: fake_site.changed
|
register: fake_site
|
||||||
|
|
||||||
- name: SERVICE | Restart nginx
|
- name: FILE | Delete current site if needed
|
||||||
service:
|
file:
|
||||||
name: nginx
|
path: "{{ nginx_etc_dir }}/sites-enabled/{{ item | nginx_site_name }}"
|
||||||
state: restarted
|
state: absent
|
||||||
when: fake_site.changed and ansible_virtualization_type != 'docker'
|
loop: "{{ acme_create }}"
|
||||||
|
when: fake_site.changed
|
||||||
|
|
||||||
- name: COMMAND | Restart nginx
|
- name: SERVICE | Restart nginx
|
||||||
command: service nginx restart
|
service:
|
||||||
args:
|
name: nginx
|
||||||
warn: false
|
state: restarted
|
||||||
when: fake_site.changed and ansible_virtualization_type == 'docker'
|
when: fake_site.changed and ansible_virtualization_type != 'docker'
|
||||||
|
|
||||||
- name: SHELL | Get certificates
|
- name: COMMAND | Restart nginx
|
||||||
shell: '{{ nginx_acmesh_bin }} --issue{% if item.name is string %} -d {{ item.name }}{% else %}{% for name in item.name %} -d {{ name }}{% endfor %}{% endif %} --nginx {% if nginx_acmesh_test %}--test{% endif %}'
|
command: service nginx restart
|
||||||
args:
|
args:
|
||||||
creates: "/root/.acme.sh/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key"
|
warn: false
|
||||||
loop: "{{ acme_create }}"
|
when: fake_site.changed and ansible_virtualization_type == 'docker'
|
||||||
register: acme_get
|
|
||||||
failed_when: acme_get.rc != 0 and acme_get.rc != 2
|
|
||||||
no_log: not nginx_debug_role
|
|
||||||
|
|
||||||
- name: FILE | Create SSL dir per site
|
- name: COMMAND | Get certificates
|
||||||
file:
|
command: |
|
||||||
path: "{{ nginx_ssl_dir }}/{{ item | nginx_site_name }}"
|
{{ nginx_acmesh_bin }}
|
||||||
loop: "{{ acme_create }}"
|
--home {{ nginx_acmesh_dir }}
|
||||||
|
--issue{% if item.name is string %} -d {{ item.name }}{% else %}{% for name in item.name %} -d {{ name }}{% endfor %}{% endif %}
|
||||||
|
--nginx
|
||||||
|
{% if nginx_acmesh_test %}--test{% endif %}
|
||||||
|
args:
|
||||||
|
creates: "{{ nginx_acmesh_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key"
|
||||||
|
loop: "{{ acme_create }}"
|
||||||
|
register: acme_get
|
||||||
|
failed_when: acme_get.rc != 0 and acme_get.rc != 2
|
||||||
|
no_log: not nginx_debug_role
|
||||||
|
|
||||||
- name: SHELL | Install certificates
|
- name: FILE | Create SSL dir per site
|
||||||
shell: '{{ nginx_acmesh_bin }} --install-cert -d {{ item | nginx_site_name }} --fullchain-file {{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.crt --key-file {{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key --reloadcmd "service nginx restart"'
|
file:
|
||||||
args:
|
path: "{{ nginx_ssl_dir }}/{{ item | nginx_site_name }}"
|
||||||
creates: "{{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key"
|
loop: "{{ acme_create }}"
|
||||||
loop: "{{ nginx_ssl_pairs }}"
|
|
||||||
when: item.acme is defined and item.acme
|
|
||||||
notify: restart nginx
|
|
||||||
|
|
||||||
- name: FILE | Delete fake sites
|
- name: COMMAND | Install certificates
|
||||||
file:
|
command: |
|
||||||
path: "{{ nginx_etc_dir }}/conf.d/FAKESITE_{{ item | nginx_site_name }}.conf"
|
{{ nginx_acmesh_bin }}
|
||||||
state: absent
|
--home {{ nginx_acmesh_dir }}
|
||||||
loop: "{{ acme_create }}"
|
--install-cert -d {{ item | nginx_site_name }}
|
||||||
|
--fullchain-file {{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.crt
|
||||||
|
--key-file {{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key
|
||||||
|
--reloadcmd "service nginx reload"
|
||||||
|
args:
|
||||||
|
creates: "{{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key"
|
||||||
|
loop: "{{ nginx_ssl_pairs }}"
|
||||||
|
when: item.acme is defined and item.acme
|
||||||
|
notify: restart nginx
|
||||||
|
|
||||||
|
rescue:
|
||||||
|
|
||||||
|
- name: FAIL | Explicit
|
||||||
|
fail:
|
||||||
|
msg: "Something is bad... Auto crash!"
|
||||||
|
|
||||||
|
always:
|
||||||
|
|
||||||
|
- name: FILE | Delete fake sites
|
||||||
|
file:
|
||||||
|
path: "{{ nginx_etc_dir }}/conf.d/FAKESITE_{{ item | nginx_site_name }}.conf"
|
||||||
|
state: absent
|
||||||
|
loop: "{{ acme_create }}"
|
||||||
|
notify: restart nginx
|
||||||
|
|
||||||
|
- name: META | Flush handlers
|
||||||
|
meta: flush_handlers
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
- name: FILE | Create SSL directories
|
- name: FILE | Create SSL directories
|
||||||
file:
|
file:
|
||||||
path: "{{ nginx_ssl_dir + '/' + item | nginx_site_name }}"
|
path: "{{ item | nginx_ssl_dir(nginx_ssl_dir) }}"
|
||||||
state: directory
|
state: directory
|
||||||
loop: "{{ nginx_ssl_pairs }}"
|
loop: "{{ nginx_ssl_pairs }}"
|
||||||
when: item.dest_key is not defined or item.dest_cert is not defined
|
when: item.dest_key is not defined or item.dest_cert is not defined
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
- name: COPY | Deploy SSL keys
|
- name: COPY | Deploy SSL keys
|
||||||
copy:
|
copy:
|
||||||
content: "{{ item.key }}"
|
content: "{{ item.key }}"
|
||||||
dest: "{{ nginx_ssl_dir + '/' + item | nginx_site_name + '/' + item | nginx_site_name + '.key' if item.dest_key is not defined else item.dest_key }}"
|
dest: "{{ item | nginx_key_path(nginx_ssl_dir) }}"
|
||||||
mode: 0640
|
mode: 0640
|
||||||
loop: "{{ nginx_ssl_pairs }}"
|
loop: "{{ nginx_ssl_pairs }}"
|
||||||
when: item.key is defined
|
when: item.key is defined
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
- name: COPY | Deploy SSL certs
|
- name: COPY | Deploy SSL certs
|
||||||
copy:
|
copy:
|
||||||
content: "{{ item.cert }}"
|
content: "{{ item.cert }}"
|
||||||
dest: "{{ nginx_ssl_dir + '/' + item | nginx_site_name + '/' + item | nginx_site_name + '.crt' if item.dest_cert is not defined else item.dest_cert }}"
|
dest: "{{ item | nginx_cert_path(nginx_ssl_dir) }}"
|
||||||
mode: 0644
|
mode: 0644
|
||||||
loop: "{{ nginx_ssl_pairs }}"
|
loop: "{{ nginx_ssl_pairs }}"
|
||||||
when: item.cert is defined
|
when: item.cert is defined
|
||||||
@@ -57,10 +57,15 @@
|
|||||||
no_log: not nginx_debug_role
|
no_log: not nginx_debug_role
|
||||||
|
|
||||||
- name: COMMAND | Create self-signed certificates
|
- name: COMMAND | Create self-signed certificates
|
||||||
command: "openssl req -new -newkey rsa:2048 -sha256 -days 3650 -nodes -x509 -subj '/CN={{ item | nginx_site_name }}' -keyout {{ item | nginx_site_name + '.key' }} -out {{ item | nginx_site_name + '.crt' }}"
|
command: |
|
||||||
|
openssl req
|
||||||
|
-new -newkey rsa:2048 -sha256 -days 3650 -nodes -x509
|
||||||
|
-subj '/CN={{ item | nginx_site_name }}'
|
||||||
|
-keyout {{ item | nginx_key_path(nginx_ssl_dir) }}
|
||||||
|
-out {{ item | nginx_cert_path(nginx_ssl_dir) }}
|
||||||
args:
|
args:
|
||||||
chdir: "{{ nginx_ssl_dir + '/' + item | nginx_site_name }}"
|
chdir: "{{ item | nginx_ssl_dir(nginx_ssl_dir) }}"
|
||||||
creates: "{% if item.force is defined and item.force %}/tmp/dummy{% else %}{{ nginx_ssl_dir + '/' + item | nginx_site_name + '/' + item | nginx_site_name + '.crt' }}{% endif %}"
|
creates: "{{ '/tmp/dummy' if item.force is defined and item.force else item | nginx_cert_path(nginx_ssl_dir) }}"
|
||||||
loop: "{{ nginx_ssl_pairs }}"
|
loop: "{{ nginx_ssl_pairs }}"
|
||||||
when: item.self_signed is defined
|
when: item.self_signed is defined
|
||||||
notify: restart nginx
|
notify: restart nginx
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
{% set __ssl_name = item.ssl_name | default(item.name if item.name is string else item.name[0]) %}
|
{% set __ssl_name = item.ssl_name | default(item.name if item.name is string else item.name[0]) %}
|
||||||
{% set __location_order = item.location_order | default(__location.keys()) %}
|
{% set __location_order = item.location_order | default(__location.keys()) %}
|
||||||
{% set __location_order_before = item.location_order_before | default(__location_before.keys()) %}
|
{% set __location_order_before = item.location_order_before | default(__location_before.keys()) %}
|
||||||
|
{% macro server_name(name) %}
|
||||||
|
{% if name is string %}{{ name }}{% else %}{{ name | join(" ") }}{% endif %}
|
||||||
|
{% endmacro %}
|
||||||
{% macro locations(list, order) %}
|
{% macro locations(list, order) %}
|
||||||
{% if order | length > 0 %}
|
{% if order | length > 0 %}
|
||||||
# --> Custom locations
|
# --> Custom locations
|
||||||
@@ -38,8 +41,8 @@
|
|||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
{% macro ssl(ssl_name) %}
|
{% macro ssl(ssl_name) %}
|
||||||
{% for sn in nginx_ssl_pairs if ((sn.name is string and sn.name == ssl_name) or (sn.name.0 == ssl_name)) %}
|
{% for sn in nginx_ssl_pairs if ((sn.name is string and sn.name == ssl_name) or (sn.name.0 == ssl_name)) %}
|
||||||
ssl_certificate {{ nginx_ssl_dir + '/' + ssl_name + '/' + ssl_name + '.crt' if sn.dest_cert is not defined else sn.dest_cert }};
|
ssl_certificate {{ sn | nginx_cert_path(nginx_ssl_dir) }};
|
||||||
ssl_certificate_key {{ nginx_ssl_dir + '/' + ssl_name + '/' + ssl_name + '.key' if sn.dest_key is not defined else sn.dest_key }};
|
ssl_certificate_key {{ sn | nginx_key_path(nginx_ssl_dir) }};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
{% macro httpsredirect(name) %}
|
{% macro httpsredirect(name) %}
|
||||||
@@ -47,7 +50,7 @@ server {
|
|||||||
{% for port in __listen %}
|
{% for port in __listen %}
|
||||||
listen {{ port }}{% if port | int in __http_proxy_protocol_port %} proxy_protocol{% endif %};
|
listen {{ port }}{% if port | int in __http_proxy_protocol_port %} proxy_protocol{% endif %};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
server_name {{ name }};
|
server_name {{ server_name(name) }};
|
||||||
location / {
|
location / {
|
||||||
return 301 https://{{ name }}{% if '443' not in __listen_ssl and 443 not in __listen_ssl %}:{{ __listen_ssl[0] }}{% endif %}$request_uri;
|
return 301 https://{{ name }}{% if '443' not in __listen_ssl and 443 not in __listen_ssl %}:{{ __listen_ssl[0] }}{% endif %}$request_uri;
|
||||||
}
|
}
|
||||||
@@ -76,7 +79,7 @@ server {
|
|||||||
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
|
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
server_name {% if item.name is string %}{{ item.name }}{% else %}{{ "\n\t\t" }}{{ item.name | join("\n\t\t") }}{% endif %};
|
server_name {{ server_name(item.name) }};
|
||||||
{% block root %}
|
{% block root %}
|
||||||
{% if item.root is defined %}
|
{% if item.root is defined %}
|
||||||
root {{ item.root }};
|
root {{ item.root }};
|
||||||
@@ -181,7 +184,7 @@ server {
|
|||||||
{% for port in __listen %}
|
{% for port in __listen %}
|
||||||
listen {{ port }}{% if port | int in __http_proxy_protocol_port %} proxy_protocol{% endif %};
|
listen {{ port }}{% if port | int in __http_proxy_protocol_port %} proxy_protocol{% endif %};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
server_name {% if item.redirect_from is string %}{{ item.redirect_from }}{% else %}{{ "\n\t\t" }}{{ item.redirect_from | join("\n\t\t") }}{% endif %};
|
server_name {{ server_name(item.redirect_from) }};
|
||||||
location / {
|
location / {
|
||||||
return 301 $scheme://{{ item.name if item.name is string else item.name[0] }}$request_uri;
|
return 301 $scheme://{{ item.name if item.name is string else item.name[0] }}$request_uri;
|
||||||
}
|
}
|
||||||
@@ -196,7 +199,7 @@ server {
|
|||||||
{% if item.ssl_template is not defined or item.ssl_template != false %}
|
{% if item.ssl_template is not defined or item.ssl_template != false %}
|
||||||
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
|
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
server_name {% if item.redirect_from is string %}{{ item.redirect_from }}{% else %}{{ "\n\t\t" }}{{ item.redirect_from | join("\n\t\t") }}{% endif %};
|
server_name {{ server_name(item.redirect_from) }};
|
||||||
location / {
|
location / {
|
||||||
return 301 https://{{ item.name if item.name is string else item.name[0] }}{% if '443' not in __listen_ssl and 443 not in __listen_ssl %}:{{ __listen_ssl[0] }}{% endif %}$request_uri;
|
return 301 https://{{ item.name if item.name is string else item.name[0] }}{% if '443' not in __listen_ssl and 443 not in __listen_ssl %}:{{ __listen_ssl[0] }}{% endif %}$request_uri;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: APT | Install webapps
|
- name: APT | Install webapps and related tools
|
||||||
apt:
|
apt:
|
||||||
pkg: "{{ packages }}"
|
pkg: "{{ packages }}"
|
||||||
state: present
|
state: present
|
||||||
@@ -8,8 +8,12 @@
|
|||||||
vars:
|
vars:
|
||||||
packages:
|
packages:
|
||||||
- backuppc
|
- backuppc
|
||||||
|
- samba-common-bin
|
||||||
|
- smbclient
|
||||||
|
|
||||||
- name: SERVICE | Ensure backuppc is started
|
- name: SERVICE | Ensure backuppc is started
|
||||||
service:
|
service:
|
||||||
name: backuppc
|
name: backuppc
|
||||||
state: started
|
state: started
|
||||||
|
register: b
|
||||||
|
failed_when: b.failed and 'Another BackupPC is running' not in b.msg
|
||||||
|
|||||||
@@ -23,10 +23,20 @@
|
|||||||
src: "file/test.key"
|
src: "file/test.key"
|
||||||
dest: "{{ int_ansible_ssl_dir }}/test.key"
|
dest: "{{ int_ansible_ssl_dir }}/test.key"
|
||||||
|
|
||||||
- name: LINEINFILE | Add all hosts in /etc/hosts
|
- name: COPY | Add all hosts in /etc/hosts
|
||||||
lineinfile:
|
copy:
|
||||||
line: "127.0.0.1\tlocalhost {% for s in nginx_sites %}{% if s.name is string %}{{ s.name }}{% else %}{% for n in s.name %}{{ n }} {% endfor %}{% endif %} {% if s.redirect_from is defined %}{% for rf in s.redirect_from %}{{ rf }} {% endfor %}{% endif %}{% endfor %}"
|
content: |
|
||||||
regexp: '^127\.0\.0\.1'
|
127.0.0.1 localhost
|
||||||
|
{% for s in nginx_sites %}
|
||||||
|
{% if s.name is string %}
|
||||||
|
127.0.0.1 {{ s.name }}
|
||||||
|
{% else %}
|
||||||
|
127.0.0.1 {% for n in s.name %}{{ n }} {% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% if s.redirect_from is defined %}
|
||||||
|
127.0.0.1 {% for rf in s.redirect_from %}{{ rf }} {% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
dest: "/etc/hosts"
|
dest: "/etc/hosts"
|
||||||
unsafe_writes: yes
|
unsafe_writes: yes
|
||||||
|
|
||||||
@@ -355,7 +365,7 @@
|
|||||||
# --------------------------------
|
# --------------------------------
|
||||||
- name: -- VERIFY PHP SITES --
|
- name: -- VERIFY PHP SITES --
|
||||||
uri:
|
uri:
|
||||||
url: "http://{{ item.name}}/"
|
url: "http://{{ item.name }}/"
|
||||||
return_content: yes
|
return_content: yes
|
||||||
register: p
|
register: p
|
||||||
loop: "{{ nginx_sites }}"
|
loop: "{{ nginx_sites }}"
|
||||||
@@ -510,3 +520,5 @@
|
|||||||
executable: /bin/sh
|
executable: /bin/sh
|
||||||
changed_when: false
|
changed_when: false
|
||||||
when: nginx_auto_config_httpv2 and 'http_v2' in nginx_modules
|
when: nginx_auto_config_httpv2 and 'http_v2' in nginx_modules
|
||||||
|
tags:
|
||||||
|
- skip_ansible_lint
|
||||||
|
|||||||
Reference in New Issue
Block a user