Skip to content

Commit

Permalink
Merge pull request #1407 from roots/fix-warnings-for-missing-paths
Browse files Browse the repository at this point in the history
Fix warnings for missing paths
  • Loading branch information
swalkinshaw authored Jul 20, 2022
2 parents e6bb065 + b06a2f3 commit 5827b36
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 45 deletions.
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

0 comments on commit 5827b36

Please sign in to comment.