I've got a couple strings I'm trying to substitute into an XML file via Ansible with Jinja. The problem is they have some special characters in them like " and <. To get around this, I'm currently doing this for all the fields in question:
<option name="mystring" value="{{ string_in_ansible | replace("&","&") | replace("'","'") | replace("\"",""") | replace("<","<") | replace(">",">") }}"/>
This is a bit verbose and not at all dry when using with multiple variables. Is there anything built in for this kind of case, or a better way to express this?
The thing you are looking for is escape, although in your specific circumstance you may actually be happier with xmlattr
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With