[ansible-project] Re: Extracting a substring with regex_replace fails

2018-02-16 Thread jean-christophe manciot
You made it, bravo!
However,  this solution is not better than the regex search, because the 
whole point of using the xml module was to make it resilient to change. As 
soon as the URI {http://docs.oasis-open.org/ns/xri/xrd-1.0 
}
 
changes, the call to access both variables will fail. 

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6aafa5d2-a54d-41af-96fa-80b80245bc38%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Re: Extracting a substring with regex_replace fails

2018-02-15 Thread 'Felix Fontein' via Ansible Project
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
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.


[ansible-project] Re: Extracting a substring with regex_replace fails

2018-02-15 Thread jean-christophe manciot
@Kai Stian Olstad
Thanks for your answer: yes, it works.

@Felix Fontain
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

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4dddbcb7-5adb-4cbc-8455-2f5c43418b4b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Extracting a substring with regex_replace fails

2018-02-14 Thread jean-christophe manciot

>
>
>
I  have the same difficulty with:
ansible 2.4.3.0 (detached HEAD 8a7f9beab7) last updated 2018/02/14 16:11:16 
(GMT +200)
 

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/fb5f8d45-ea18-42ab-bd6e-ddc19fbec3b3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.