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