2023-12-11 16:54:07 +01:00
|
|
|
---
|
|
|
|
- name: Find all .conf
|
|
|
|
ansible.builtin.find:
|
2023-12-12 12:32:35 +01:00
|
|
|
paths: "{{nginx_servers_directory}}"
|
2023-12-11 16:54:07 +01:00
|
|
|
patterns: '*.*.conf'
|
|
|
|
register: conf_files
|
|
|
|
|
|
|
|
- name: Filter domain names and remove .conf extension and path
|
|
|
|
set_fact:
|
2023-12-12 15:50:57 +01:00
|
|
|
filtered_domains: "{{ conf_files.files | map(attribute='path') | map('regex_search', domain_regex) | select('string') | map('regex_replace', path_regex, '') | map('regex_replace', '.conf$', '') | list }}"
|
2023-12-11 16:54:07 +01:00
|
|
|
vars:
|
2023-12-12 15:50:57 +01:00
|
|
|
domain_regex: "^{{ nginx_servers_directory }}(?!www\\.)[^/]+\\.conf$"
|
|
|
|
path_regex: "^{{ nginx_servers_directory }}"
|
2023-12-11 16:54:07 +01:00
|
|
|
|
2023-12-11 19:45:42 +01:00
|
|
|
- name: The domains for which a www. redirect will be implemented
|
2023-12-11 16:54:07 +01:00
|
|
|
debug:
|
|
|
|
var: filtered_domains
|
|
|
|
|
|
|
|
- name: Include nginx-domain-redirect role with dynamic domain mappings
|
|
|
|
include_role:
|
|
|
|
name: nginx-domain-redirect
|
|
|
|
vars:
|
2023-12-12 17:43:13 +01:00
|
|
|
domain_mappings: "{{ filtered_domains | map('regex_replace', '^(.*)$', '{ source: \"www.\\1\", target: \"\\1\" }') | map('from_yaml') | list }}"
|