win_lineinfile backrefs not working

245 views
Skip to first unread message

d...@stylelabs.com

unread,
Apr 6, 2016, 12:46:49 PM4/6/16
to Ansible Project
Hello great people of ansible persuasion,

I'm trying to do some win_lineinfile with backrefs.

Being a core module, it could be I'm doing it wrong, so here it goes - let me know if you have any clue:

      win_lineinfile:
        dest
: c:\Windows\System32\inetsrv\config\applicationHost.config
        regexp
: '^(.*)<urlCompression \/>$'
        line
: '\1<urlCompression doStaticCompression="true" doDynamicCompression="true" />'
        state
: present
        backrefs
: yes
        backup
: yes

It's runninng against this

        <urlCompression />

and after execution I end up with this 

\1<urlCompression doStaticCompression="true" doDynamicCompression="true" />

it does the job, but i get the \1 instead of the group of spaces. Am I missing anything?



Brussels · New York · stylelabs.com


Join our team and help us create and innovate ⓜ Marketing Content Hub, one of the most user-friendly content marketing tools on the market.

Belgium:  Senior Web Developer  -  Senior Dotnet Developer  -  Dotnet Developer  -  Project Manager  -  Solution Architect  -  Business Analyst 
United States:  Senior Dotnet Developer

J Hawkesworth

unread,
Apr 6, 2016, 3:35:39 PM4/6/16
to Ansible Project
 Not used this module myself but I think perhaps you need to use $1 instead of \1

Have a look at the integration tests for this module here:

https://github.com/ansible/ansible/blob/devel/test/integration/roles/test_win_lineinfile/tasks/main.yml

There's a task that looks like this


- name: replace a line with backrefs included in the line
  win_lineinfile
: dest={{win_output_dir}}/test.txt state=present line="New $1 created with the backref" backrefs=yes regexp="^This is (line 4)$"

hence suggestion to try using $1

HTH

Jon

d...@stylelabs.com

unread,
Apr 8, 2016, 9:01:54 AM4/8/16
to Ansible Project
Yap, that works, it's .net regexp after all /me silly. Thx for pointing it out

Also, regading this module the idempotence is slightly broken - I've opened an issue (and provided a dirty fix)
Reply all
Reply to author
Forward
0 new messages