0

my ansible play book is working for me to uncomment certain lines in a .conf file, but its failing for one particular line its not making any change.

below is my .conf file part.

   #<VirtualHost *:443>
      #SSLEnable
   #Header always set Strict-Transport-Security "max-age=31536000 includeSubDomains; preload"
   #</VirtualHost>

Expected output


       <VirtualHost *:443>
          SSLEnable
       #Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
        </VirtualHost>

below is my play

   - name: uncomment virtualhost starting line
     replace:
       path: /opt/conf/httpd.conf
       regexp: '^#(.*<VirtualHost *:443>.*)'
       replace: '\1'
   - name: uncomment virtualhost end line
       replace:
         path: /opt/conf/httpd.conf
         regexp: '^#(.*</VirtualHost>.*)'
         replace: '\1'

Here my virtualhost end line is getting uncommented but the startline is not.. can you please guide me here.....

saran
  • 3
  • 2

2 Answers2

0

* is a special character in a regular expression, it's a wildcard.

Replace the first task with the following(I have modified only the regexp parameter):

   - name: uncomment virtualhost starting line
     replace:
       path: /opt/conf/httpd.conf
       regexp: '^#(.*<VirtualHost \*:443>.*)'
       replace: '\1'
NoNoNo
  • 1,939
  • 14
  • 19
0

Try to escape the * in *:443. Otherwise, it will be interpreted as control char for the regexp:

regexp: '^#(.*<VirtualHost \*:443>.*)'

https://docs.python.org/2/library/re.html

Sven
  • 97,248
  • 13
  • 177
  • 225