change way of enabling/disabling apache modules for Redhat

use file.comment and file.uncomment builtin states instead of sed
command
This commit is contained in:
Karim Hamza 2019-04-23 12:47:00 +02:00
parent ba2368907d
commit 84e5328906

View File

@ -31,27 +31,47 @@ a2dismod -f {{ module }}:
include: include:
- apache - apache
- apache.config
- apache.vhosts.vhost
{% for module in salt['pillar.get']('apache:modules:enabled', default=hardening_values.modules.enforce_enabled, merge=True) if module not in hardening_values.modules.enforce_disabled %} {% set modules_enabled = salt['pillar.get']('apache:modules:enabled', default=hardening_values.modules.enforce_enabled, merge=True) %}
find /etc/httpd/ -name '*.conf' -type f -exec sed -i -e 's/\(^#\)\(\s*LoadModule.{{ module }}_module\)/\2/g' {} \;: {% set conf_files = salt['file.find'](path='/etc/httpd/', type='f', name='*.conf') %}
cmd.run:
- unless: httpd -M 2> /dev/null | grep "[[:space:]]{{ module }}_module" {% for module in modules_enabled if module not in hardening_values.modules.enforce_disabled %}
- order: 225
{% for conf_file in conf_files if salt['file.search'](path=conf_file, pattern='LoadModule.' ~ module ) %}
enable_{{ module }}_{{ conf_file }}:
file.uncomment:
- name: {{ conf_file }}
- regex: LoadModule.{{ module }}
- require: - require:
- pkg: apache - pkg: apache
- sls: apache.config
- sls: apache.vhosts.vhost
- watch_in: - watch_in:
- module: apache-restart - module: apache-restart
{% endfor %}
{% endfor %} {% endfor %}
{% for module in salt['pillar.get']('apache:modules:disabled', default=hardening_values.modules.enforce_disabled, merge=True) if module not in hardening_values.modules.enforce_enabled %} {% set modules_disabled = salt['pillar.get']('apache:modules:disabled', default=hardening_values.modules.enforce_disabled, merge=True) %}
find /etc/httpd/ -name '*.conf' -type f -exec sed -i -e 's/\(^\s*LoadModule.{{ module }}_module\)/#\1/g' {} \;:
cmd.run: {% for module in modules_disabled if module not in hardening_values.modules.enforce_enabled %}
- onlyif: httpd -M 2> /dev/null | grep "[[:space:]]{{ module }}_module" {% for conf_file in conf_files if salt['file.search'](path=conf_file, pattern='LoadModule.' ~ module ) %}
- order: 225
disable_{{ module }}_{{ conf_file }}:
file.comment:
- name: {{ conf_file }}
- regex: LoadModule.{{ module }}
- require: - require:
- pkg: apache - pkg: apache
- sls: apache.config
- sls: apache.vhosts.vhost
- watch_in: - watch_in:
- module: apache-restart - module: apache-restart
{% endfor %}
{% endfor %} {% endfor %}