I have been thinking about doing this with lineinfile with backrefs, or with the replace module, but I am at a loss as to where to start (I am horrible with regexp…)
Consider the following:
vif = ['mac=00:21:f6:A1:B7:49,bridge=1053d3f53c']
I would like to replace the last three octets, but leave everything else alone:
ie
I am using a regexp tester, but am not getting the results I would like. Is regexp the right way to tackle this? Is there another/better way? If the former, I could use some regexp help. Thanks in advance.
Well, not ansible, but you should be able to use as a reference. This works with sed: sed -e"s|^\(vif=\['mac=..:..:..:\)..:..:..\(,bridge=.*'\]\)$|\1AA:BB:CC\2|" file
where file has your text.
Awesome, thanks guys! Kai, I am unsure if I would have got that one my own. I can see what it is doing now, but is near voodoo to me. I thought I understood backrefs at a very basic level, but this proves I have a long way to go. Thank you.