Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Xpath /settings/setting[@id="setting.key"]/@value does not reference a node!" when trying to set an attribute value #15

Closed
Lx opened this issue May 2, 2015 · 7 comments

Comments

@Lx
Copy link

Lx commented May 2, 2015

Give this Ansible task:

- name: ensure required setting
  xml: >
    file=.../settings.xml
    xpath='/settings/setting[@id="setting.key"]/@value'
    value=true

and this remote XML file:

<settings>
    <setting id="setting.key" value="false" />
</settings>

I get this error:

TASK: [playbook | ensure required setting] ******************* 
failed: [XXX] => {"failed": true}
msg: Xpath /settings/setting[@id="setting.key"]/@value does not reference a node!

The documentation (through showing how to remove an attribute) suggests that I should be able to alter an attribute's value. Am I doing something wrong?

@codyro
Copy link

codyro commented Jun 5, 2015

I'm also having the issue described above when trying to set a value for an attribute. After peaking at the code it doesn't seem to account for changing an attribute?

@add1ct3dd
Copy link

Any solutions to this?

@Hubbitus
Copy link

I also come here with intention fill bug...
But it seems we misunderstood (and doc has not useful description and examples). I have looked at code and it intended to work in other way (on my mind used in question much more sane and I also understand and try it on that manner). So in current implementation it works for me if I pass separate attribute value like:

- name: ensure required setting
  xml:
    file: .../settings.xml
    xpath: '/settings/setting[@id="setting.key"]'
    attribute: value
    value: "some new value"

Please note few thing there:

  • xpath is always element
  • attribute has name without @

@cmprescott
Copy link
Owner

I'll use this issue to track updating the documentation's clarity concerning this.

@dagwieers
Copy link
Collaborator

The xml module is upstream now (and ships with Ansible v2.4).

Please close this issue, and retest against the new upstream xml module. If needed, open a new issue at: https://github.com/ansible/ansible/issues

@dagwieers
Copy link
Collaborator

dagwieers commented Aug 25, 2017

@Hubbitus Are you willing to create a PR for this at: https://github.com/ansible/ansible ?

I just verified the same thing. This does not work:

[dag@moria ansible.git]$ ansible -m xml --diff -a 'xpath=/settings/setting[@id="setting.key"]/@value value=true file=/tmp/test.xml ' -C localhost
localhost | FAILED! => {
    "changed": false, 
    "failed": true, 
    "msg": "Xpath /settings/setting[@id=\"setting.key\"]/@value does not reference a node! tree is <settings>\n    <setting id=\"setting.key\" value=\"\"/>\n</settings>\n"
}

[dag@moria ansible.git]$ ansible -m xml --diff -a 'xpath=/settings/setting[@id="setting.key"]/@value attribute=value value=true file=/tmp/test.xml' -C localhost
localhost | FAILED! => {
    "changed": false, 
    "failed": true, 
    "msg": "Xpath /settings/setting[@id=\"setting.key\"]/@value does not reference a node! tree is <settings>\n    <setting id=\"setting.key\" value=\"\"/>\n</settings>\n"
}

But this works fine:

[dag@moria ansible.git]$ ansible -m xml --diff -a 'xpath=/settings/setting[@id="setting.key"] attribute=value value=true file=/tmp/test.xml' -C localhost
--- before
+++ after
@@ -1,4 +1,4 @@
 <?xml version='1.0' encoding='UTF-8'?>
 <settings>
-    <setting id="setting.key" value="false"/>
+    <setting id="setting.key" value="true"/>
 </settings>

localhost | SUCCESS => {
    "actions": {
        "namespaces": {}, 
        "state": "present", 
        "xpath": "/settings/setting[@id=\"setting.key\"]"
    }, 
    "changed": true, 
    "failed": false, 
}

@dagwieers
Copy link
Collaborator

I have updated the documentation. Setting attribute values using xpath only would be very useful, but is a feature request. We are welcoming anyone who can do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants