dr1
April 6, 2016, 4:25pm
1
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
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
dr1
April 8, 2016, 1:01pm
3
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)