Venkata Jaswanth
Venkata Jaswanth

Reputation: 1921

Template in block is not running filters properly in ansible

When using the blockinfile module of ansible, if we use regex_replace filter the filters arguments have to changed in order to get it working. This is against the documentation of the filter. Is it that the escaping is done by the template engine?

https://github.com/ansible/ansible-modules-extras/issues/3105

Upvotes: 0

Views: 134

Answers (1)

Konstantin Suvorov
Konstantin Suvorov

Reputation: 68269

It's generally a bad practice to ask questions with links to external site with essential information.

As for your problem, you use or don't use escaping depending on outer string quotes:

# don't escape
block: |
       RewriteCond %{HTTP_HOST} ={{ url | regex_replace('(?:https?://)?([^/:]+)?.*', '\1')  }}

# escape
block: "RewriteCond %{HTTP_HOST} ={{ url | regex_replace('(?:https?://)?([^/:]+)?.*', '\\1')  }}"

Upvotes: 1

Related Questions