On Thu, 24 Oct 2019 02:32:05 -0700 (PDT)
Ankit <ankitvashis...@gmail.com> wrote:

> > replace [monitor://D:\Logs\Org.SNP.Publisher\*]
> > to      [monitor://D:\new\path\dir\*]
> >
> > ---
> > - 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 *}}"
> > ...

Try this

    - replace:
        path: 'playbook.yml'
        regexp: '{{ regex }}'
        replace: '{{ replace }}'
      vars:
        regex: '\[monitor\://D\:\\Logs\\Org\.SNP\.Publisher\\\*]'
        replace: '[monitor://D:\\new\\path\\dir\\*]'


1) Put *regex* and *replace* into separate variables and use "7.3.2.
   Single-Quoted Style".
   Quoting: '...the “\” and “"” characters may be freely used. This restricts
   single-quoted scalars to printable characters ...'
   https://yaml.org/spec/1.2/spec.html#id2788097

2) In *regex* escape Python regular expressions special characters only
   https://pythex.org/

3) In *replace* escape control characters only
   https://en.wiktionary.org/wiki/Appendix:Control_characters

Cheers,

        -vlado

-- 
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/20191030055257.519293a8%40gmail.com.

Attachment: pgpmMidw125Ne.pgp
Description: OpenPGP digital signature

Reply via email to