Skip to content
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

Fix warnings for missing paths #1407

Merged
merged 2 commits into from
Jul 20, 2022
Merged
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/fail2ban/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ fail2ban_services_default:
fail2ban_services_custom: []
fail2ban_services: "{{ fail2ban_services_default + fail2ban_services_custom }}"

fail2ban_builtin_filter_templates_path: "{{ playbook_dir }}/roles/fail2ban/templates/filters"
fail2ban_filter_templates_path: fail2ban_filters
14 changes: 11 additions & 3 deletions roles/fail2ban/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@
notify:
- restart fail2ban

- name: Check if fail2ban_filter_templates_path exists
stat:
path: "{{ fail2ban_filter_templates_path }}"
become: no
delegate_to: localhost
register: fail2ban_filter_templates_path_result

- name: build list of fail2ban filter templates
find:
paths:
- "{{ playbook_dir }}/roles/fail2ban/templates/filters"
- "{{ fail2ban_filter_templates_path }}"
paths: "{{ fail2ban_filter_templates_path_result.stat.isdir is defined | ternary(
[fail2ban_builtin_filter_templates_path, fail2ban_filter_templates_path],
[fail2ban_builtin_filter_templates_path]
) }}"
pattern: "*.conf.j2"
become: no
delegate_to: localhost
Expand Down
99 changes: 57 additions & 42 deletions roles/wordpress-setup/tasks/nginx-includes.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,64 @@
---
- name: Build list of Nginx includes templates
find:
paths:
- "{{ nginx_includes_templates_path }}"
pattern: "*.conf.j2"
recurse: yes
- stat:
path: "{{ nginx_includes_templates_path }}"
become: no
delegate_to: localhost
register: nginx_includes_templates
register: nginx_includes_local_directory

- name: Create includes.d directories
file:
path: "{{ nginx_path }}/includes.d/{{ item }}"
state: directory
mode: '0755'
with_items: "{{ nginx_includes_templates.files | map(attribute='path') |
map('regex_replace', nginx_includes_pattern, '\\2') |
map('dirname') | unique | list | sort
}}"
when: nginx_includes_templates.files | count
- block:
- name: Build list of Nginx includes templates
find:
paths: "{{ nginx_includes_templates_path }}"
pattern: "*.conf.j2"
recurse: yes
become: no
delegate_to: localhost
register: nginx_includes_templates

- name: Template files out to includes.d
template:
src: "{{ item }}"
dest: "{{ nginx_path }}/includes.d/{{ item | regex_replace(nginx_includes_pattern, '\\2') }}"
mode: '0644'
with_items: "{{ nginx_includes_templates.files | map(attribute='path') | list | sort(True) }}"
notify: reload nginx
- name: Create includes.d directories
file:
path: "{{ nginx_path }}/includes.d/{{ item }}"
state: directory
recurse: yes
mode: '0755'
with_items: "{{ nginx_includes_templates.files | map(attribute='path') |
map('regex_replace', nginx_includes_pattern, '\\2') |
map('dirname') | unique | list | sort
}}"
when: nginx_includes_templates.files | count

- name: Retrieve list of existing files in includes.d
find:
paths: "{{ nginx_path }}/includes.d"
pattern: "*.conf"
recurse: yes
register: nginx_includes_existing
when: nginx_includes_d_cleanup | bool
- name: Template files out to includes.d
template:
src: "{{ item }}"
dest: "{{ nginx_path }}/includes.d/{{ item | regex_replace(nginx_includes_pattern, '\\2') }}"
mode: '0644'
with_items: "{{ nginx_includes_templates.files | map(attribute='path') | list | sort(True) }}"
notify: reload nginx
when: nginx_includes_local_directory.stat.isdir is defined

- name: Cleanup old unmanaged Nginx includes
block:
- stat:
path: "{{ nginx_path }}/includes.d"
register: nginx_includes_directory

- name: Remove unmanaged files from includes.d
file:
path: "{{ item }}"
state: absent
with_items: "{{ nginx_includes_existing.files | default({}) | map(attribute='path') |
difference(nginx_includes_templates.files | map(attribute='path') |
map('regex_replace', nginx_includes_pattern, nginx_path + '/includes.d/\\2') | unique
) | list
}}"
when: nginx_includes_d_cleanup
notify: reload nginx
- name: Retrieve list of existing files in includes.d
find:
paths: "{{ nginx_path }}/includes.d"
pattern: "*.conf"
recurse: yes
register: nginx_includes_existing
when: nginx_includes_directory.stat.isdir is defined

- name: Remove unmanaged files from includes.d
file:
path: "{{ item }}"
state: absent
with_items: "{{ nginx_includes_existing.files | default({}) | map(attribute='path') |
difference(nginx_includes_templates.files | default({} )| map(attribute='path') |
map('regex_replace', nginx_includes_pattern, nginx_path + '/includes.d/\\2') | unique
) | list
}}"
when: nginx_includes_directory.stat.isdir is defined
notify: reload nginx
when: nginx_includes_d_cleanup | bool