-
Notifications
You must be signed in to change notification settings - Fork 64
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
Reading an attribute value into an ansible variable is not documented #59
Comments
That should definitely be included. |
is it possible to read the value? what is the syntax? |
Looks like it's "xmlstring" from the source |
The xmlstring is inaccurate:
|
So it has been months since this issue was opened and identified as a bug. What is the status of an example on how to load an attribute or element value into an ansible variable. Examples with and with out namespaces are relevant as many users simply need to access the values and do not need to manipulate the XML. I have spent many many days trying to do this and the closest I have gotten returns the following TASK [test : Print patch] ****************************************************** or TASK [test : Print hist] ******************************************************* I have been unable to get the values "patch_JR55554_ISD_all_11500-1" into variables so that I can compare a patch manifest to a list of applied patches in order to determine if a patch has been applied. This is to prevent what is apparent in the attached Version.xml file where a patch has been repeatedly applied. I like many, don't want to manipulate the xml files, I simply need the values in the attributes. Here are my files: Here is my main.yml
Here is my inner.yml
I have no idea why this has to be so difficult but any prompt resolution to this bug or direction on how to get the values into variables for testing would be appreciated. |
Ok, I finally figured it out. I had to use json_query in order to search the nested data that is returned as json data. This is not well documented and I only figured it out be looking at the code. However, the method I took is a kludge at best and a real set of methods and examples that a user can implement to read an attribute or element into a variable is needed. I should be able to use an xpath like "/PatchManifest/@patchName" and get back only "patch_JR55554_ISD_all_11500-1" from my PatchManifest.xml and an xpath like "//iis:HistoricalEvent/@installerId" with a defined namespace and get back "patch_JR55554_ISD_all_11500-1" from my Version.xml file as well as a loop construct that would allow me to iterate of the items in all "//iis:HistoricalEvent" elements under "//iis:History" The files I used are above but I modified my role/tasks as follows
# important to cast numerics to integer otherwise it is a string and no matches will be found or looping will occur
output: TASK [test : print get_element_text] ******************************************* TASK [test : Get patch name attributes] **************************************** TASK [test : print get_element_attribute] ************************************** TASK [test : pring patchName attributes] *************************************** TASK [test : Count applied patches] ******************************************** TASK [test : Print count of applied patches] *********************************** TASK [test : Get applied patches] ********************************************** TASK [test : Print applied patch for first patch] ****************************** TASK [test : Print attribute from nested JSON data] **************************** TASK [test : Print nested JSON data for the first item in a list of namespaced data] *** TASK [test : Print the desired attribute value from each item in a list of namespaced data] *** |
This issue was moved to ansible/ansible#27951 |
Please close this issue. |
Missing bits and pieces, clarifications and examples. This fixes ansible#27951 This fixes ansible#28119 This fixes cmprescott/ansible-xml#59
Missing bits and pieces, clarifications and examples. This fixes #27951 This fixes #28119 This fixes cmprescott/ansible-xml#59
Missing bits and pieces, clarifications and examples. This fixes ansible#27951 This fixes ansible#28119 This fixes cmprescott/ansible-xml#59
The documentation should include a code sample that loads an attribute value into an ansible variable. I may make sense to provide a simple example for reading the
charset
attribute from insite HTML page.html>headers>meta>charset
. Maybe even specifying what happens if it is missing.The text was updated successfully, but these errors were encountered: