mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
xml module: Improve documentation (#28667)
Missing bits and pieces, clarifications and examples. This fixes #27951 This fixes #28119 This fixes cmprescott/ansible-xml#59
This commit is contained in:
parent
ebf529f8b8
commit
357119f3b7
1 changed files with 33 additions and 3 deletions
|
@ -51,6 +51,10 @@ options:
|
||||||
default: present
|
default: present
|
||||||
choices: [ absent, present ]
|
choices: [ absent, present ]
|
||||||
aliases: [ ensure ]
|
aliases: [ ensure ]
|
||||||
|
attribute:
|
||||||
|
description:
|
||||||
|
- The attribute to select when using parameter C(value).
|
||||||
|
- This is a string, not prepended with C(@).
|
||||||
value:
|
value:
|
||||||
description:
|
description:
|
||||||
- Desired state of the selected attribute.
|
- Desired state of the selected attribute.
|
||||||
|
@ -59,23 +63,27 @@ options:
|
||||||
- Attributes default to an empty string.
|
- Attributes default to an empty string.
|
||||||
add_children:
|
add_children:
|
||||||
description:
|
description:
|
||||||
- Add additional child-element(s) to a selected element.
|
- Add additional child-element(s) to a selected element for a given C(xpath).
|
||||||
- Child elements must be given in a list and each item may be either a string
|
- Child elements must be given in a list and each item may be either a string
|
||||||
(eg. C(children=ansible) to add an empty C(<ansible/>) child element),
|
(eg. C(children=ansible) to add an empty C(<ansible/>) child element),
|
||||||
or a hash where the key is an element name and the value is the element value.
|
or a hash where the key is an element name and the value is the element value.
|
||||||
|
- This parameter requires C(xpath) to be set.
|
||||||
set_children:
|
set_children:
|
||||||
description:
|
description:
|
||||||
- Set the child-element(s) of a selected element.
|
- Set the child-element(s) of a selected element for a given C(xpath).
|
||||||
- Removes any existing children.
|
- Removes any existing children.
|
||||||
- Child elements must be specified as in C(add_children).
|
- Child elements must be specified as in C(add_children).
|
||||||
|
- This parameter requires C(xpath) to be set.
|
||||||
count:
|
count:
|
||||||
description:
|
description:
|
||||||
- Search for a given C(xpath) and provide the count of any matches.
|
- Search for a given C(xpath) and provide the count of any matches.
|
||||||
|
- This parameter requires C(xpath) to be set.
|
||||||
type: bool
|
type: bool
|
||||||
default: 'no'
|
default: 'no'
|
||||||
print_match:
|
print_match:
|
||||||
description:
|
description:
|
||||||
- Search for a given C(xpath) and print out any matches.
|
- Search for a given C(xpath) and print out any matches.
|
||||||
|
- This parameter requires C(xpath) to be set.
|
||||||
type: bool
|
type: bool
|
||||||
default: 'no'
|
default: 'no'
|
||||||
pretty_print:
|
pretty_print:
|
||||||
|
@ -86,6 +94,7 @@ options:
|
||||||
content:
|
content:
|
||||||
description:
|
description:
|
||||||
- Search for a given C(xpath) and get content.
|
- Search for a given C(xpath) and get content.
|
||||||
|
- This parameter requires C(xpath) to be set.
|
||||||
choices: [ attribute, text ]
|
choices: [ attribute, text ]
|
||||||
input_type:
|
input_type:
|
||||||
description:
|
description:
|
||||||
|
@ -106,6 +115,7 @@ notes:
|
||||||
- This module does not handle complicated xpath expressions, so limit xpath selectors to simple expressions.
|
- This module does not handle complicated xpath expressions, so limit xpath selectors to simple expressions.
|
||||||
- Beware that in case your XML elements are namespaced, you need to use the C(namespaces) parameter.
|
- Beware that in case your XML elements are namespaced, you need to use the C(namespaces) parameter.
|
||||||
- Namespaces prefix should be used for all children of an element where namespace is defined, unless another namespace is defined for them.
|
- Namespaces prefix should be used for all children of an element where namespace is defined, unless another namespace is defined for them.
|
||||||
|
- More information about this module is available from the community wiki at U(https://github.com/ansible/community/wiki/Module:-xml)
|
||||||
author:
|
author:
|
||||||
- Tim Bielawa (@tbielawa)
|
- Tim Bielawa (@tbielawa)
|
||||||
- Magnus Hedemark (@magnus919)
|
- Magnus Hedemark (@magnus919)
|
||||||
|
@ -161,6 +171,26 @@ EXAMPLES = r'''
|
||||||
path: /foo/bar.xml
|
path: /foo/bar.xml
|
||||||
xpath: /business/website/validxhtml/@validatedon
|
xpath: /business/website/validxhtml/@validatedon
|
||||||
|
|
||||||
|
- name: Add or modify an attribute, add element if needed
|
||||||
|
xml:
|
||||||
|
path: /foo/bar.xml
|
||||||
|
xpath: /business/website/validxhtml
|
||||||
|
attribute: validatedon
|
||||||
|
value: 1976-08-05
|
||||||
|
|
||||||
|
# How to read an attrribute value and access it in Ansible
|
||||||
|
- name: Read attribute value
|
||||||
|
xml:
|
||||||
|
path: /foo/bar.xml
|
||||||
|
xpath: /business/website/validxhtml
|
||||||
|
content: attribute
|
||||||
|
attribute: validatedon
|
||||||
|
register: xmlresp
|
||||||
|
|
||||||
|
- name: Show attribute value
|
||||||
|
debug:
|
||||||
|
var: xmlresp.matches[0].validxhtml.validatedon
|
||||||
|
|
||||||
- name: Remove all children from the website element (option 1)
|
- name: Remove all children from the website element (option 1)
|
||||||
xml:
|
xml:
|
||||||
path: /foo/bar.xml
|
path: /foo/bar.xml
|
||||||
|
@ -174,7 +204,7 @@ EXAMPLES = r'''
|
||||||
children: []
|
children: []
|
||||||
|
|
||||||
# In case of namespaces, like in below XML, they have to be explicitely stated
|
# In case of namespaces, like in below XML, they have to be explicitely stated
|
||||||
# Note: there's the prefix "x" in front of the "bar", too
|
# NOTE: there's the prefix "x" in front of the "bar", too
|
||||||
#<?xml version='1.0' encoding='UTF-8'?>
|
#<?xml version='1.0' encoding='UTF-8'?>
|
||||||
#<foo xmlns="http://x.test" xmlns:attr="http://z.test">
|
#<foo xmlns="http://x.test" xmlns:attr="http://z.test">
|
||||||
# <bar>
|
# <bar>
|
||||||
|
|
Loading…
Reference in a new issue