Hello Kai,

Thanks for your response.
Actually the issue here is that these pattern value and replace text values
are provided to the playbook using surveys i.e., during run time and hence,
it won't be possible to manually escape them by the users who run the
template.

Is there a way to auto escape  any special chars in the pattern and replace
the text without escaped values in the file?

*Regards,*
*Ankit*


On Fri, Oct 25, 2019 at 12:15 AM Kai Stian Olstad <
ansible-project+l...@olstad.com> wrote:

> On 23.10.2019 08:35, Ankit wrote:
> > ---
> > - hosts: all
> >    gather_facts: false
> >    vars:
> >      *var1:* '[monitor://D:\Logs\Org.SNP.Publisher\*]'
> >      *var2**:* '[monitor://D:\new\path\dir\*]'
> >    tasks:
> >        - name: test unsafe variable in the file
> >          replace:
> >            path: /home/anks/yaml/filewithcontent
> >            regexp: '{{ *var1 *| regex_escape() }}'
> >            replace: "{{ *var2 *}}"
> > ...
> >
> > I have been trying different things like *unsafe!* , *regex_replace()*
> but
> > it doesn't seem to work. Could anyone please suggest how can i achieve
> this?
>
> Replace module is using Python re[1] module.
> Your replace: contain escape sequences, if Python re recognize a escape
> sequence it will replace it.
>
> You have \n, \b and \d of these Python re do recognize \n at least, so you
> need to be escaped it by putting an extra \ in it so it becomes \\n
>
>
> [1] https://docs.python.org/2/library/re.html
>
> --
> Kai Stian Olstad
>
> --
> 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 ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/9dab55f4-2443-88a7-8fda-2c58131254e4%40olstad.com
> .
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACecUhv2qoPo%2Bi62MQ5h_ASeTzD2DMcR7Amr0LNcpwjXGkZYtg%40mail.gmail.com.

Reply via email to