How to print all matched strings using Ansible regex

I wish to match all lines that begin with SSLFile or SSLFile in a file httpd.conf on a remote server and store the matched found strings in a variable for use later in the playbook.

Below is what i did.

`

  • name: Find entries
    shell: “cat /tmp/httpd.conf”
    register: filecontent

  • name: Debug filecontentvar
    debug:
    msg: “{{ filecontent }}”

  • name: Find certificate entries
    set_fact:
    target: “{{ filecontent.stdout | regex_replace('\sSSLFile.*, ‘\1’) }}”

`

Using debug verbose I was able to confirm that the filecontent variable gets the contents of the httpd.conf file of the remote host.

However, the variable called “target” does not get matched lines for searched string despite it being present and errors as below:

TASK [Find certificate entries] ***************************************
task path: /app/test.yml:906
The full traceback is:
Traceback (most recent call last):
File “/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py”, line 144, in run
res = self._execute()
File “/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py”, line 576, in _execute
self._task.post_validate(templar=templar)
File “/usr/lib/python2.7/site-packages/ansible/playbook/task.py”, line 268, in post_validate
super(Task, self).post_validate(templar)
File “/usr/lib/python2.7/site-packages/ansible/playbook/base.py”, line 384, in post_validate
value = templar.template(getattr(self, name))
File “/usr/lib/python2.7/site-packages/ansible/template/init.py”, line 584, in template
disable_lookups=disable_lookups,
File “/usr/lib/python2.7/site-packages/ansible/template/init.py”, line 539, in template
disable_lookups=disable_lookups,
File “/usr/lib/python2.7/site-packages/ansible/template/init.py”, line 773, in do_template
data = _escape_backslashes(data, myenv)
File “/usr/lib/python2.7/site-packages/ansible/template/init.py”, line 145, in _escape_backslashes
for token in jinja_env.lex(d2):
File “/usr/lib/python2.7/site-packages/jinja2/lexer.py”, line 733, in tokeniter
name, filename)
TemplateSyntaxError: unexpected char u’\’ at 64
line 1 fatal: [10.9.9.11]: FAILED! => {
“msg”: “Unexpected failure during module execution.”,
“stdout”: “”
}

I used https://regex101.com to confirm that my \sSSLFile.* condition is good and returns matches on my httpd.conf file.

Can you please suggest ?