Manage custom templates for sites

Issue #12 related
debian_11^2
Emilien Mantel 2020-08-23 16:22:33 +02:00 committed by Emilien M
parent da08953a27
commit 204e95725e
3 changed files with 66 additions and 8 deletions

View File

@ -39,12 +39,22 @@
loop_control:
label: "{{ item | nginx_site_name }}"
- name: TEMPLATE | Create sites
- name: TEMPLATE | Create sites with preconfigured template
template:
src: "etc/nginx/sites-available/{{ item.template if item.redirect_to is not defined else '_redirect' }}.j2"
dest: "{{ nginx_etc_dir }}/sites-available/{{ item | nginx_site_filename }}"
notify: ['reload nginx', 'restart nginx freebsd']
when: item.state is not defined or item.state != 'absent'
when: (item.state is not defined or item.state != 'absent') and item.custom_template is not defined
loop: "{{ nginx_sites }}"
loop_control:
label: "{{ item | nginx_site_name }}"
- name: TEMPLATE | Create sites with preconfigured template
template:
src: "{{ item.custom_template }}"
dest: "{{ nginx_etc_dir }}/sites-available/{{ item | nginx_site_filename }}"
notify: ['reload nginx', 'restart nginx freebsd']
when: (item.state is not defined or item.state != 'absent') and item.custom_template is defined
loop: "{{ nginx_sites }}"
loop_control:
label: "{{ item | nginx_site_name }}"

View File

@ -0,0 +1,16 @@
# {{ ansible_managed }} - custom template
server {
listen 80;
listen 8888 http2;
listen 9999 http2 proxy_protocol;
server_name {{ item.name }};
index index.html index.htm;
root {{ item.root }};
location / {
try_files $uri $uri/ =404;
}
}

View File

@ -277,6 +277,9 @@
ssl_name: '{{ ngrok.stdout }}'
headers:
'X-acme': '1'
- name: 'test-custom-template.local'
custom_template: 'templates/custom_template.conf.j2'
root: '/tmp/custom-template'
nginx_php: "{{ [{'upstream_name': 'manual', 'sockets': [{'host': '127.0.0.1', 'port': '9636' }] }] }}"
nginx_dh_length: 1024
@ -301,6 +304,14 @@
- 'test-php-index.local'
- 'test-php-index2.local'
- name: -- Add Directories --
file:
path: "{{ item }}"
state: directory
loop:
- "{{ nginx_root }}/test-htpasswd.local/public/hello"
- "/tmp/custom-template"
- name: -- Add HTML file --
copy:
dest: "{{ item }}/index.html"
@ -314,11 +325,7 @@
- '{{ nginx_root }}/test-ssl-predeployed.local/public'
- '{{ nginx_root }}/test-ssl-proxy-protocol.local/public'
- '{{ nginx_root }}/{{ ngrok.stdout }}/public'
- name: -- Create directory --
file:
path: "{{ nginx_root }}/test-htpasswd.local/public/hello"
state: directory
- '/tmp/custom-template'
- name: -- Add HTML file hello --
copy:
@ -536,7 +543,7 @@
# --------------------------------
# Check HTTP2
# --------------------------------
- name: SHELL | Check HTTP2
- name: SHELL | Check HTTPS HTTP2
shell: nghttp -nv https://localhost 2> /dev/null | grep -q h2
args:
executable: /bin/sh
@ -544,3 +551,28 @@
when: nginx_auto_config_httpv2 and 'http_v2' in nginx_modules
tags:
- skip_ansible_lint
- block:
- name: SHELL | Check HTTP2C (on custom template)
shell: curl --http2-prior-knowledge http://localhost:8888
args:
executable: /bin/sh
warn: no
changed_when: false
when: nginx_auto_config_httpv2 and 'http_v2' in nginx_modules
tags:
- skip_ansible_lint
- name: SHELL | Check HTTP2C + proxy protocol (on custom template)
shell: curl --http2-prior-knowledge --haproxy-protocol http://localhost:9999
args:
executable: /bin/sh
warn: no
changed_when: false
when: nginx_auto_config_httpv2 and 'http_v2' in nginx_modules
tags:
- skip_ansible_lint
when: not (ansible_distribution == 'Debian' and ansible_distribution_major_version is version('9', 'eq'))