Hi,
> I have no XML skills. I nevertheless took a look at the ansible xml
> module, and it's obscure to me.
> I think you're right though: it'd be better to read XML appropriately
> with that module rather than use some regex filter which can be
> easily defeated if the input changes in the future.
> So I tried something, but of course it does not work
> (api_root_filename is the file containing the xml multi-line string):
>
> - name: Reading RESTconf release
> xml:
> attribute: rel
> content: attribute
> path: "{{ api_root_filename }}"
> xpath: /XRD/Link
> register: return_restconf_release
>
> - name: Showing attribute value
> debug:
> var: return_restconf_release.matches[0].Link.rel
The problem here is that your XML uses a namespace. I'm not very
familiar with xpaths either, but after a little googling I came up with
this:
- name: Reading RESTconf release
xml:
attribute: rel
content: attribute
path: "{{ api_root_filename }}"
xpath: "/*[name()='XRD']/*[name()='Link']"
register: return_restconf_release
- name: Showing attribute value
debug:
var:
return_restconf_release.matches[0]['{http://docs.oasis-open.org/ns/xri/xrd-1.0}Link']
This gives for me:
ok: [localhost] => {
"failed": false,
"return_restconf_release.matches[0]['{http://docs.oasis-open.org/ns/xri/xrd-1.0}Link']":
{
"href": "/restconf",
"rel": "restconf"
}
}
Cheers,
Felix
--
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/20180215154350.030250d6%40utsjoki.
For more options, visit https://groups.google.com/d/optout.