On 04/26/2016 02:34 PM, Cavette wrote:
My code below doesn't work (invalid group reference) :
- name : Change IP in file
replace: dest=myfile.xml regexp='(.*){{master_ip}}(.*)'
replace='\1{{ansible_default_ipv4.address}}\2'
But If i put 1 space before and after my variable, it works but have
useless spaces.
I think the problem might be this.
Lets say that ansible_default_ipv4.address is 2.2.2.2
Then your replace will be '\12.2.2.2\2', so the group you are
referencing is \12 and not \1.
Python re.sub has an alternative way that should work,
replace: dest=myfile.xml regexp='(.*){{master_ip}}(.*)'
replace='\g<1>{{ansible_default_ipv4.address}}\g<2>'
You can read more about it here
https://docs.python.org/2/library/re.html#re.sub
--
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 [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/e76285e5-1817-b0ac-d585-a1abaa527e37%40olstad.com.
For more options, visit https://groups.google.com/d/optout.