Skip to content

Commit f1faaa9

Browse files
committed
Ensure that the rewrite module is loaded when required by the role
1 parent b1231f7 commit f1faaa9

File tree

3 files changed

+45
-30
lines changed

3 files changed

+45
-30
lines changed

CHANGES.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The current role maintainer_ is ypid_.
1212

1313

1414
debops.apache v0.1.0 - unreleased
15-
----------------------------------------
15+
---------------------------------
1616

1717
Added
1818
~~~~~
@@ -66,6 +66,9 @@ Fixed
6666
for :envvar:`apache__ocsp_stapling_cache`. Before, the ``socache_shmcb``
6767
module was implicitly loaded by the ``ssl`` module. [ypid_]
6868

69+
- Ensure that the rewrite module is loaded when it is used by the configuration
70+
generated by the role. [ypid_]
71+
6972
- Fix ``item.https_enabled`` support for virtual hosts. This variable was
7073
ignored previously using the global default (``True``) directly. [ypid_]
7174

defaults/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,11 @@ apache__role_modules:
333333
enabled: '{{ True
334334
if (apache__status_enabled|bool
335335
and apache__status_allow_localhost)
336+
else omit }}'
337+
'rewrite':
338+
enabled: '{{ True
339+
if (apache__register_mod_rewrite_used is defined and
340+
apache__register_mod_rewrite_used.rc|d(1) == 0)
336341
else omit }}'
337342

338343
# ]]]

tasks/main.yml

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,6 @@
1010
- '{{ apache__packages }}'
1111
- '{{ apache__dependent_packages }}'
1212

13-
# Manage Apache modules [[[1
14-
15-
- name: Get list of available modules
16-
find:
17-
file_type: 'file'
18-
paths: [ '{{ apache__config_path + "/mods-available/" }}' ]
19-
patterns: [ '*.load' ]
20-
register: apache__register_mods_available
21-
tags: [ 'role::apache:modules' ]
22-
23-
- name: Set list of available modules
24-
set_fact:
25-
apache__tpl_available_modules: '{{ apache__register_mods_available.files|d({}) | map(attribute="path") | map("replace", apache__config_path + "/mods-available/", "") | map("regex_replace", "\.load$", "") | list }}'
26-
tags: [ 'role::apache:modules' ]
27-
28-
- name: Enable/disable Apache modules
29-
apache2_module:
30-
name: '{{ item.key }}'
31-
state: '{{ (item.value.enabled
32-
if (item.value is mapping)
33-
else item.value) | bool | ternary("present", "absent") }}'
34-
force: '{{ item.value.force|d(False) | bool }}'
35-
notify: [ 'Test apache and reload' ]
36-
when: (item.key in apache__tpl_available_modules
37-
and item.value.enabled|d(True) != omit
38-
and apache__deploy_state == "present")
39-
with_dict: '{{ apache__combined_modules }}'
40-
tags: [ 'role::apache:modules' ]
41-
4213
# Manage Apache configuration snippets [[[1
4314
- name: Divert conf-available configuration
4415
command: dpkg-divert --quiet --local
@@ -137,3 +108,39 @@
137108
when: (item.type|d(apache__vhost_type) not in ["divert"])
138109
with_flattened: '{{ apache__combined_vhosts }}'
139110
tags: [ 'role::apache:vhosts' ]
111+
112+
# Manage Apache modules [[[1
113+
- name: Detect if the rewrite module has been used in the active configuration
114+
shell: grep --ignore-case '^\s*RewriteEngine On' {{ apache__config_path | quote }}/sites-enabled/* {{ apache__config_path | quote }}/conf-enabled/*
115+
register: apache__register_mod_rewrite_used
116+
always_run: True
117+
failed_when: apache__register_mod_rewrite_used.rc not in [ 0, 1 ]
118+
changed_when: False
119+
when: apache__register_mod_rewrite_used is undefined
120+
121+
- name: Get list of available modules
122+
find:
123+
file_type: 'file'
124+
paths: [ '{{ apache__config_path + "/mods-available/" }}' ]
125+
patterns: [ '*.load' ]
126+
register: apache__register_mods_available
127+
tags: [ 'role::apache:modules' ]
128+
129+
- name: Set list of available modules
130+
set_fact:
131+
apache__tpl_available_modules: '{{ apache__register_mods_available.files|d({}) | map(attribute="path") | map("replace", apache__config_path + "/mods-available/", "") | map("regex_replace", "\.load$", "") | list }}'
132+
tags: [ 'role::apache:modules' ]
133+
134+
- name: Enable/disable Apache modules
135+
apache2_module:
136+
name: '{{ item.key }}'
137+
state: '{{ (item.value.enabled
138+
if (item.value is mapping)
139+
else item.value) | bool | ternary("present", "absent") }}'
140+
force: '{{ item.value.force|d(False) | bool }}'
141+
notify: [ 'Test apache and reload' ]
142+
when: (item.key in apache__tpl_available_modules
143+
and item.value.enabled|d(True) != omit
144+
and apache__deploy_state == "present")
145+
with_dict: '{{ apache__combined_modules }}'
146+
tags: [ 'role::apache:modules' ]

0 commit comments

Comments
 (0)