I'd like to add a block between <IfModule mod_ssl.c>
and </IfModule>
in /etc/apache2/mods-available/ssl.conf
with the ansible task shown below. I use blockinfile
and insertbefore
.
Unfortunately the block is always added after </IfModule>
at the bottom of the file. I guess my regex is wrong.
- name: Apache2 > update SSL conf
become: yes
blockinfile:
path: /etc/apache2/mods-available/ssl.conf
block: |
# Requires Apache >= 2.4
SSLCompression off
SSLUseStapling on
SSLStaplingCache "shmcb:logs/stapling-cache(150000)"
# Requires Apache >= 2.4.11
SSLSessionTickets Off
Header always set Strict-Transport-Security "max-age=15768000; includeSubDomains"
Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure
marker: ""
insertbefore: '^<\/IfModule>'
notify:
- Restart apache2
I have tried the following regex without success:
insertbefore: '/^<\/IfModule>/m'
insertbefore: "<\/IfModule>"
insertbefore: "</IfModule>"
insertbefore: "</IfModule> "
insertbefore: '^<\/IfModule>$'
insertbefore: "</IfModule>"
insertbefore: '(?m)^<\/IfModule>\\s?$'
insertbefore: '^</IfModule>\s?$'
I would be very grateful if anyone could help me to fix my regex. Thanks.