mirror of
https://github.com/HanXHX/ansible-nginx.git
synced 2026-02-28 09:22:10 +07:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
|
- 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
|
||||||
@@ -47,7 +52,7 @@
|
|||||||
update: no
|
update: no
|
||||||
|
|
||||||
- name: SHELL | Install acme.sh
|
- name: SHELL | Install acme.sh
|
||||||
shell: ./acme.sh --install --home {{ nginx_acmesh_dir }} --cert-home {{ nginx_acmesh_dir }}
|
shell: ./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 }}"
|
||||||
|
|||||||
@@ -17,56 +17,77 @@
|
|||||||
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: SHELL | Get certificates
|
||||||
file:
|
shell: '{{ nginx_acmesh_bin }} --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 %}'
|
||||||
path: "{{ nginx_ssl_dir }}/{{ item | nginx_site_name }}"
|
args:
|
||||||
loop: "{{ acme_create }}"
|
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: SHELL | Install certificates
|
||||||
file:
|
shell: '{{ nginx_acmesh_bin }} --home {{ nginx_acmesh_dir }} --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"'
|
||||||
path: "{{ nginx_etc_dir }}/conf.d/FAKESITE_{{ item | nginx_site_name }}.conf"
|
args:
|
||||||
state: absent
|
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
|
||||||
|
|
||||||
|
rescue:
|
||||||
|
|
||||||
|
- name: FILE | Delete acme.sh files
|
||||||
|
file:
|
||||||
|
path: "{{ nginx_acmesh_dir }}/{{ item | nginx_site_name }}/"
|
||||||
|
state: absent
|
||||||
|
loop: "{{ nginx_ssl_pairs }}"
|
||||||
|
|
||||||
|
- 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
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user