changed the way vhosts are created to prevent creation of vhosts without certificate

This commit is contained in:
muppeth 2024-02-24 00:50:09 +01:00
parent 31bfe12f38
commit 91cc0fd69b
Signed by: muppeth
GPG Key ID: 0EBC7B9848D04031
1 changed files with 80 additions and 9 deletions

View File

@ -3,19 +3,48 @@
slurp:
src: "/var/lib/tor/{{ item.name }}/hostname"
register: "onion_address"
when: item.onion is defined and item.onion == 'true'
when:
- item.onion is defined
- item.onion == 'true'
- name: "[NGINX] - Set fact"
set_fact:
enable_tor: 'false'
- name: "[NGINX] - Check if the certificate for the vhost exists"
stat:
path: '{{ nginx_ssl_dir }}/{{ item.name }}/privkey.pem'
register: cert_exists
when:
- item.sslname is defined
- name: 'DEBUG'
debug:
msg: 'The var is there {{ cert_exists }}'
when: cert_exists
- name: "[NGINX] - Create vhosts"
- name: "[NGINX] - Create HTTPS vhosts"
template:
src: etc/nginx/sites-available/{{ item.template }}.j2
dest: "{{ nginx_etc_dir }}/sites-available/{{ item.name }}"
notify:
- reload nginx
when: item.state is defined and item.state != 'delete'
when:
- cert_exists is defined
- cert_exists.skipped == 'false'
- cert_exists.stat.exists == 'true'
- item.state is defined
- item.state != 'delete'
- name: "[NGINX] - Create HTTP vhosts"
template:
src: etc/nginx/sites-available/{{ item.template }}.j2
dest: "{{ nginx_etc_dir }}/sites-available/{{ item.name }}"
notify:
- reload nginx
when:
- item.ssl_name is not defined
- item.state is defined
- item.state != 'delete'
- name: "[NGINX] - Delete vhosts"
file:
@ -23,16 +52,35 @@
state: absent
notify:
- reload nginx
when: item.state is defined and item.state == 'delete'
when:
- item.state is defined
- item.state == 'delete'
- name: "[NGINX] - Enable vhosts"
- name: "[NGINX] - Enable HTTPS vhosts"
file:
src: "{{ nginx_etc_dir }}/sites-available/{{ item.name }}"
dest: "{{ nginx_etc_dir }}/sites-enabled/{{ item.name }}"
state: link
notify:
- reload nginx
when: item.state is defined and item.state == 'enable'
when:
- cert_exists is defined
- cert_exists.skipped == 'false'
- cert_exists.stat.exists == 'true'
- item.state is defined
- item.state == 'enable'
- name: "[NGINX] - Enable HTTP vhosts"
file:
src: "{{ nginx_etc_dir }}/sites-available/{{ item.name }}"
dest: "{{ nginx_etc_dir }}/sites-enabled/{{ item.name }}"
state: link
notify:
- reload nginx
when:
- item.ssl_name is not defined
- item.state is defined
- item.state == 'enable'
- name: "[NGINX] - Disable vhosts"
file:
@ -40,7 +88,10 @@
state: absent
notify:
- reload nginx
when: item.state is defined and (item.state == 'disable' or item.state == 'delete')
when:
- item.state is defined
- item.state == 'disable'
- item.state == 'delete'
- name: "[NGINX] - Delete default vhost when explicitely defined"
file:
@ -50,10 +101,30 @@
- reload nginx
when: nginx_default_vhost is not none
- name: "[NGINX] - Create maintenance vhosts"
- name: "[NGINX] - Create HTTPS maintenance vhosts"
template:
src: etc/nginx/sites-available/maintenance.j2
dest: "{{ nginx_etc_dir }}/sites-available/maintenance-{{ item.name }}"
notify:
- reload nginx
when: (item.state is defined) and (item.state != 'delete') and (item.maintenance is defined) and (item.maintenance == 'true')
when:
- cert_exists is defined
- cert_exists.skipped == 'false'
- cert_exists.stat.exists == 'true'
- item.state is defined
- item.state != 'delete'
- item.maintenance is defined
- item.maintenance == 'true'
- name: "[NGINX] - Create HTTP maintenance vhosts"
template:
src: etc/nginx/sites-available/maintenance.j2
dest: "{{ nginx_etc_dir }}/sites-available/maintenance-{{ item.name }}"
notify:
- reload nginx
when:
- item.ssl_name is not defined
- item.state is defined
- item.state != 'delete'
- item.maintenance is defined
- item.maintenance == 'true'