Add nginx_prune_sites to remove sites dropped from nginx_sites
This commit is contained in:
@@ -8,6 +8,48 @@
|
||||
- Validate nginx configuration
|
||||
- Reload nginx
|
||||
|
||||
- name: Find existing site configs
|
||||
ansible.builtin.find:
|
||||
paths: "{{ nginx_site_config_path }}"
|
||||
file_type: file
|
||||
register: nginx_existing_site_configs
|
||||
when: nginx_prune_sites
|
||||
|
||||
- name: Remove site configs no longer in nginx_sites
|
||||
ansible.builtin.file:
|
||||
path: "{{ item.path }}"
|
||||
state: absent
|
||||
loop: "{{ nginx_existing_site_configs.files | default([]) }}"
|
||||
loop_control:
|
||||
label: "{{ item.path | basename }}"
|
||||
when:
|
||||
- nginx_prune_sites
|
||||
- (item.path | basename) not in (nginx_sites | map(attribute='name') | list)
|
||||
notify:
|
||||
- Validate nginx configuration
|
||||
- Reload nginx
|
||||
|
||||
- name: Find existing enabled-site symlinks
|
||||
ansible.builtin.find:
|
||||
paths: "{{ nginx_site_enabled_path }}"
|
||||
file_type: any
|
||||
register: nginx_existing_enabled_sites
|
||||
when: nginx_prune_sites
|
||||
|
||||
- name: Remove enabled-site symlinks no longer in nginx_sites
|
||||
ansible.builtin.file:
|
||||
path: "{{ item.path }}"
|
||||
state: absent
|
||||
loop: "{{ nginx_existing_enabled_sites.files | default([]) }}"
|
||||
loop_control:
|
||||
label: "{{ item.path | basename }}"
|
||||
when:
|
||||
- nginx_prune_sites
|
||||
- (item.path | basename) not in (nginx_sites | map(attribute='name') | list)
|
||||
notify:
|
||||
- Validate nginx configuration
|
||||
- Reload nginx
|
||||
|
||||
- name: Add all the template site configurations
|
||||
ansible.builtin.template:
|
||||
src: "{{ item.template_path | default(nginx_site_config_template) }}"
|
||||
|
||||
Reference in New Issue
Block a user