mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2024-11-10 06:51:04 +01:00
24 lines
937 B
YAML
24 lines
937 B
YAML
---
|
|
- name: Find all .conf
|
|
ansible.builtin.find:
|
|
paths: "{{nginx_servers_directory}}"
|
|
patterns: '*.*.conf'
|
|
register: conf_files
|
|
|
|
- name: Filter domain names and remove .conf extension and path
|
|
set_fact:
|
|
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 }}"
|
|
vars:
|
|
domain_regex: "^{{ nginx_servers_directory }}(?!www\\.)[^/]+\\.conf$"
|
|
path_regex: "^{{ nginx_servers_directory }}"
|
|
|
|
- name: The domains for which a www. redirect will be implemented
|
|
debug:
|
|
var: filtered_domains
|
|
|
|
- name: Include nginx-domain-redirect role with dynamic domain mappings
|
|
include_role:
|
|
name: nginx-domain-redirect
|
|
vars:
|
|
domain_mappings: "{{ filtered_domains | map('regex_replace', '^(.*)$', '{ source: \"www.\\1\", target: \"\\1\" }') | map('from_yaml') | list }}"
|