Skip to content

Filter Nginx includes by sites present on target server #1573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions roles/wordpress-setup/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ nginx_cache_background_update: "on"
nginx_includes_templates_path: nginx-includes
nginx_includes_pattern: "^({{ nginx_includes_templates_path | regex_escape }})/(.*)\\.j2$"
nginx_includes_d_cleanup: true
nginx_includes_extra_folders: 'all'

# h5bp helpers
not_dev: "{{ env != 'development' }}"
Expand Down
25 changes: 24 additions & 1 deletion roles/wordpress-setup/tasks/nginx-includes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,30 @@
recurse: yes
become: no
delegate_to: localhost
register: nginx_includes_templates
register: nginx_includes_templates_all

- name: Normalize extra include folders to a list
set_fact:
nginx_includes_extra_folders_list: >-
{{
nginx_includes_extra_folders
if nginx_includes_extra_folders is iterable and not nginx_includes_extra_folders is string
else [nginx_includes_extra_folders | default('all')]
}}

- name: Combine site keys with extra include folders
set_fact:
nginx_include_contexts: "{{ wordpress_sites.keys() | list + nginx_includes_extra_folders_list }}"

- name: Filter Nginx includes templates by existing sites and extra folders
set_fact:
nginx_includes_templates:
files: >-
{{
nginx_includes_templates_all.files
| selectattr('path', 'search', '/(' + nginx_include_contexts | join('|') + ')/')
| list
}}

- name: Create includes.d directories
file:
Expand Down