Hi,
You are missing the newlines the string contains. regex_replace uses
re.sub() in Python and does not offer a way to set the MULTILINE flag.
If you remove '^' and '$' from your regexps, you can see what happens:
only the matching part between two '\n's is replaced.
Instead of regexp_replace() you should use the regex_search() filter;
that works as expected:
- set_fact: api_release="{{ host_meta | regex_search('rel=(.*)') }}"
when: host_meta is defined
- set_fact: api_root="{{ host_meta | regex_search('href=(.*)/>') }}"
when: host_meta is defined
Yields:
"api_release": "rel='restconf' href='/restconf'/>"
"api_root": "href='/restconf'/>"
(That's not exactly equal to what you expected, but that is what your
original regexes would have returned if the multiline flag would have
been set. The problem is that regexes are notoriously bad for matching
XML and or HTML.)
Cheers,
Felix
>
--
Felix Fontein --
fe...@fontein.de --
http://felix.fontein.de/