Browse Source

simplify nginx role templating

- remove the handling of which template to use
- do not access parent role
- update riot-web nginx configuration
- update icinga role to use new nginx templating
- update synapse nginx configuration
- update matrix role to use new nginx templates
- update dokuwiki to use new nginx template
- extend nginx template in dokuwiki
- update login role to new nginx templates
- add protocol for default option
- add extra block to nginx template
- update riote-web version
- fix template extension for riot web nginx definition
- update login template for nginx endpoint
python3
Edoardo Putti 7 years ago
parent
commit
5d2fd43425
23 changed files with 128 additions and 157 deletions
  1. +1
    -3
      roles/dokuwiki/meta/main.yaml
  2. +14
    -6
      roles/dokuwiki/tasks/main.yaml
  3. +24
    -0
      roles/dokuwiki/templates/dokuwiki.conf
  4. +0
    -20
      roles/dokuwiki/templates/dokuwiki.conf.nginx.j2
  5. +1
    -3
      roles/icinga2/meta/main.yaml
  6. +8
    -0
      roles/icinga2/tasks/main.yaml
  7. +4
    -0
      roles/icinga2/templates/icinga.conf
  8. +4
    -0
      roles/login/defaults/main.yaml
  9. +0
    -4
      roles/login/meta/main.yaml
  10. +7
    -0
      roles/login/tasks/main.yaml
  11. +5
    -0
      roles/login/templates/login.conf
  12. +0
    -1
      roles/login/templates/login.conf.nginx.j2
  13. +1
    -5
      roles/matrix-synapse/meta/main.yaml
  14. +14
    -5
      roles/matrix-synapse/tasks/main.yaml
  15. +1
    -0
      roles/matrix-synapse/templates/synapse.conf
  16. +0
    -36
      roles/nginx/defaults/main.yml
  17. +7
    -59
      roles/nginx/tasks/main.yaml
  18. +0
    -11
      roles/nginx/templates/proxy.conf.nginx.j2
  19. +20
    -0
      roles/nginx/templates/service.conf
  20. +3
    -1
      roles/riot-web/defaults/main.yaml
  21. +7
    -0
      roles/riot-web/tasks/main.yaml
  22. +7
    -0
      roles/riot-web/templates/riot.conf
  23. +0
    -3
      roles/riot-web/templates/riot.conf.nginx.j2

+ 1
- 3
roles/dokuwiki/meta/main.yaml View File

@ -1,6 +1,4 @@
--- ---
dependencies: dependencies:
- role: nginx - role: nginx
php: true
config_name: "dokuwiki"
parent_role_path: "dokuwiki"
server_fqdn: "wiki.lilik.it"

+ 14
- 6
roles/dokuwiki/tasks/main.yaml View File

@ -1,15 +1,23 @@
--- ---
- name: install dokuwiki and associated packages - name: install dokuwiki and associated packages
apt: apt:
name: "{{ item }}"
state: present
update_cache: yes
cache_valid_time: 3600
name: "{{ item }}"
state: present
update_cache: yes
cache_valid_time: 3600
with_items: with_items:
- dokuwiki
- dokuwiki
- name: add nginx configurations
template:
src: dokuwiki.conf
dest: "/etc/nginx/locations/{{ server_fqdn }}/dokuwiki.conf"
notify:
- restart nginx
- name: Write dokuwiki configuration to local.php - name: Write dokuwiki configuration to local.php
copy: copy:
src: dokuwiki.php src: dokuwiki.php
dest: /etc/dokuwiki/local.php dest: /etc/dokuwiki/local.php
notify: notify:
- restart nginx
- restart nginx

+ 24
- 0
roles/dokuwiki/templates/dokuwiki.conf View File

@ -0,0 +1,24 @@
{% extends "proxy.conf.nginx.j2" %}
{% block proxy_conf %}
root /usr/share/dokuwiki;
index doku.php;
location ~ /(data/|conf/|bin/|inc/|install.php) { deny all; }
location / { try_files $uri $uri/ @dokuwiki; }
location @dokuwiki {
rewrite ^/_media/(.*) /lib/exe/fetch.php?media=$1 last;
rewrite ^/_detail/(.*) /lib/exe/detail.php?media=$1 last;
rewrite ^/_export/([^/]+)/(.*) /doku.php?do=export_$1&id=$2 last;
rewrite ^/(.*) /doku.php?id=$1&$args last;
}
location ~ \.php$ {
try_files $uri $uri/ /doku.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param REDIRECT_STATUS 200;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
{% endblock %}

+ 0
- 20
roles/dokuwiki/templates/dokuwiki.conf.nginx.j2 View File

@ -1,20 +0,0 @@
root /usr/share/dokuwiki;
index doku.php;
location ~ /(data/|conf/|bin/|inc/|install.php) { deny all; }
location / { try_files $uri $uri/ @dokuwiki; }
location @dokuwiki {
rewrite ^/_media/(.*) /lib/exe/fetch.php?media=$1 last;
rewrite ^/_detail/(.*) /lib/exe/detail.php?media=$1 last;
rewrite ^/_export/([^/]+)/(.*) /doku.php?do=export_$1&id=$2 last;
rewrite ^/(.*) /doku.php?id=$1&$args last;
}
location ~ \.php$ {
try_files $uri $uri/ /doku.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param REDIRECT_STATUS 200;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}

+ 1
- 3
roles/icinga2/meta/main.yaml View File

@ -1,7 +1,5 @@
---
dependencies: dependencies:
- role: nginx - role: nginx
php: true
parent_role_path: "icinga2"
config_name: "icinga2"
server_fqdn: "status.lilik.it" server_fqdn: "status.lilik.it"
- role: postgresql - role: postgresql

+ 8
- 0
roles/icinga2/tasks/main.yaml View File

@ -1,3 +1,4 @@
---
- name: configure icinga2-ido-pgsql (host) - name: configure icinga2-ido-pgsql (host)
debconf: debconf:
name: 'icinga2-ido-pgsql' name: 'icinga2-ido-pgsql'
@ -100,3 +101,10 @@
mode: 0770 mode: 0770
with_items: with_items:
- /etc/icinga2/conf.d/hosts/ - /etc/icinga2/conf.d/hosts/
- name: add nginx configurations
template:
src: icinga.conf
dest: "/etc/nginx/locations/{{ server_fqdn }}/service.conf"
notify:
- restart nginx

roles/icinga2/templates/icinga2.conf.nginx.j2 → roles/icinga2/templates/icinga.conf View File


+ 4
- 0
roles/login/defaults/main.yaml View File

@ -1 +1,5 @@
---
ldap_server: ldap.dmz.lilik ldap_server: ldap.dmz.lilik
proxy_location_path: api
remote_host: "http://localhost:5000"
server_fqdn: "login.lilik.it"

+ 0
- 4
roles/login/meta/main.yaml View File

@ -1,8 +1,4 @@
--- ---
dependencies: dependencies:
- role: nginx - role: nginx
is_proxy: true
config_name: "login"
remote_host: "http://localhost:5000"
server_fqdn: "login.lilik.it" server_fqdn: "login.lilik.it"
parent_role_path: "login"

+ 7
- 0
roles/login/tasks/main.yaml View File

@ -61,6 +61,13 @@
mode: 0664 mode: 0664
state: file state: file
- name: add nginx configurations
template:
src: login.conf
dest: "/etc/nginx/locations/{{ server_fqdn }}/login.conf"
notify:
- restart nginx
- name: reload systemd - name: reload systemd
systemd: systemd:
daemon_reload: yes daemon_reload: yes


+ 5
- 0
roles/login/templates/login.conf View File

@ -0,0 +1,5 @@
{% extends "roles/nginx/templates/service.conf" %}
{% block extra %}
root /srv/login/static;
{% block extra %}

+ 0
- 1
roles/login/templates/login.conf.nginx.j2 View File

@ -1 +0,0 @@
rewrite ^/$ /static/index.html permanent;

+ 1
- 5
roles/matrix-synapse/meta/main.yaml View File

@ -1,8 +1,4 @@
--- ---
dependencies: dependencies:
- role: nginx - role: nginx
is_proxy: true
parent_role_path: "matrix-synapse"
remote_host: "http://127.0.0.1:8008/_matrix"
proxy_location_path: "_matrix"
server_fqdn: "{{ ansible_hostname }}.lilik.it"
server_fqdn: "matrix.lilik.it"

+ 14
- 5
roles/matrix-synapse/tasks/main.yaml View File

@ -1,9 +1,10 @@
---
- name: set synapse server name - name: set synapse server name
debconf: debconf:
name: 'matrix-synapse'
question: 'matrix-synapse/server-name'
vtype: 'string'
value: '{{ ansible_hostname }}'
name: 'matrix-synapse'
question: 'matrix-synapse/server-name'
vtype: 'string'
value: '{{ ansible_hostname }}'
- name: install synapse - name: install synapse
include_role: include_role:
@ -25,7 +26,15 @@
- /etc/matrix-synapse - /etc/matrix-synapse
- /etc/matrix-synapse/conf.d - /etc/matrix-synapse/conf.d
- template:
- name: upload synapse reverse proxy conf
template:
src: synapse.conf
dest: "/etc/nginx/locations/{{ server_fqdn }}/synapse.conf"
notify:
- restart nginx
- name: upload synapse conf
template:
src: homeserver.yaml.j2 src: homeserver.yaml.j2
dest: /etc/matrix-synapse/homeserver.yaml dest: /etc/matrix-synapse/homeserver.yaml
notify: "restart matrix-synapse" notify: "restart matrix-synapse"

+ 1
- 0
roles/matrix-synapse/templates/synapse.conf View File

@ -0,0 +1 @@
{% extends "roles/nginx/templates/service.conf" %}

+ 0
- 36
roles/nginx/defaults/main.yml View File

@ -1,38 +1,2 @@
--- ---
is_proxy: false
php: false
config_name: null
# max body size in Mb
max_body_size: 8
server_fqdn: "{{ ansible_hostname }}.lilik.it" server_fqdn: "{{ ansible_hostname }}.lilik.it"
proxy_location_path: ''
# Same example usages:
#
# Redirect trakt folder to a proxy on fqdn_domain,
# create a location file in /etc/nginx/locations/media.lilik.it/trakt.conf
# dependencies:
# - role: nginx
# is_proxy: true
# proxy_location_path: "trakt"
# remote_host: "http://localhost:5000"
# server_fqdn: "media.lilik.it"
# parent_role_path: "trakt"
#
# Serve a location based on role template 'kodi-repository.conf.nginx.j2' on fqdn_domain,
# create a location file in /etc/nginx/locations/media.lilik.it/kodi-repository.conf
# dependencies:
# - role: nginx
# config_name: "kodi-repository"
# server_fqdn: "{{ fqdn_domain }}"
# parent_role_path: "kodi-repository"
#
# Serve a location based on role template 'roundcube.conf.nginx.j2' on fqdn_domain,
# create a location file in /etc/nginx/locations/media.lilik.it/roundcube.conf,
# serve php file using php pfm
# dependencies:
# - role: nginx
# php: true
# config_name: "roundcube"
# server_fqdn: "webmail.lilik.it"
# parent_role_path: "roundcube"

+ 7
- 59
roles/nginx/tasks/main.yaml View File

@ -1,11 +1,10 @@
--- ---
- include_role: - include_role:
name: service name: service
# static: yes # see static include issue: https://github.com/ansible/ansible/issues/13485
vars: vars:
service_name: nginx service_name: nginx
service_packages: service_packages:
- nginx
- nginx
- name: disable nginx default configuration - name: disable nginx default configuration
file: file:
@ -13,27 +12,6 @@
state: absent state: absent
notify: restart nginx notify: restart nginx
- name: install php-fpm
apt:
name: "{{ item }}"
state: present
update_cache: yes
cache_valid_time: 3600
with_items:
- php-fpm
when: php | bool
notify:
- restart nginx
- name: add timezone to php.ini
lineinfile:
dest: /etc/php/7.0/fpm/php.ini
regexp: '^;?date.timezone ='
line: 'date.timezone = Europe/Berlin'
when: php | bool
notify:
- restart nginx
- name: create nginx location configuration directory - name: create nginx location configuration directory
file: file:
path: '{{ item }}' path: '{{ item }}'
@ -47,23 +25,10 @@
- name: upload nginx configuration - name: upload nginx configuration
template: template:
src: base.j2
dest: "/etc/nginx/sites-available/{{ server_fqdn }}.conf"
src: base.j2
dest: "/etc/nginx/sites-available/{{ server_fqdn }}.conf"
notify: notify:
- restart nginx
# - name: add nginx configurations
# template:
# src: "roles/{{ parent_role_path }}/templates/{{ item }}.conf.nginx.j2"
# dest: /etc/nginx/sites-available/{{ item }}.conf
# with_items: "{{ config_names }}"
# notify:
# - restart nginx
# - name: add proxy to config_names
# set_fact:
# config_names: "{{ config_names | union( [config_name])}}"
# when: is_proxy | bool
- restart nginx
- name: create Diffie Hellman exchange parameters - name: create Diffie Hellman exchange parameters
command: openssl dhparam -out /etc/nginx/dhparam.pem 2048 command: openssl dhparam -out /etc/nginx/dhparam.pem 2048
@ -73,24 +38,7 @@
- name: enable nginx configurations - name: enable nginx configurations
file: file:
src: "/etc/nginx/sites-available/{{ server_fqdn }}.conf"
dest: "/etc/nginx/sites-enabled/{{ server_fqdn }}.conf"
state: link
# with_items: "{{ config_names }}"
src: "/etc/nginx/sites-available/{{ server_fqdn }}.conf"
dest: "/etc/nginx/sites-enabled/{{ server_fqdn }}.conf"
state: link
notify: restart nginx notify: restart nginx
- name: upload nginx location configuration from parent role
template:
src: "roles/{{ parent_role_path }}/templates/{{ config_name }}.conf.nginx.j2"
dest: "/etc/nginx/locations/{{ server_fqdn }}/{{ config_name }}.conf"
notify:
- restart nginx
when: 'config_name is not none'
- name: upload nginx location configuration for proxy
template:
src: proxy.conf.nginx.j2
dest: "/etc/nginx/locations/{{ server_fqdn }}/{{ parent_role_path or 'proxy' }}.conf"
notify:
- restart nginx
when: 'is_proxy'

+ 0
- 11
roles/nginx/templates/proxy.conf.nginx.j2 View File

@ -1,11 +0,0 @@
location /{{ proxy_location_path }} {
client_max_body_size {{ max_body_size }}M;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_pass {{ remote_host }};
}

+ 20
- 0
roles/nginx/templates/service.conf View File

@ -0,0 +1,20 @@
{% block proxy_conf %}
{#
This is the default block that gets included if the
child template does not declare a {% block proxy_conf %}
#}
location /{{ proxy_location_path | default("")}} {
client_max_body_size {{ max_body_size | default(8) }}M;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_pass {{ remote_host | default("http://127.0.0.1:8080") }};
}
{% endblock %}
{% block extra %}
{% endblock %}

+ 3
- 1
roles/riot-web/defaults/main.yaml View File

@ -1,2 +1,4 @@
# Based on https://github.com/vector-im/riot-web/releases # Based on https://github.com/vector-im/riot-web/releases
riot_web_version: "v0.12.2"
---
riot_web_version: "v0.15.4"
server_fqdn: "{{ ansible_hostname }}.lilik.it"

+ 7
- 0
roles/riot-web/tasks/main.yaml View File

@ -18,6 +18,13 @@
owner: www-data owner: www-data
group: www-data group: www-data
- template:
src: riot.conf
dest: "/etc/nginx/locations/{{ server_fqdn }}/riot.conf"
notify:
- restart nginx
- template: - template:
src: config.json.j2 src: config.json.j2
dest: "/srv/riot-web/riot-{{ riot_web_version }}/config.json" dest: "/srv/riot-web/riot-{{ riot_web_version }}/config.json"

+ 7
- 0
roles/riot-web/templates/riot.conf View File

@ -0,0 +1,7 @@
{% extends "roles/nginx/templates/service.conf" %}
{% block proxy_conf %}
location / {
root /srv/riot-web/riot-{{ riot_web_version }};
}
{% endblock %}

+ 0
- 3
roles/riot-web/templates/riot.conf.nginx.j2 View File

@ -1,3 +0,0 @@
location / {
root /srv/riot-web/riot-{{ riot_web_version }};
}

Loading…
Cancel
Save