As far as I can see the built-in Jinja filter escape does this, so for 
example

- name: escape
  command: echo "{{ 'a&b' | escape }}"

produces

TASK [test : escape] **************************************************
changed: [localhost] => {"changed": true, "cmd": ["echo", "a&b"], 
"delta": "0:00:00.018286", "end": "2017-04-12 11:16:17.629886", "rc": 0, 
"start": "2017-04-12 11:16:17.611600", "stderr": "", "stdout": "a&b", 
"stdout_lines": ["a&b"], "warnings": []}

Alexey


среда, 30 ноября 2016 г., 21:41:16 UTC+7 пользователь 
[email protected] написал:
>
>
>
> On Monday, November 7, 2016 at 3:15:59 PM UTC+1, [email protected] 
> wrote:
>>
>> I would like this escaping to be done automatically, how should I proceed?
>>
>> I've looked for "xml escaping jinja filter" without any luck.
>>
>
> For the record, the solution was to write my own xml-escaping filter 
> plugin.
>
> Which is easy enough:
>
> $ cat filter_plugins/myfilters.py
> # Make coding more python3-ish
> from __future__ import (absolute_import, division, print_function)
> __metaclass__ = type
> import xml.sax.saxutils
> class FilterModule(object):
>     ''' my jinja2 filters for ansible'''
>     def filters(self):
>         return {'escape_xml_attr' : xml.sax.saxutils.quoteattr,
>                 'escape_xml_data' : xml.sax.saxutils.escape}
>
> Then, use it like this
>
>  - { role: jenkinspipelinejob, name: 'feeds', script: "{{ lookup('file', 
> 'jenkins/jobs/feeds/script.groovy') | escape_xml_data }}" }
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/7a1ca3b3-f2e4-477d-a823-9bf2479a2c79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to