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

Problems with attributes #27

Closed
ErebusBat opened this issue Sep 3, 2015 · 3 comments
Closed

Problems with attributes #27

ErebusBat opened this issue Sep 3, 2015 · 3 comments
Labels

Comments

@ErebusBat
Copy link

I am attempting to write a playbook for Syncthing and use ansible-xml for managing the config file.

However I seem to be having issues when it comes to attributes.
I have the following task, which I would expect to set the enabled attribute to yourmom but it does nothing.

- name: Config | Enable GUI
  xml: 
    file: "{{st_config}}"
    xpath: /configuration/gui/@enabled
    value: yourmom

I know that st_config is correct, because this task works just fine:

  xml: 
    file: "{{st_config}}"
    xpath: /configuration/gui/address
    value: 0.0.0.0:8080

I am also having trouble extracting attribute values via a register command, that will crash the entire run (rather than failing silently). I was going to enter a ticket for it, however I now wonder if my syntax is incorrect.

@cmprescott
Copy link
Owner

For the first issue, this sounds similar to #15 . I've been pondering how to clear up the use of this feature by unit tests & the readme.

The register crash is more troubling. What version OS, ansible, lxml, & python are you using?

@ErebusBat
Copy link
Author

It does indeed appear to be similar to #15. I was able to get my desired effect for the given xml:

<?xml version='1.0' encoding='UTF-8'?>
<configuration version="11">
    <gui enabled="false" tls="false">
        <address>0.0.0.0:8080</address>
        <apikey>ABCDEFGHI</apikey>
    </gui>
</configuration>

with the given task:

- name: Config | Enable GUI
  xml: 
    file: "{{st_config}}"
    xpath: /configuration/gui
    attribute: enabled
    value: 'true'

Two things to notice here:

  • The quoted 'true'. If I did not force this as a string then I would get a crash with the error: TypeError: Argument must be bytes or unicode, got 'bool'
  • The attribute name is not referenced in the xpath expression.

I was able to add and change attributes with this pattern.

@ErebusBat
Copy link
Author

Opened a separate issue for the register problem.

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

No branches or pull requests

3 participants