uncommenting a line in file is not working

18 views
Skip to first unread message

vowner

unread,
Nov 27, 2018, 10:27:02 AM11/27/18
to Ansible Project
Hello Experts,

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.....

Kai Stian Olstad

unread,
Nov 27, 2018, 11:07:03 AM11/27/18
to ansible...@googlegroups.com
You have a * in you data, * is a regexp special character, when you are using a special character as a literal character you need to escape it.
So this should work:
regexp: '^#(.*<VirtualHost \*:443>.*)'


--
Kai Stian Olstad


visar

unread,
Nov 27, 2018, 11:59:43 AM11/27/18
to Ansible Project
Hello Kai,

Great Advise!!!!! Thanks a lot for your help. It worked like a magic... 
Reply all
Reply to author
Forward
0 new messages