x*: adjust docs (#9308)

* adjust docs

* Update plugins/modules/xml.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* fix capitalisation

* add markup to references of the xe command (xenserver)

* add missing markup

* Update plugins/modules/xml.py

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
pull/9344/head
Alexei Znamensky 2024-12-24 06:58:02 +13:00 committed by GitHub
parent 005c8f50db
commit f9bfe4e4a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 827 additions and 863 deletions

View File

@ -8,14 +8,12 @@
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
DOCUMENTATION = ''' DOCUMENTATION = r"""
---
module: xattr module: xattr
short_description: Manage user defined extended attributes short_description: Manage user defined extended attributes
description: description:
- Manages filesystem user defined extended attributes. - Manages filesystem user defined extended attributes.
- Requires that extended attributes are enabled on the target filesystem - Requires that extended attributes are enabled on the target filesystem and that the C(setfattr)/C(getfattr) utilities are present.
and that the setfattr/getfattr utilities are present.
extends_documentation_fragment: extends_documentation_fragment:
- community.general.attributes - community.general.attributes
attributes: attributes:
@ -29,7 +27,7 @@ options:
- The full path of the file/object to get the facts of. - The full path of the file/object to get the facts of.
type: path type: path
required: true required: true
aliases: [ name ] aliases: [name]
namespace: namespace:
description: description:
- Namespace of the named name/key. - Namespace of the named name/key.
@ -45,27 +43,26 @@ options:
type: str type: str
state: state:
description: description:
- defines which state you want to do. - Defines which state you want to do.
V(read) retrieves the current value for a O(key) (default) - V(read) retrieves the current value for a O(key).
V(present) sets O(path) to O(value), default if value is set - V(present) sets O(path) to O(value), default if value is set.
V(all) dumps all data - V(all) dumps all data.
V(keys) retrieves all keys - V(keys) retrieves all keys.
V(absent) deletes the key - V(absent) deletes the key.
type: str type: str
choices: [ absent, all, keys, present, read ] choices: [absent, all, keys, present, read]
default: read default: read
follow: follow:
description: description:
- If V(true), dereferences symlinks and sets/gets attributes on symlink target, - If V(true), dereferences symlinks and sets/gets attributes on symlink target, otherwise acts on symlink itself.
otherwise acts on symlink itself.
type: bool type: bool
default: true default: true
author: author:
- Brian Coca (@bcoca) - Brian Coca (@bcoca)
''' """
EXAMPLES = ''' EXAMPLES = r"""
- name: Obtain the extended attributes of /etc/foo.conf - name: Obtain the extended attributes of /etc/foo.conf
community.general.xattr: community.general.xattr:
path: /etc/foo.conf path: /etc/foo.conf
@ -94,7 +91,7 @@ EXAMPLES = '''
namespace: trusted namespace: trusted
key: glusterfs.volume-id key: glusterfs.volume-id
state: absent state: absent
''' """
import os import os

View File

@ -10,86 +10,78 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
DOCUMENTATION = ''' DOCUMENTATION = r"""
---
module: xbps module: xbps
short_description: Manage packages with XBPS short_description: Manage packages with XBPS
description: description:
- Manage packages with the XBPS package manager. - Manage packages with the XBPS package manager.
author: author:
- "Dino Occhialini (@dinoocch)" - "Dino Occhialini (@dinoocch)"
- "Michael Aldridge (@the-maldridge)" - "Michael Aldridge (@the-maldridge)"
extends_documentation_fragment: extends_documentation_fragment:
- community.general.attributes - community.general.attributes
attributes: attributes:
check_mode: check_mode:
support: full support: full
diff_mode: diff_mode:
support: none support: none
options: options:
name: name:
description: description:
- Name of the package to install, upgrade, or remove. - Name of the package to install, upgrade, or remove.
aliases: [pkg,package] aliases: [pkg, package]
type: list type: list
elements: str elements: str
state: state:
description: description:
- Desired state of the package. - Desired state of the package.
default: "present" default: "present"
choices: ["present", "absent", "latest", "installed", "removed"] choices: ["present", "absent", "latest", "installed", "removed"]
type: str type: str
recurse: recurse:
description: description:
- When removing a package, also remove its dependencies, provided - When removing a package, also remove its dependencies, provided that they are not required by other packages and were not explicitly installed
that they are not required by other packages and were not by a user.
explicitly installed by a user. type: bool
type: bool default: false
default: false update_cache:
update_cache: description:
description: - Whether or not to refresh the master package lists. This can be run as part of a package installation or as a separate step.
- Whether or not to refresh the master package lists. This can be type: bool
run as part of a package installation or as a separate step. default: true
type: bool upgrade:
default: true description:
upgrade: - Whether or not to upgrade whole system.
description: type: bool
- Whether or not to upgrade whole system default: false
type: bool upgrade_xbps:
default: false description:
upgrade_xbps: - Whether or not to upgrade the xbps package when necessary. Before installing new packages, xbps requires the user to update the xbps package
description: itself. Thus when this option is set to V(false), upgrades and installations will fail when xbps is not up to date.
- Whether or not to upgrade the xbps package when necessary. type: bool
Before installing new packages, default: true
xbps requires the user to update the xbps package itself. version_added: '0.2.0'
Thus when this option is set to V(false), root:
upgrades and installations will fail when xbps is not up to date. description:
type: bool - The full path for the target root directory.
default: true type: path
version_added: '0.2.0' version_added: '10.2.0'
root: repositories:
description: description:
- The full path for the target root directory. - Repository URL(s) to prepend to the repository list for the package installation. The URL can be a URL to a repository for remote repositories
type: path or a path for local repositories.
version_added: '10.2.0' type: list
repositories: elements: str
description: version_added: '10.2.0'
- Repository URL(s) to prepend to the repository list for the accept_pubkey:
package installation. description:
The URL can be a URL to a repository for - Whether or not repository signing keys should be automatically accepted.
remote repositories or a path for local repositories. type: bool
type: list default: false
elements: str version_added: '10.2.0'
version_added: '10.2.0' """
accept_pubkey:
description:
- Whether or not repository signing keys should be automatically accepted.
type: bool
default: false
version_added: '10.2.0'
'''
EXAMPLES = ''' EXAMPLES = r"""
- name: Install package foo (automatically updating the xbps package if needed) - name: Install package foo (automatically updating the xbps package if needed)
community.general.xbps: community.general.xbps:
name: foo name: foo
@ -151,20 +143,20 @@ EXAMPLES = '''
state: present state: present
repositories: https://repo-default.voidlinux.org/current repositories: https://repo-default.voidlinux.org/current
root: /mnt root: /mnt
''' """
RETURN = ''' RETURN = r"""
msg: msg:
description: Message about results description: Message about results.
returned: success returned: success
type: str type: str
sample: "System Upgraded" sample: "System Upgraded"
packages: packages:
description: Packages that are affected/would be affected description: Packages that are affected/would be affected.
type: list type: list
sample: ["ansible"] sample: ["ansible"]
returned: success returned: success
''' """
import os import os

View File

@ -8,14 +8,13 @@
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
DOCUMENTATION = ''' DOCUMENTATION = r"""
---
module: xcc_redfish_command module: xcc_redfish_command
short_description: Manages Lenovo Out-Of-Band controllers using Redfish APIs short_description: Manages Lenovo Out-Of-Band controllers using Redfish APIs
version_added: 2.4.0 version_added: 2.4.0
description: description:
- Builds Redfish URIs locally and sends them to remote OOB controllers to - Builds Redfish URIs locally and sends them to remote OOB controllers to perform an action or get information back or update a configuration
perform an action or get information back or update a configuration attribute. attribute.
- Manages virtual media. - Manages virtual media.
- Supports getting information back via GET method. - Supports getting information back via GET method.
- Supports updating a configuration attribute via PATCH method. - Supports updating a configuration attribute via PATCH method.
@ -54,7 +53,7 @@ options:
type: str type: str
auth_token: auth_token:
description: description:
- Security token for authentication with OOB controller - Security token for authentication with OOB controller.
type: str type: str
timeout: timeout:
description: description:
@ -120,181 +119,181 @@ options:
type: dict type: dict
author: "Yuyan Pan (@panyy3)" author: "Yuyan Pan (@panyy3)"
''' """
EXAMPLES = ''' EXAMPLES = r"""
- name: Insert Virtual Media - name: Insert Virtual Media
community.general.xcc_redfish_command: community.general.xcc_redfish_command:
category: Manager category: Manager
command: VirtualMediaInsert command: VirtualMediaInsert
baseuri: "{{ baseuri }}" baseuri: "{{ baseuri }}"
username: "{{ username }}" username: "{{ username }}"
password: "{{ password }}" password: "{{ password }}"
virtual_media: virtual_media:
image_url: "http://example.com/images/SomeLinux-current.iso" image_url: "http://example.com/images/SomeLinux-current.iso"
media_types: media_types:
- CD - CD
- DVD - DVD
resource_id: "1" resource_id: "1"
- name: Eject Virtual Media - name: Eject Virtual Media
community.general.xcc_redfish_command: community.general.xcc_redfish_command:
category: Manager category: Manager
command: VirtualMediaEject command: VirtualMediaEject
baseuri: "{{ baseuri }}" baseuri: "{{ baseuri }}"
username: "{{ username }}" username: "{{ username }}"
password: "{{ password }}" password: "{{ password }}"
virtual_media: virtual_media:
image_url: "http://example.com/images/SomeLinux-current.iso" image_url: "http://example.com/images/SomeLinux-current.iso"
resource_id: "1" resource_id: "1"
- name: Eject all Virtual Media - name: Eject all Virtual Media
community.general.xcc_redfish_command: community.general.xcc_redfish_command:
category: Manager category: Manager
command: VirtualMediaEject command: VirtualMediaEject
baseuri: "{{ baseuri }}" baseuri: "{{ baseuri }}"
username: "{{ username }}" username: "{{ username }}"
password: "{{ password }}" password: "{{ password }}"
resource_id: "1" resource_id: "1"
- name: Get ComputeSystem Oem property SystemStatus via GetResource command - name: Get ComputeSystem Oem property SystemStatus via GetResource command
community.general.xcc_redfish_command: community.general.xcc_redfish_command:
category: Raw category: Raw
command: GetResource command: GetResource
baseuri: "{{ baseuri }}" baseuri: "{{ baseuri }}"
username: "{{ username }}" username: "{{ username }}"
password: "{{ password }}" password: "{{ password }}"
resource_uri: "/redfish/v1/Systems/1" resource_uri: "/redfish/v1/Systems/1"
register: result register: result
- ansible.builtin.debug: - ansible.builtin.debug:
msg: "{{ result.redfish_facts.data.Oem.Lenovo.SystemStatus }}" msg: "{{ result.redfish_facts.data.Oem.Lenovo.SystemStatus }}"
- name: Get Oem DNS setting via GetResource command - name: Get Oem DNS setting via GetResource command
community.general.xcc_redfish_command: community.general.xcc_redfish_command:
category: Raw category: Raw
command: GetResource command: GetResource
baseuri: "{{ baseuri }}" baseuri: "{{ baseuri }}"
username: "{{ username }}" username: "{{ username }}"
password: "{{ password }}" password: "{{ password }}"
resource_uri: "/redfish/v1/Managers/1/NetworkProtocol/Oem/Lenovo/DNS" resource_uri: "/redfish/v1/Managers/1/NetworkProtocol/Oem/Lenovo/DNS"
register: result register: result
- name: Print fetched information - name: Print fetched information
ansible.builtin.debug: ansible.builtin.debug:
msg: "{{ result.redfish_facts.data }}" msg: "{{ result.redfish_facts.data }}"
- name: Get Lenovo FoD key collection resource via GetCollectionResource command - name: Get Lenovo FoD key collection resource via GetCollectionResource command
community.general.xcc_redfish_command: community.general.xcc_redfish_command:
category: Raw category: Raw
command: GetCollectionResource command: GetCollectionResource
baseuri: "{{ baseuri }}" baseuri: "{{ baseuri }}"
username: "{{ username }}" username: "{{ username }}"
password: "{{ password }}" password: "{{ password }}"
resource_uri: "/redfish/v1/Managers/1/Oem/Lenovo/FoD/Keys" resource_uri: "/redfish/v1/Managers/1/Oem/Lenovo/FoD/Keys"
register: result register: result
- name: Print fetched information - name: Print fetched information
ansible.builtin.debug: ansible.builtin.debug:
msg: "{{ result.redfish_facts.data_list }}" msg: "{{ result.redfish_facts.data_list }}"
- name: Update ComputeSystem property AssetTag via PatchResource command - name: Update ComputeSystem property AssetTag via PatchResource command
community.general.xcc_redfish_command: community.general.xcc_redfish_command:
category: Raw category: Raw
command: PatchResource command: PatchResource
baseuri: "{{ baseuri }}" baseuri: "{{ baseuri }}"
username: "{{ username }}" username: "{{ username }}"
password: "{{ password }}" password: "{{ password }}"
resource_uri: "/redfish/v1/Systems/1" resource_uri: "/redfish/v1/Systems/1"
request_body: request_body:
AssetTag: "new_asset_tag" AssetTag: "new_asset_tag"
- name: Perform BootToBIOSSetup action via PostResource command - name: Perform BootToBIOSSetup action via PostResource command
community.general.xcc_redfish_command: community.general.xcc_redfish_command:
category: Raw category: Raw
command: PostResource command: PostResource
baseuri: "{{ baseuri }}" baseuri: "{{ baseuri }}"
username: "{{ username }}" username: "{{ username }}"
password: "{{ password }}" password: "{{ password }}"
resource_uri: "/redfish/v1/Systems/1/Actions/Oem/LenovoComputerSystem.BootToBIOSSetup" resource_uri: "/redfish/v1/Systems/1/Actions/Oem/LenovoComputerSystem.BootToBIOSSetup"
request_body: {} request_body: {}
- name: Perform SecureBoot.ResetKeys action via PostResource command - name: Perform SecureBoot.ResetKeys action via PostResource command
community.general.xcc_redfish_command: community.general.xcc_redfish_command:
category: Raw category: Raw
command: PostResource command: PostResource
baseuri: "{{ baseuri }}" baseuri: "{{ baseuri }}"
username: "{{ username }}" username: "{{ username }}"
password: "{{ password }}" password: "{{ password }}"
resource_uri: "/redfish/v1/Systems/1/SecureBoot/Actions/SecureBoot.ResetKeys" resource_uri: "/redfish/v1/Systems/1/SecureBoot/Actions/SecureBoot.ResetKeys"
request_body: request_body:
ResetKeysType: DeleteAllKeys ResetKeysType: DeleteAllKeys
- name: Create session - name: Create session
community.general.redfish_command: community.general.redfish_command:
category: Sessions category: Sessions
command: CreateSession command: CreateSession
baseuri: "{{ baseuri }}" baseuri: "{{ baseuri }}"
username: "{{ username }}" username: "{{ username }}"
password: "{{ password }}" password: "{{ password }}"
register: result register: result
- name: Update Manager DateTimeLocalOffset property using security token for auth - name: Update Manager DateTimeLocalOffset property using security token for auth
community.general.xcc_redfish_command: community.general.xcc_redfish_command:
category: Raw category: Raw
command: PatchResource command: PatchResource
baseuri: "{{ baseuri }}" baseuri: "{{ baseuri }}"
auth_token: "{{ result.session.token }}" auth_token: "{{ result.session.token }}"
resource_uri: "/redfish/v1/Managers/1" resource_uri: "/redfish/v1/Managers/1"
request_body: request_body:
DateTimeLocalOffset: "+08:00" DateTimeLocalOffset: "+08:00"
- name: Delete session using security token created by CreateSesssion above - name: Delete session using security token created by CreateSesssion above
community.general.redfish_command: community.general.redfish_command:
category: Sessions category: Sessions
command: DeleteSession command: DeleteSession
baseuri: "{{ baseuri }}" baseuri: "{{ baseuri }}"
auth_token: "{{ result.session.token }}" auth_token: "{{ result.session.token }}"
session_uri: "{{ result.session.uri }}" session_uri: "{{ result.session.uri }}"
''' """
RETURN = ''' RETURN = r"""
msg: msg:
description: A message related to the performed action(s). description: A message related to the performed action(s).
returned: when failure or action/update success returned: when failure or action/update success
type: str type: str
sample: "Action was successful" sample: "Action was successful"
redfish_facts: redfish_facts:
description: Resource content. description: Resource content.
returned: when command == GetResource or command == GetCollectionResource returned: when command == GetResource or command == GetCollectionResource
type: dict type: dict
sample: '{ sample: '{
"redfish_facts": { "redfish_facts": {
"data": { "data": {
"@odata.etag": "\"3179bf00d69f25a8b3c\"", "@odata.etag": "\"3179bf00d69f25a8b3c\"",
"@odata.id": "/redfish/v1/Managers/1/NetworkProtocol/Oem/Lenovo/DNS", "@odata.id": "/redfish/v1/Managers/1/NetworkProtocol/Oem/Lenovo/DNS",
"@odata.type": "#LenovoDNS.v1_0_0.LenovoDNS", "@odata.type": "#LenovoDNS.v1_0_0.LenovoDNS",
"DDNS": [ "DDNS": [
{ {
"DDNSEnable": true, "DDNSEnable": true,
"DomainName": "", "DomainName": "",
"DomainNameSource": "DHCP" "DomainNameSource": "DHCP"
} }
], ],
"DNSEnable": true, "DNSEnable": true,
"Description": "This resource is used to represent a DNS resource for a Redfish implementation.", "Description": "This resource is used to represent a DNS resource for a Redfish implementation.",
"IPv4Address1": "10.103.62.178", "IPv4Address1": "10.103.62.178",
"IPv4Address2": "0.0.0.0", "IPv4Address2": "0.0.0.0",
"IPv4Address3": "0.0.0.0", "IPv4Address3": "0.0.0.0",
"IPv6Address1": "::", "IPv6Address1": "::",
"IPv6Address2": "::", "IPv6Address2": "::",
"IPv6Address3": "::", "IPv6Address3": "::",
"Id": "LenovoDNS", "Id": "LenovoDNS",
"PreferredAddresstype": "IPv4" "PreferredAddresstype": "IPv4"
}, },
"ret": true "ret": true
} }
}' }'
''' """
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native from ansible.module_utils.common.text.converters import to_native

View File

@ -9,12 +9,11 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
DOCUMENTATION = ''' DOCUMENTATION = r"""
---
module: xenserver_facts module: xenserver_facts
short_description: Get facts reported on xenserver short_description: Get facts reported on xenserver
description: description:
- Reads data out of XenAPI, can be used instead of multiple xe commands. - Reads data out of XenAPI, can be used instead of multiple C(xe) commands.
author: author:
- Andy Hill (@andyhky) - Andy Hill (@andyhky)
- Tim Rupp (@caphrim007) - Tim Rupp (@caphrim007)
@ -28,9 +27,9 @@ attributes:
version_added: 3.3.0 version_added: 3.3.0
# This was backported to 2.5.4 and 1.3.11 as well, since this was a bugfix # This was backported to 2.5.4 and 1.3.11 as well, since this was a bugfix
options: {} options: {}
''' """
EXAMPLES = ''' EXAMPLES = r"""
- name: Gather facts from xenserver - name: Gather facts from xenserver
community.general.xenserver_facts: community.general.xenserver_facts:
@ -48,7 +47,7 @@ EXAMPLES = '''
# "item": "Control domain on host: 10.0.13.22", # "item": "Control domain on host: 10.0.13.22",
# "msg": "Control domain on host: 10.0.13.22" # "msg": "Control domain on host: 10.0.13.22"
# } # }
''' """
HAVE_XENAPI = False HAVE_XENAPI = False

View File

@ -8,43 +8,41 @@
from __future__ import (absolute_import, division, print_function) from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
DOCUMENTATION = r''' DOCUMENTATION = r"""
---
module: xenserver_guest module: xenserver_guest
short_description: Manages virtual machines running on Citrix Hypervisor/XenServer host or pool short_description: Manages virtual machines running on Citrix Hypervisor/XenServer host or pool
description: > description: >-
This module can be used to create new virtual machines from templates or other virtual machines, This module can be used to create new virtual machines from templates or other virtual machines, modify various virtual machine components like
modify various virtual machine components like network and disk, rename a virtual machine and network and disk, rename a virtual machine and remove a virtual machine with associated components.
remove a virtual machine with associated components.
author: author:
- Bojan Vitnik (@bvitnik) <bvitnik@mainstream.rs> - Bojan Vitnik (@bvitnik) <bvitnik@mainstream.rs>
notes: notes:
- Minimal supported version of XenServer is 5.6. - Minimal supported version of XenServer is 5.6.
- Module was tested with XenServer 6.5, 7.1, 7.2, 7.6, Citrix Hypervisor 8.0, XCP-ng 7.6 and 8.0. - Module was tested with XenServer 6.5, 7.1, 7.2, 7.6, Citrix Hypervisor 8.0, XCP-ng 7.6 and 8.0.
- 'To acquire XenAPI Python library, just run C(pip install XenAPI) on your Ansible Control Node. The library can also be found inside - 'To acquire XenAPI Python library, just run C(pip install XenAPI) on your Ansible Control Node. The library can also be found inside Citrix
Citrix Hypervisor/XenServer SDK (downloadable from Citrix website). Copy the XenAPI.py file from the SDK to your Python site-packages on your Hypervisor/XenServer SDK (downloadable from Citrix website). Copy the C(XenAPI.py) file from the SDK to your Python site-packages on your Ansible
Ansible Control Node to use it. Latest version of the library can also be acquired from GitHub: Control Node to use it. Latest version of the library can also be acquired from GitHub:
U(https://raw.githubusercontent.com/xapi-project/xen-api/master/scripts/examples/python/XenAPI/XenAPI.py)' U(https://raw.githubusercontent.com/xapi-project/xen-api/master/scripts/examples/python/XenAPI/XenAPI.py).'
- 'If no scheme is specified in O(hostname), module defaults to C(http://) because C(https://) is problematic in most setups. Make sure you are - 'If no scheme is specified in O(hostname), module defaults to C(http://) because C(https://) is problematic in most setups. Make sure you
accessing XenServer host in trusted environment or use C(https://) scheme explicitly.' are accessing XenServer host in trusted environment or use C(https://) scheme explicitly.'
- 'To use C(https://) scheme for O(hostname) you have to either import host certificate to your OS certificate store or use O(validate_certs=false) - 'To use C(https://) scheme for O(hostname) you have to either import host certificate to your OS certificate store or use O(validate_certs=false)
which requires XenAPI library from XenServer 7.2 SDK or newer and Python 2.7.9 or newer.' which requires XenAPI library from XenServer 7.2 SDK or newer and Python 2.7.9 or newer.'
- 'Network configuration inside a guest OS, by using O(networks[].type), O(networks[].ip), O(networks[].gateway) etc. parameters, is supported on - 'Network configuration inside a guest OS, by using O(networks[].type), O(networks[].ip), O(networks[].gateway) etc. parameters, is supported
XenServer 7.0 or newer for Windows guests by using official XenServer Guest agent support for network configuration. The module will try to on XenServer 7.0 or newer for Windows guests by using official XenServer Guest agent support for network configuration. The module will try
detect if such support is available and utilize it, else it will use a custom method of configuration via xenstore. Since XenServer Guest to detect if such support is available and utilize it, else it will use a custom method of configuration via xenstore. Since XenServer Guest
agent only support None and Static types of network configuration, where None means DHCP configured interface, O(networks[].type) and O(networks[].type6) agent only support None and Static types of network configuration, where None means DHCP configured interface, O(networks[].type) and O(networks[].type6)
values V(none) and V(dhcp) have same effect. More info here: values V(none) and V(dhcp) have same effect. More info here:
U(https://www.citrix.com/community/citrix-developer/citrix-hypervisor-developer/citrix-hypervisor-developing-products/citrix-hypervisor-staticip.html)' U(https://www.citrix.com/community/citrix-developer/citrix-hypervisor-developer/citrix-hypervisor-developing-products/citrix-hypervisor-staticip.html).'
- 'On platforms without official support for network configuration inside a guest OS, network parameters will be written to xenstore - 'On platforms without official support for network configuration inside a guest OS, network parameters will be written to xenstore
C(vm-data/networks/<vif_device>) key. Parameters can be inspected by using C(xenstore ls) and C(xenstore read) tools on \*nix guests or through C(vm-data/networks/<vif_device>) key. Parameters can be inspected by using C(xenstore ls) and C(xenstore read) tools on \*nix guests or through WMI
WMI interface on Windows guests. They can also be found in VM facts C(instance.xenstore_data) key as returned by the module. It is up to the user interface on Windows guests.
to implement a boot time scripts or custom agent that will read the parameters from xenstore and configure network with given parameters. They can also be found in VM facts C(instance.xenstore_data) key as returned by the module. It is up to the user to implement a boot time
Take note that for xenstore data to become available inside a guest, a VM restart is needed hence module will require VM restart if any scripts or custom agent that will read the parameters from xenstore and configure network with given parameters. Take note that for xenstore
parameter is changed. This is a limitation of XenAPI and xenstore. Considering these limitations, network configuration through xenstore is most data to become available inside a guest, a VM restart is needed hence module will require VM restart if any parameter is changed. This is
useful for bootstrapping newly deployed VMs, much less for reconfiguring existing ones. More info here: a limitation of XenAPI and xenstore. Considering these limitations, network configuration through xenstore is most useful for bootstrapping
U(https://support.citrix.com/article/CTX226713)' newly deployed VMs, much less for reconfiguring existing ones. More info here: U(https://support.citrix.com/article/CTX226713).'
requirements: requirements:
- XenAPI - XenAPI
attributes: attributes:
check_mode: check_mode:
support: full support: full
@ -53,248 +51,249 @@ attributes:
options: options:
state: state:
description: description:
- Specify the state VM should be in. - Specify the state VM should be in.
- If O(state) is set to V(present) and VM exists, ensure the VM configuration conforms to given parameters. - If O(state) is set to V(present) and VM exists, ensure the VM configuration conforms to given parameters.
- If O(state) is set to V(present) and VM does not exist, then VM is deployed with given parameters. - If O(state) is set to V(present) and VM does not exist, then VM is deployed with given parameters.
- If O(state) is set to V(absent) and VM exists, then VM is removed with its associated components. - If O(state) is set to V(absent) and VM exists, then VM is removed with its associated components.
- If O(state) is set to V(poweredon) and VM does not exist, then VM is deployed with given parameters and powered on automatically. - If O(state) is set to V(poweredon) and VM does not exist, then VM is deployed with given parameters and powered on automatically.
type: str type: str
default: present default: present
choices: [ present, absent, poweredon ] choices: [present, absent, poweredon]
name: name:
description: description:
- Name of the VM to work with. - Name of the VM to work with.
- VMs running on XenServer do not necessarily have unique names. The module will fail if multiple VMs with same name are found. - VMs running on XenServer do not necessarily have unique names. The module will fail if multiple VMs with same name are found.
- In case of multiple VMs with same name, use O(uuid) to uniquely specify VM to manage. - In case of multiple VMs with same name, use O(uuid) to uniquely specify VM to manage.
- This parameter is case sensitive. - This parameter is case sensitive.
type: str type: str
aliases: [ name_label ] aliases: [name_label]
name_desc: name_desc:
description: description:
- VM description. - VM description.
type: str type: str
uuid: uuid:
description: description:
- UUID of the VM to manage if known. This is XenServer's unique identifier. - UUID of the VM to manage if known. This is XenServer's unique identifier.
- It is required if name is not unique. - It is required if name is not unique.
- Please note that a supplied UUID will be ignored on VM creation, as XenServer creates the UUID internally. - Please note that a supplied UUID will be ignored on VM creation, as XenServer creates the UUID internally.
type: str type: str
template: template:
description: description:
- Name of a template, an existing VM (must be shut down) or a snapshot that should be used to create VM. - Name of a template, an existing VM (must be shut down) or a snapshot that should be used to create VM.
- Templates/VMs/snapshots on XenServer do not necessarily have unique names. The module will fail if multiple templates with same name are found. - Templates/VMs/snapshots on XenServer do not necessarily have unique names. The module will fail if multiple templates with same name are
- In case of multiple templates/VMs/snapshots with same name, use O(template_uuid) to uniquely specify source template. found.
- If VM already exists, this setting will be ignored. - In case of multiple templates/VMs/snapshots with same name, use O(template_uuid) to uniquely specify source template.
- This parameter is case sensitive. - If VM already exists, this setting will be ignored.
- This parameter is case sensitive.
type: str type: str
aliases: [ template_src ] aliases: [template_src]
template_uuid: template_uuid:
description: description:
- UUID of a template, an existing VM or a snapshot that should be used to create VM. - UUID of a template, an existing VM or a snapshot that should be used to create VM.
- It is required if template name is not unique. - It is required if template name is not unique.
type: str type: str
is_template: is_template:
description: description:
- Convert VM to template. - Convert VM to template.
type: bool type: bool
default: false default: false
folder: folder:
description: description:
- Destination folder for VM. - Destination folder for VM.
- This parameter is case sensitive. - This parameter is case sensitive.
- 'Example:' - 'Example:'
- ' folder: /folder1/folder2' - ' folder: /folder1/folder2'
type: str type: str
hardware: hardware:
description: description:
- Manage VM's hardware parameters. VM needs to be shut down to reconfigure these parameters. - Manage VM's hardware parameters. VM needs to be shut down to reconfigure these parameters.
type: dict type: dict
suboptions: suboptions:
num_cpus: num_cpus:
description: description:
- Number of CPUs. - Number of CPUs.
type: int type: int
num_cpu_cores_per_socket: num_cpu_cores_per_socket:
description: description:
- Number of Cores Per Socket. O(hardware.num_cpus) has to be a multiple of O(hardware.num_cpu_cores_per_socket). - Number of Cores Per Socket. O(hardware.num_cpus) has to be a multiple of O(hardware.num_cpu_cores_per_socket).
type: int type: int
memory_mb: memory_mb:
description: description:
- Amount of memory in MB. - Amount of memory in MB.
type: int type: int
disks: disks:
description: description:
- A list of disks to add to VM. - A list of disks to add to VM.
- All parameters are case sensitive. - All parameters are case sensitive.
- Removing or detaching existing disks of VM is not supported. - Removing or detaching existing disks of VM is not supported.
- New disks are required to have either a O(disks[].size) or one of O(ignore:disks[].size_[tb,gb,mb,kb,b]) parameters specified. - New disks are required to have either a O(disks[].size) or one of O(ignore:disks[].size_[tb,gb,mb,kb,b]) parameters specified.
- VM needs to be shut down to reconfigure disk size. - VM needs to be shut down to reconfigure disk size.
type: list type: list
elements: dict elements: dict
aliases: [ disk ] aliases: [disk]
suboptions: suboptions:
size: size:
description: description:
- 'Disk size with unit. Unit must be: V(b), V(kb), V(mb), V(gb), V(tb). VM needs to be shut down to reconfigure this parameter.' - 'Disk size with unit. Unit must be: V(b), V(kb), V(mb), V(gb), V(tb). VM needs to be shut down to reconfigure this parameter.'
- If no unit is specified, size is assumed to be in bytes. - If no unit is specified, size is assumed to be in bytes.
type: str type: str
size_b: size_b:
description: description:
- Disk size in bytes. - Disk size in bytes.
type: str type: str
size_kb: size_kb:
description: description:
- Disk size in kilobytes. - Disk size in kilobytes.
type: str type: str
size_mb: size_mb:
description: description:
- Disk size in megabytes. - Disk size in megabytes.
type: str type: str
size_gb: size_gb:
description: description:
- Disk size in gigabytes. - Disk size in gigabytes.
type: str type: str
size_tb: size_tb:
description: description:
- Disk size in terabytes. - Disk size in terabytes.
type: str type: str
name: name:
description: description:
- Disk name. - Disk name.
type: str type: str
aliases: [ name_label ] aliases: [name_label]
name_desc: name_desc:
description: description:
- Disk description. - Disk description.
type: str type: str
sr: sr:
description: description:
- Storage Repository to create disk on. If not specified, will use default SR. Cannot be used for moving disk to other SR. - Storage Repository to create disk on. If not specified, will use default SR. Cannot be used for moving disk to other SR.
type: str type: str
sr_uuid: sr_uuid:
description: description:
- UUID of a SR to create disk on. Use if SR name is not unique. - UUID of a SR to create disk on. Use if SR name is not unique.
type: str type: str
cdrom: cdrom:
description: description:
- A CD-ROM configuration for the VM. - A CD-ROM configuration for the VM.
- All parameters are case sensitive. - All parameters are case sensitive.
type: dict type: dict
suboptions: suboptions:
type: type:
description: description:
- The type of CD-ROM. With V(none) the CD-ROM device will be present but empty. - The type of CD-ROM. With V(none) the CD-ROM device will be present but empty.
type: str type: str
choices: [ none, iso ] choices: [none, iso]
iso_name: iso_name:
description: description:
- 'The file name of an ISO image from one of the XenServer ISO Libraries (implies O(cdrom.type=iso)).' - 'The file name of an ISO image from one of the XenServer ISO Libraries (implies O(cdrom.type=iso)).'
- Required if O(cdrom.type) is set to V(iso). - Required if O(cdrom.type) is set to V(iso).
type: str type: str
networks: networks:
description: description:
- A list of networks (in the order of the NICs). - A list of networks (in the order of the NICs).
- All parameters are case sensitive. - All parameters are case sensitive.
- Name is required for new NICs. Other parameters are optional in all cases. - Name is required for new NICs. Other parameters are optional in all cases.
type: list type: list
elements: dict elements: dict
aliases: [ network ] aliases: [network]
suboptions: suboptions:
name: name:
description: description:
- Name of a XenServer network to attach the network interface to. - Name of a XenServer network to attach the network interface to.
type: str type: str
aliases: [ name_label ] aliases: [name_label]
mac: mac:
description: description:
- Customize MAC address of the interface. - Customize MAC address of the interface.
type: str type: str
type: type:
description: description:
- Type of IPv4 assignment. Value V(none) means whatever is default for OS. - Type of IPv4 assignment. Value V(none) means whatever is default for OS.
- On some operating systems it could be DHCP configured (e.g. Windows) or unconfigured interface (e.g. Linux). - On some operating systems it could be DHCP configured (e.g. Windows) or unconfigured interface (e.g. Linux).
type: str type: str
choices: [ none, dhcp, static ] choices: [none, dhcp, static]
ip: ip:
description: description:
- 'Static IPv4 address (implies O(networks[].type=static)). Can include prefix in format C(<IPv4 address>/<prefix>) instead of using C(netmask).' - Static IPv4 address (implies O(networks[].type=static)). Can include prefix in format C(<IPv4 address>/<prefix>) instead of using
type: str C(netmask).
netmask: type: str
description: netmask:
description:
- Static IPv4 netmask required for O(networks[].ip) if prefix is not specified. - Static IPv4 netmask required for O(networks[].ip) if prefix is not specified.
type: str type: str
gateway: gateway:
description: description:
- Static IPv4 gateway. - Static IPv4 gateway.
type: str type: str
type6: type6:
description: description:
- Type of IPv6 assignment. Value V(none) means whatever is default for OS. - Type of IPv6 assignment. Value V(none) means whatever is default for OS.
type: str type: str
choices: [ none, dhcp, static ] choices: [none, dhcp, static]
ip6: ip6:
description: description:
- 'Static IPv6 address (implies O(networks[].type6=static)) with prefix in format C(<IPv6 address>/<prefix>).' - 'Static IPv6 address (implies O(networks[].type6=static)) with prefix in format C(<IPv6 address>/<prefix>).'
type: str type: str
gateway6: gateway6:
description: description:
- Static IPv6 gateway. - Static IPv6 gateway.
type: str type: str
home_server: home_server:
description: description:
- Name of a XenServer host that will be a Home Server for the VM. - Name of a XenServer host that will be a Home Server for the VM.
- This parameter is case sensitive. - This parameter is case sensitive.
type: str type: str
custom_params: custom_params:
description: description:
- Define a list of custom VM params to set on VM. - Define a list of custom VM params to set on VM.
- Useful for advanced users familiar with managing VM params through xe CLI. - Useful for advanced users familiar with managing VM params through C(xe) CLI.
- A custom value object takes two fields O(custom_params[].key) and O(custom_params[].value) (see example below). - A custom value object takes two fields O(custom_params[].key) and O(custom_params[].value) (see example below).
type: list type: list
elements: dict elements: dict
suboptions: suboptions:
key: key:
description: description:
- VM param name. - VM param name.
type: str type: str
required: true required: true
value: value:
description: description:
- VM param value. - VM param value.
type: raw type: raw
required: true required: true
wait_for_ip_address: wait_for_ip_address:
description: description:
- Wait until XenServer detects an IP address for the VM. If O(state) is set to V(absent), this parameter is ignored. - Wait until XenServer detects an IP address for the VM. If O(state) is set to V(absent), this parameter is ignored.
- This requires XenServer Tools to be preinstalled on the VM to work properly. - This requires XenServer Tools to be preinstalled on the VM to work properly.
type: bool type: bool
default: false default: false
state_change_timeout: state_change_timeout:
description: description:
- 'By default, module will wait indefinitely for VM to acquire an IP address if O(wait_for_ip_address=true).' - 'By default, module will wait indefinitely for VM to acquire an IP address if O(wait_for_ip_address=true).'
- If this parameter is set to positive value, the module will instead wait specified number of seconds for the state change. - If this parameter is set to positive value, the module will instead wait specified number of seconds for the state change.
- In case of timeout, module will generate an error message. - In case of timeout, module will generate an error message.
type: int type: int
default: 0 default: 0
linked_clone: linked_clone:
description: description:
- Whether to create a Linked Clone from the template, existing VM or snapshot. If no, will create a full copy. - Whether to create a Linked Clone from the template, existing VM or snapshot. If no, will create a full copy.
- This is equivalent to C(Use storage-level fast disk clone) option in XenCenter. - This is equivalent to C(Use storage-level fast disk clone) option in XenCenter.
type: bool type: bool
default: false default: false
force: force:
description: description:
- Ignore warnings and complete the actions. - Ignore warnings and complete the actions.
- This parameter is useful for removing VM in running state or reconfiguring VM params that require VM to be shut down. - This parameter is useful for removing VM in running state or reconfiguring VM params that require VM to be shut down.
type: bool type: bool
default: false default: false
extends_documentation_fragment: extends_documentation_fragment:
- community.general.xenserver.documentation - community.general.xenserver.documentation
- community.general.attributes - community.general.attributes
"""
''' EXAMPLES = r"""
EXAMPLES = r'''
- name: Create a VM from a template - name: Create a VM from a template
community.general.xenserver_guest: community.general.xenserver_guest:
hostname: "{{ xenserver_hostname }}" hostname: "{{ xenserver_hostname }}"
@ -305,8 +304,8 @@ EXAMPLES = r'''
state: poweredon state: poweredon
template: CentOS 7 template: CentOS 7
disks: disks:
- size_gb: 10 - size_gb: 10
sr: my_sr sr: my_sr
hardware: hardware:
num_cpus: 6 num_cpus: 6
num_cpu_cores_per_socket: 3 num_cpu_cores_per_socket: 3
@ -315,8 +314,8 @@ EXAMPLES = r'''
type: iso type: iso
iso_name: guest-tools.iso iso_name: guest-tools.iso
networks: networks:
- name: VM Network - name: VM Network
mac: aa:bb:dd:aa:00:14 mac: aa:bb:dd:aa:00:14
wait_for_ip_address: true wait_for_ip_address: true
delegate_to: localhost delegate_to: localhost
register: deploy register: deploy
@ -330,8 +329,8 @@ EXAMPLES = r'''
name: testvm_6 name: testvm_6
is_template: true is_template: true
disk: disk:
- size_gb: 10 - size_gb: 10
sr: my_sr sr: my_sr
hardware: hardware:
memory_mb: 512 memory_mb: 512
num_cpus: 1 num_cpus: 1
@ -365,8 +364,8 @@ EXAMPLES = r'''
name: testvm_8 name: testvm_8
state: present state: present
custom_params: custom_params:
- key: HVM_boot_params - key: HVM_boot_params
value: { "order": "ndc" } value: {"order": "ndc"}
delegate_to: localhost delegate_to: localhost
- name: Customize network parameters - name: Customize network parameters
@ -376,154 +375,154 @@ EXAMPLES = r'''
password: "{{ xenserver_password }}" password: "{{ xenserver_password }}"
name: testvm_10 name: testvm_10
networks: networks:
- name: VM Network - name: VM Network
ip: 192.168.1.100/24 ip: 192.168.1.100/24
gateway: 192.168.1.1 gateway: 192.168.1.1
- type: dhcp - type: dhcp
delegate_to: localhost delegate_to: localhost
''' """
RETURN = r''' RETURN = r"""
instance: instance:
description: Metadata about the VM description: Metadata about the VM.
returned: always returned: always
type: dict type: dict
sample: { sample: {
"cdrom": { "cdrom": {
"type": "none" "type": "none"
}, },
"customization_agent": "native", "customization_agent": "native",
"disks": [ "disks": [
{ {
"name": "testvm_11-0", "name": "testvm_11-0",
"name_desc": "",
"os_device": "xvda",
"size": 42949672960,
"sr": "Local storage",
"sr_uuid": "0af1245e-bdb0-ba33-1446-57a962ec4075",
"vbd_userdevice": "0"
},
{
"name": "testvm_11-1",
"name_desc": "",
"os_device": "xvdb",
"size": 42949672960,
"sr": "Local storage",
"sr_uuid": "0af1245e-bdb0-ba33-1446-57a962ec4075",
"vbd_userdevice": "1"
}
],
"domid": "56",
"folder": "",
"hardware": {
"memory_mb": 8192,
"num_cpu_cores_per_socket": 2,
"num_cpus": 4
},
"home_server": "",
"is_template": false,
"name": "testvm_11",
"name_desc": "", "name_desc": "",
"networks": [ "os_device": "xvda",
{ "size": 42949672960,
"gateway": "192.168.0.254", "sr": "Local storage",
"gateway6": "fc00::fffe", "sr_uuid": "0af1245e-bdb0-ba33-1446-57a962ec4075",
"ip": "192.168.0.200", "vbd_userdevice": "0"
"ip6": [ },
"fe80:0000:0000:0000:e9cb:625a:32c5:c291", {
"fc00:0000:0000:0000:0000:0000:0000:0001" "name": "testvm_11-1",
], "name_desc": "",
"mac": "ba:91:3a:48:20:76", "os_device": "xvdb",
"mtu": "1500", "size": 42949672960,
"name": "Pool-wide network associated with eth1", "sr": "Local storage",
"netmask": "255.255.255.128", "sr_uuid": "0af1245e-bdb0-ba33-1446-57a962ec4075",
"prefix": "25", "vbd_userdevice": "1"
"prefix6": "64", }
"vif_device": "0" ],
} "domid": "56",
"folder": "",
"hardware": {
"memory_mb": 8192,
"num_cpu_cores_per_socket": 2,
"num_cpus": 4
},
"home_server": "",
"is_template": false,
"name": "testvm_11",
"name_desc": "",
"networks": [
{
"gateway": "192.168.0.254",
"gateway6": "fc00::fffe",
"ip": "192.168.0.200",
"ip6": [
"fe80:0000:0000:0000:e9cb:625a:32c5:c291",
"fc00:0000:0000:0000:0000:0000:0000:0001"
], ],
"other_config": { "mac": "ba:91:3a:48:20:76",
"base_template_name": "Windows Server 2016 (64-bit)", "mtu": "1500",
"import_task": "OpaqueRef:e43eb71c-45d6-5351-09ff-96e4fb7d0fa5", "name": "Pool-wide network associated with eth1",
"install-methods": "cdrom", "netmask": "255.255.255.128",
"instant": "true", "prefix": "25",
"mac_seed": "f83e8d8a-cfdc-b105-b054-ef5cb416b77e" "prefix6": "64",
}, "vif_device": "0"
"platform": { }
"acpi": "1", ],
"apic": "true", "other_config": {
"cores-per-socket": "2", "base_template_name": "Windows Server 2016 (64-bit)",
"device_id": "0002", "import_task": "OpaqueRef:e43eb71c-45d6-5351-09ff-96e4fb7d0fa5",
"hpet": "true", "install-methods": "cdrom",
"nx": "true", "instant": "true",
"pae": "true", "mac_seed": "f83e8d8a-cfdc-b105-b054-ef5cb416b77e"
"timeoffset": "-25200", },
"vga": "std", "platform": {
"videoram": "8", "acpi": "1",
"viridian": "true", "apic": "true",
"viridian_reference_tsc": "true", "cores-per-socket": "2",
"viridian_time_ref_count": "true" "device_id": "0002",
}, "hpet": "true",
"state": "poweredon", "nx": "true",
"uuid": "e3c0b2d5-5f05-424e-479c-d3df8b3e7cda", "pae": "true",
"xenstore_data": { "timeoffset": "-25200",
"vm-data": "" "vga": "std",
} "videoram": "8",
"viridian": "true",
"viridian_reference_tsc": "true",
"viridian_time_ref_count": "true"
},
"state": "poweredon",
"uuid": "e3c0b2d5-5f05-424e-479c-d3df8b3e7cda",
"xenstore_data": {
"vm-data": ""
} }
}
changes: changes:
description: Detected or made changes to VM description: Detected or made changes to VM.
returned: always returned: always
type: list type: list
sample: [ sample: [
{
"hardware": [
"num_cpus"
]
},
{
"disks_changed": [
[],
[
"size"
]
]
},
{
"disks_new": [
{ {
"hardware": [ "name": "new-disk",
"num_cpus" "name_desc": "",
] "position": 2,
}, "size_gb": "4",
"vbd_userdevice": "2"
}
]
},
{
"cdrom": [
"type",
"iso_name"
]
},
{
"networks_changed": [
[
"mac"
],
]
},
{
"networks_new": [
{ {
"disks_changed": [ "name": "Pool-wide network associated with eth2",
[], "position": 1,
[ "vif_device": "1"
"size" }
] ]
] },
}, "need_poweredoff"
{ ]
"disks_new": [ """
{
"name": "new-disk",
"name_desc": "",
"position": 2,
"size_gb": "4",
"vbd_userdevice": "2"
}
]
},
{
"cdrom": [
"type",
"iso_name"
]
},
{
"networks_changed": [
[
"mac"
],
]
},
{
"networks_new": [
{
"name": "Pool-wide network associated with eth2",
"position": 1,
"vif_device": "1"
}
]
},
"need_poweredoff"
]
'''
import re import re

View File

@ -8,48 +8,46 @@
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
DOCUMENTATION = r''' DOCUMENTATION = r"""
---
module: xenserver_guest_info module: xenserver_guest_info
short_description: Gathers information for virtual machines running on Citrix Hypervisor/XenServer host or pool short_description: Gathers information for virtual machines running on Citrix Hypervisor/XenServer host or pool
description: > description: This module can be used to gather essential VM facts.
This module can be used to gather essential VM facts.
author: author:
- Bojan Vitnik (@bvitnik) <bvitnik@mainstream.rs> - Bojan Vitnik (@bvitnik) <bvitnik@mainstream.rs>
notes: notes:
- Minimal supported version of XenServer is 5.6. - Minimal supported version of XenServer is 5.6.
- Module was tested with XenServer 6.5, 7.1, 7.2, 7.6, Citrix Hypervisor 8.0, XCP-ng 7.6 and 8.0. - Module was tested with XenServer 6.5, 7.1, 7.2, 7.6, Citrix Hypervisor 8.0, XCP-ng 7.6 and 8.0.
- 'To acquire XenAPI Python library, just run C(pip install XenAPI) on your Ansible Control Node. The library can also be found inside - 'To acquire XenAPI Python library, just run C(pip install XenAPI) on your Ansible Control Node. The library can also be found inside Citrix
Citrix Hypervisor/XenServer SDK (downloadable from Citrix website). Copy the XenAPI.py file from the SDK to your Python site-packages on your Hypervisor/XenServer SDK (downloadable from Citrix website). Copy the C(XenAPI.py) file from the SDK to your Python site-packages on your Ansible
Ansible Control Node to use it. Latest version of the library can also be acquired from GitHub: Control Node to use it. Latest version of the library can also be acquired from GitHub:
U(https://raw.githubusercontent.com/xapi-project/xen-api/master/scripts/examples/python/XenAPI/XenAPI.py)' U(https://raw.githubusercontent.com/xapi-project/xen-api/master/scripts/examples/python/XenAPI/XenAPI.py)'
- 'If no scheme is specified in C(hostname), module defaults to C(http://) because C(https://) is problematic in most setups. Make sure you are - 'If no scheme is specified in C(hostname), module defaults to C(http://) because C(https://) is problematic in most setups. Make sure you
accessing XenServer host in trusted environment or use C(https://) scheme explicitly.' are accessing XenServer host in trusted environment or use C(https://) scheme explicitly.'
- 'To use C(https://) scheme for C(hostname) you have to either import host certificate to your OS certificate store or use C(validate_certs: no) - 'To use C(https://) scheme for C(hostname) you have to either import host certificate to your OS certificate store or use O(validate_certs=no) which
which requires XenAPI library from XenServer 7.2 SDK or newer and Python 2.7.9 or newer.' requires XenAPI library from XenServer 7.2 SDK or newer and Python 2.7.9 or newer.'
requirements: requirements:
- XenAPI - XenAPI
options: options:
name: name:
description: description:
- Name of the VM to gather facts from. - Name of the VM to gather facts from.
- VMs running on XenServer do not necessarily have unique names. The module will fail if multiple VMs with same name are found. - VMs running on XenServer do not necessarily have unique names. The module will fail if multiple VMs with same name are found.
- In case of multiple VMs with same name, use O(uuid) to uniquely specify VM to manage. - In case of multiple VMs with same name, use O(uuid) to uniquely specify VM to manage.
- This parameter is case sensitive. - This parameter is case sensitive.
type: str type: str
aliases: [ name_label ] aliases: [name_label]
uuid: uuid:
description: description:
- UUID of the VM to gather fact of. This is XenServer's unique identifier. - UUID of the VM to gather fact of. This is XenServer's unique identifier.
- It is required if name is not unique. - It is required if name is not unique.
type: str type: str
extends_documentation_fragment: extends_documentation_fragment:
- community.general.xenserver.documentation - community.general.xenserver.documentation
- community.general.attributes - community.general.attributes
- community.general.attributes.info_module - community.general.attributes.info_module
''' """
EXAMPLES = r''' EXAMPLES = r"""
- name: Gather facts - name: Gather facts
community.general.xenserver_guest_info: community.general.xenserver_guest_info:
hostname: "{{ xenserver_hostname }}" hostname: "{{ xenserver_hostname }}"
@ -58,11 +56,11 @@ EXAMPLES = r'''
name: testvm_11 name: testvm_11
delegate_to: localhost delegate_to: localhost
register: facts register: facts
''' """
RETURN = r''' RETURN = r"""
instance: instance:
description: Metadata about the VM description: Metadata about the VM.
returned: always returned: always
type: dict type: dict
sample: { sample: {
@ -147,7 +145,7 @@ instance:
"vm-data": "" "vm-data": ""
} }
} }
''' """
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule

View File

@ -8,27 +8,25 @@
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
DOCUMENTATION = r''' DOCUMENTATION = r"""
---
module: xenserver_guest_powerstate module: xenserver_guest_powerstate
short_description: Manages power states of virtual machines running on Citrix Hypervisor/XenServer host or pool short_description: Manages power states of virtual machines running on Citrix Hypervisor/XenServer host or pool
description: > description: This module can be used to power on, power off, restart or suspend virtual machine and gracefully reboot or shutdown guest OS of virtual machine.
This module can be used to power on, power off, restart or suspend virtual machine and gracefully reboot or shutdown guest OS of virtual machine.
author: author:
- Bojan Vitnik (@bvitnik) <bvitnik@mainstream.rs> - Bojan Vitnik (@bvitnik) <bvitnik@mainstream.rs>
notes: notes:
- Minimal supported version of XenServer is 5.6. - Minimal supported version of XenServer is 5.6.
- Module was tested with XenServer 6.5, 7.1, 7.2, 7.6, Citrix Hypervisor 8.0, XCP-ng 7.6 and 8.0. - Module was tested with XenServer 6.5, 7.1, 7.2, 7.6, Citrix Hypervisor 8.0, XCP-ng 7.6 and 8.0.
- 'To acquire XenAPI Python library, just run C(pip install XenAPI) on your Ansible Control Node. The library can also be found inside - 'To acquire XenAPI Python library, just run C(pip install XenAPI) on your Ansible Control Node. The library can also be found inside Citrix
Citrix Hypervisor/XenServer SDK (downloadable from Citrix website). Copy the XenAPI.py file from the SDK to your Python site-packages on your Hypervisor/XenServer SDK (downloadable from Citrix website). Copy the C(XenAPI.py) file from the SDK to your Python site-packages on your Ansible
Ansible Control Node to use it. Latest version of the library can also be acquired from GitHub: Control Node to use it. Latest version of the library can also be acquired from GitHub:
U(https://raw.githubusercontent.com/xapi-project/xen-api/master/scripts/examples/python/XenAPI/XenAPI.py)' U(https://raw.githubusercontent.com/xapi-project/xen-api/master/scripts/examples/python/XenAPI/XenAPI.py).'
- 'If no scheme is specified in C(hostname), module defaults to C(http://) because C(https://) is problematic in most setups. Make sure you are - 'If no scheme is specified in C(hostname), module defaults to C(http://) because C(https://) is problematic in most setups. Make sure you
accessing XenServer host in trusted environment or use C(https://) scheme explicitly.' are accessing XenServer host in trusted environment or use C(https://) scheme explicitly.'
- 'To use C(https://) scheme for C(hostname) you have to either import host certificate to your OS certificate store or use C(validate_certs: no) - 'To use C(https://) scheme for C(hostname) you have to either import host certificate to your OS certificate store or use C(validate_certs:
which requires XenAPI library from XenServer 7.2 SDK or newer and Python 2.7.9 or newer.' no) which requires XenAPI library from XenServer 7.2 SDK or newer and Python 2.7.9 or newer.'
requirements: requirements:
- XenAPI - XenAPI
attributes: attributes:
check_mode: check_mode:
support: full support: full
@ -37,45 +35,44 @@ attributes:
options: options:
state: state:
description: description:
- Specify the state VM should be in. - Specify the state VM should be in.
- If O(state) is set to value other than V(present), then VM is transitioned into required state and facts are returned. - If O(state) is set to value other than V(present), then VM is transitioned into required state and facts are returned.
- If O(state) is set to V(present), then VM is just checked for existence and facts are returned. - If O(state) is set to V(present), then VM is just checked for existence and facts are returned.
type: str type: str
default: present default: present
choices: [ powered-on, powered-off, restarted, shutdown-guest, reboot-guest, suspended, present ] choices: [powered-on, powered-off, restarted, shutdown-guest, reboot-guest, suspended, present]
name: name:
description: description:
- Name of the VM to manage. - Name of the VM to manage.
- VMs running on XenServer do not necessarily have unique names. The module will fail if multiple VMs with same name are found. - VMs running on XenServer do not necessarily have unique names. The module will fail if multiple VMs with same name are found.
- In case of multiple VMs with same name, use O(uuid) to uniquely specify VM to manage. - In case of multiple VMs with same name, use O(uuid) to uniquely specify VM to manage.
- This parameter is case sensitive. - This parameter is case sensitive.
type: str type: str
aliases: [ name_label ] aliases: [name_label]
uuid: uuid:
description: description:
- UUID of the VM to manage if known. This is XenServer's unique identifier. - UUID of the VM to manage if known. This is XenServer's unique identifier.
- It is required if name is not unique. - It is required if name is not unique.
type: str type: str
wait_for_ip_address: wait_for_ip_address:
description: description:
- Wait until XenServer detects an IP address for the VM. - Wait until XenServer detects an IP address for the VM.
- This requires XenServer Tools to be preinstalled on the VM to work properly. - This requires XenServer Tools to be preinstalled on the VM to work properly.
type: bool type: bool
default: false default: false
state_change_timeout: state_change_timeout:
description: description:
- 'By default, module will wait indefinitely for VM to change state or acquire an IP address if O(wait_for_ip_address=true).' - 'By default, module will wait indefinitely for VM to change state or acquire an IP address if O(wait_for_ip_address=true).'
- If this parameter is set to positive value, the module will instead wait specified number of seconds for the state change. - If this parameter is set to positive value, the module will instead wait specified number of seconds for the state change.
- In case of timeout, module will generate an error message. - In case of timeout, module will generate an error message.
type: int type: int
default: 0 default: 0
extends_documentation_fragment: extends_documentation_fragment:
- community.general.xenserver.documentation - community.general.xenserver.documentation
- community.general.attributes - community.general.attributes
"""
''' EXAMPLES = r"""
EXAMPLES = r'''
- name: Power on VM - name: Power on VM
community.general.xenserver_guest_powerstate: community.general.xenserver_guest_powerstate:
hostname: "{{ xenserver_hostname }}" hostname: "{{ xenserver_hostname }}"
@ -85,11 +82,11 @@ EXAMPLES = r'''
state: powered-on state: powered-on
delegate_to: localhost delegate_to: localhost
register: facts register: facts
''' """
RETURN = r''' RETURN = r"""
instance: instance:
description: Metadata about the VM description: Metadata about the VM.
returned: always returned: always
type: dict type: dict
sample: { sample: {
@ -174,7 +171,7 @@ instance:
"vm-data": "" "vm-data": ""
} }
} }
''' """
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule

View File

@ -8,26 +8,25 @@
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
DOCUMENTATION = """ DOCUMENTATION = r"""
---
module: xfconf module: xfconf
author: author:
- "Joseph Benden (@jbenden)" - "Joseph Benden (@jbenden)"
- "Alexei Znamensky (@russoz)" - "Alexei Znamensky (@russoz)"
short_description: Edit XFCE4 Configurations short_description: Edit XFCE4 Configurations
description: description:
- This module allows for the manipulation of Xfce 4 Configuration with the help of C(xfconf-query). - This module allows for the manipulation of Xfce 4 Configuration with the help of C(xfconf-query).
seealso: seealso:
- name: xfconf-query(1) man page - name: xfconf-query(1) man page
description: Manual page of the C(xfconf-query) tool at the XFCE documentation site. description: Manual page of the C(xfconf-query) tool at the XFCE documentation site.
link: 'https://docs.xfce.org/xfce/xfconf/xfconf-query' link: 'https://docs.xfce.org/xfce/xfconf/xfconf-query'
- name: xfconf - Configuration Storage System - name: xfconf - Configuration Storage System
description: XFCE documentation for the Xfconf configuration system. description: XFCE documentation for the Xfconf configuration system.
link: 'https://docs.xfce.org/xfce/xfconf/start' link: 'https://docs.xfce.org/xfce/xfconf/start'
extends_documentation_fragment: extends_documentation_fragment:
- community.general.attributes - community.general.attributes
attributes: attributes:
check_mode: check_mode:
@ -38,50 +37,49 @@ attributes:
options: options:
channel: channel:
description: description:
- A Xfconf preference channel is a top-level tree key, inside of the Xfconf repository that corresponds to the location for which all application - A Xfconf preference channel is a top-level tree key, inside of the Xfconf repository that corresponds to the location for which all application
properties/keys are stored. See man xfconf-query(1). properties/keys are stored. See man xfconf-query(1).
required: true required: true
type: str type: str
property: property:
description: description:
- A Xfce preference key is an element in the Xfconf repository that corresponds to an application preference. See man xfconf-query(1). - A Xfce preference key is an element in the Xfconf repository that corresponds to an application preference. See man xfconf-query(1).
required: true required: true
type: str type: str
value: value:
description: description:
- Preference properties typically have simple values such as strings, integers, or lists of strings and integers. See man xfconf-query(1). - Preference properties typically have simple values such as strings, integers, or lists of strings and integers. See man xfconf-query(1).
type: list type: list
elements: raw elements: raw
value_type: value_type:
description: description:
- The type of value being set. - The type of value being set.
- When providing more than one O(value_type), the length of the list must be equal to the length of O(value). - When providing more than one O(value_type), the length of the list must be equal to the length of O(value).
- If only one O(value_type) is provided, but O(value) contains more than on element, that O(value_type) will be applied to all elements of - If only one O(value_type) is provided, but O(value) contains more than on element, that O(value_type) will be applied to all elements
O(value). of O(value).
- If the O(property) being set is an array and it can possibly have only one element in the array, then O(force_array=true) must be used to - If the O(property) being set is an array and it can possibly have only one element in the array, then O(force_array=true) must be used
ensure that C(xfconf-query) will interpret the value as an array rather than a scalar. to ensure that C(xfconf-query) will interpret the value as an array rather than a scalar.
- Support for V(uchar), V(char), V(uint64), and V(int64) has been added in community.general 4.8.0. - Support for V(uchar), V(char), V(uint64), and V(int64) has been added in community.general 4.8.0.
type: list type: list
elements: str elements: str
choices: [string, int, double, bool, uint, uchar, char, uint64, int64, float] choices: [string, int, double, bool, uint, uchar, char, uint64, int64, float]
state: state:
type: str type: str
description: description:
- The action to take upon the property/value. - The action to take upon the property/value.
- The state V(get) has been removed in community.general 5.0.0. Please use the module M(community.general.xfconf_info) instead. - The state V(get) has been removed in community.general 5.0.0. Please use the module M(community.general.xfconf_info) instead.
choices: [present, absent] choices: [present, absent]
default: "present" default: "present"
force_array: force_array:
description: description:
- Force array even if only one element. - Force array even if only one element.
type: bool type: bool
default: false default: false
aliases: ['array'] aliases: ['array']
version_added: 1.0.0 version_added: 1.0.0
""" """
EXAMPLES = """ EXAMPLES = r"""
---
- name: Change the DPI to "192" - name: Change the DPI to "192"
xfconf: xfconf:
channel: "xsettings" channel: "xsettings"
@ -105,57 +103,56 @@ EXAMPLES = """
force_array: true force_array: true
""" """
RETURN = """ RETURN = r"""
---
channel: channel:
description: The channel specified in the module parameters description: The channel specified in the module parameters.
returned: success returned: success
type: str type: str
sample: "xsettings" sample: "xsettings"
property: property:
description: The property specified in the module parameters description: The property specified in the module parameters.
returned: success returned: success
type: str type: str
sample: "/Xft/DPI" sample: "/Xft/DPI"
value_type: value_type:
description: description:
- The type of the value that was changed (V(none) for O(state=reset)). Either a single string value or a list of strings for array types. - The type of the value that was changed (V(none) for O(state=reset)). Either a single string value or a list of strings for array types.
- This is a string or a list of strings. - This is a string or a list of strings.
returned: success returned: success
type: any type: any
sample: '"int" or ["str", "str", "str"]' sample: '"int" or ["str", "str", "str"]'
value: value:
description: description:
- The value of the preference key after executing the module. Either a single string value or a list of strings for array types. - The value of the preference key after executing the module. Either a single string value or a list of strings for array types.
- This is a string or a list of strings. - This is a string or a list of strings.
returned: success returned: success
type: any type: any
sample: '"192" or ["orange", "yellow", "violet"]' sample: "'192' or ['orange', 'yellow', 'violet']"
previous_value: previous_value:
description: description:
- The value of the preference key before executing the module. Either a single string value or a list of strings for array types. - The value of the preference key before executing the module. Either a single string value or a list of strings for array types.
- This is a string or a list of strings. - This is a string or a list of strings.
returned: success returned: success
type: any type: any
sample: '"96" or ["red", "blue", "green"]' sample: '"96" or ["red", "blue", "green"]'
cmd: cmd:
description: description:
- A list with the resulting C(xfconf-query) command executed by the module. - A list with the resulting C(xfconf-query) command executed by the module.
returned: success returned: success
type: list type: list
elements: str elements: str
version_added: 5.4.0 version_added: 5.4.0
sample: sample:
- /usr/bin/xfconf-query - /usr/bin/xfconf-query
- --channel - --channel
- xfce4-panel - xfce4-panel
- --property - --property
- /plugins/plugin-19/timezone - /plugins/plugin-19/timezone
- --create - --create
- --type - --type
- string - string
- --set - --set
- Pacific/Auckland - Pacific/Auckland
""" """
from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper

View File

@ -7,18 +7,17 @@
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
DOCUMENTATION = """ DOCUMENTATION = r"""
---
module: xfconf_info module: xfconf_info
author: author:
- "Alexei Znamensky (@russoz)" - "Alexei Znamensky (@russoz)"
short_description: Retrieve XFCE4 configurations short_description: Retrieve XFCE4 configurations
version_added: 3.5.0 version_added: 3.5.0
description: description:
- This module allows retrieving Xfce 4 configurations with the help of C(xfconf-query). - This module allows retrieving Xfce 4 configurations with the help of C(xfconf-query).
extends_documentation_fragment: extends_documentation_fragment:
- community.general.attributes - community.general.attributes
- community.general.attributes.info_module - community.general.attributes.info_module
attributes: attributes:
check_mode: check_mode:
version_added: 3.3.0 version_added: 3.3.0
@ -26,26 +25,21 @@ attributes:
options: options:
channel: channel:
description: description:
- > - "A Xfconf preference channel is a top-level tree key, inside of the Xfconf repository that corresponds to the location for which all application
A Xfconf preference channel is a top-level tree key, inside of the properties/keys are stored."
Xfconf repository that corresponds to the location for which all - If not provided, the module will list all available channels.
application properties/keys are stored.
- If not provided, the module will list all available channels.
type: str type: str
property: property:
description: description:
- > - "A Xfce preference key is an element in the Xfconf repository that corresponds to an application preference."
A Xfce preference key is an element in the Xfconf repository - If provided, then O(channel) is required.
that corresponds to an application preference. - If not provided and a O(channel) is provided, then the module will list all available properties in that O(channel).
- If provided, then O(channel) is required.
- If not provided and a O(channel) is provided, then the module will list all available properties in that O(channel).
type: str type: str
notes: notes:
- See man xfconf-query(1) for more details. - See man xfconf-query(1) for more details.
""" """
EXAMPLES = """ EXAMPLES = r"""
---
- name: Get list of all available channels - name: Get list of all available channels
community.general.xfconf_info: {} community.general.xfconf_info: {}
register: result register: result
@ -68,63 +62,62 @@ EXAMPLES = """
register: result register: result
""" """
RETURN = """ RETURN = r"""
---
channels: channels:
description: description:
- List of available channels. - List of available channels.
- Returned when the module receives no parameter at all. - Returned when the module receives no parameter at all.
returned: success returned: success
type: list type: list
elements: str elements: str
sample: sample:
- xfce4-desktop - xfce4-desktop
- displays - displays
- xsettings - xsettings
- xfwm4 - xfwm4
properties: properties:
description: description:
- List of available properties for a specific channel. - List of available properties for a specific channel.
- Returned by passing only the O(channel) parameter to the module. - Returned by passing only the O(channel) parameter to the module.
returned: success returned: success
type: list type: list
elements: str elements: str
sample: sample:
- /Gdk/WindowScalingFactor - /Gdk/WindowScalingFactor
- /Gtk/ButtonImages - /Gtk/ButtonImages
- /Gtk/CursorThemeSize - /Gtk/CursorThemeSize
- /Gtk/DecorationLayout - /Gtk/DecorationLayout
- /Gtk/FontName - /Gtk/FontName
- /Gtk/MenuImages - /Gtk/MenuImages
- /Gtk/MonospaceFontName - /Gtk/MonospaceFontName
- /Net/DoubleClickTime - /Net/DoubleClickTime
- /Net/IconThemeName - /Net/IconThemeName
- /Net/ThemeName - /Net/ThemeName
- /Xft/Antialias - /Xft/Antialias
- /Xft/Hinting - /Xft/Hinting
- /Xft/HintStyle - /Xft/HintStyle
- /Xft/RGBA - /Xft/RGBA
is_array: is_array:
description: description:
- Flag indicating whether the property is an array or not. - Flag indicating whether the property is an array or not.
returned: success returned: success
type: bool type: bool
value: value:
description: description:
- The value of the property. Empty if the property is of array type. - The value of the property. Empty if the property is of array type.
returned: success returned: success
type: str type: str
sample: Monospace 10 sample: Monospace 10
value_array: value_array:
description: description:
- The array value of the property. Empty if the property is not of array type. - The array value of the property. Empty if the property is not of array type.
returned: success returned: success
type: list type: list
elements: str elements: str
sample: sample:
- Main - Main
- Work - Work
- Tmp - Tmp
""" """
from ansible_collections.community.general.plugins.module_utils.module_helper import ModuleHelper from ansible_collections.community.general.plugins.module_utils.module_helper import ModuleHelper

View File

@ -12,7 +12,6 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
DOCUMENTATION = r""" DOCUMENTATION = r"""
---
module: xfs_quota module: xfs_quota
short_description: Manage quotas on XFS filesystems short_description: Manage quotas on XFS filesystems
description: description:
@ -85,7 +84,7 @@ options:
- absent - absent
requirements: requirements:
- xfsprogs - xfsprogs
""" """
EXAMPLES = r""" EXAMPLES = r"""
@ -109,40 +108,39 @@ EXAMPLES = r"""
mountpoint: /home mountpoint: /home
isoft: 1024 isoft: 1024
ihard: 2048 ihard: 2048
""" """
RETURN = r""" RETURN = r"""
bhard: bhard:
description: the current bhard setting in bytes description: The current C(bhard) setting in bytes.
returned: always returned: always
type: int type: int
sample: 1024 sample: 1024
bsoft: bsoft:
description: the current bsoft setting in bytes description: The current C(bsoft) setting in bytes.
returned: always returned: always
type: int type: int
sample: 1024 sample: 1024
ihard: ihard:
description: the current ihard setting in bytes description: The current C(ihard) setting in bytes.
returned: always returned: always
type: int type: int
sample: 100 sample: 100
isoft: isoft:
description: the current isoft setting in bytes description: The current C(isoft) setting in bytes.
returned: always returned: always
type: int type: int
sample: 100 sample: 100
rtbhard: rtbhard:
description: the current rtbhard setting in bytes description: The current C(rtbhard) setting in bytes.
returned: always returned: always
type: int type: int
sample: 1024 sample: 1024
rtbsoft: rtbsoft:
description: the current rtbsoft setting in bytes description: The current C(rtbsoft) setting in bytes.
returned: always returned: always
type: int type: int
sample: 1024 sample: 1024
""" """
import grp import grp

View File

@ -11,8 +11,7 @@
from __future__ import (absolute_import, division, print_function) from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
DOCUMENTATION = r''' DOCUMENTATION = r"""
---
module: xml module: xml
short_description: Manage bits and pieces of XML files or strings short_description: Manage bits and pieces of XML files or strings
description: description:
@ -27,96 +26,94 @@ attributes:
options: options:
path: path:
description: description:
- Path to the file to operate on. - Path to the file to operate on.
- This file must exist ahead of time. - This file must exist ahead of time.
- This parameter is required, unless O(xmlstring) is given. - This parameter is required, unless O(xmlstring) is given.
type: path type: path
aliases: [ dest, file ] aliases: [dest, file]
xmlstring: xmlstring:
description: description:
- A string containing XML on which to operate. - A string containing XML on which to operate.
- This parameter is required, unless O(path) is given. - This parameter is required, unless O(path) is given.
type: str type: str
xpath: xpath:
description: description:
- A valid XPath expression describing the item(s) you want to manipulate. - A valid XPath expression describing the item(s) you want to manipulate.
- Operates on the document root, V(/), by default. - Operates on the document root, V(/), by default.
type: str type: str
namespaces: namespaces:
description: description:
- The namespace C(prefix:uri) mapping for the XPath expression. - The namespace C(prefix:uri) mapping for the XPath expression.
- Needs to be a C(dict), not a C(list) of items. - Needs to be a C(dict), not a C(list) of items.
type: dict type: dict
default: {} default: {}
state: state:
description: description:
- Set or remove an xpath selection (node(s), attribute(s)). - Set or remove an xpath selection (node(s), attribute(s)).
type: str type: str
choices: [ absent, present ] choices: [absent, present]
default: present default: present
aliases: [ ensure ] aliases: [ensure]
attribute: attribute:
description: description:
- The attribute to select when using parameter O(value). - The attribute to select when using parameter O(value).
- This is a string, not prepended with V(@). - This is a string, not prepended with V(@).
type: raw type: raw
value: value:
description: description:
- Desired state of the selected attribute. - Desired state of the selected attribute.
- Either a string, or to unset a value, the Python V(None) keyword (YAML Equivalent, V(null)). - Either a string, or to unset a value, the Python V(None) keyword (YAML Equivalent, V(null)).
- Elements default to no value (but present). - Elements default to no value (but present).
- Attributes default to an empty string. - Attributes default to an empty string.
type: raw type: raw
add_children: add_children:
description: description:
- Add additional child-element(s) to a selected element for a given O(xpath). - Add additional child-element(s) to a selected element for a given O(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 (for example C(children=ansible) to add an empty C(<ansible/>)
(for example C(children=ansible) to add an empty C(<ansible/>) child element), 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 O(xpath) to be set.
- This parameter requires O(xpath) to be set.
type: list type: list
elements: raw elements: raw
set_children: set_children:
description: description:
- Set the child-element(s) of a selected element for a given O(xpath). - Set the child-element(s) of a selected element for a given O(xpath).
- Removes any existing children. - Removes any existing children.
- Child elements must be specified as in O(add_children). - Child elements must be specified as in O(add_children).
- This parameter requires O(xpath) to be set. - This parameter requires O(xpath) to be set.
type: list type: list
elements: raw elements: raw
count: count:
description: description:
- Search for a given O(xpath) and provide the count of any matches. - Search for a given O(xpath) and provide the count of any matches.
- This parameter requires O(xpath) to be set. - This parameter requires O(xpath) to be set.
type: bool type: bool
default: false default: false
print_match: print_match:
description: description:
- Search for a given O(xpath) and print out any matches. - Search for a given O(xpath) and print out any matches.
- This parameter requires O(xpath) to be set. - This parameter requires O(xpath) to be set.
type: bool type: bool
default: false default: false
pretty_print: pretty_print:
description: description:
- Pretty print XML output. - Pretty print XML output.
type: bool type: bool
default: false default: false
content: content:
description: description:
- Search for a given O(xpath) and get content. - Search for a given O(xpath) and get content.
- This parameter requires O(xpath) to be set. - This parameter requires O(xpath) to be set.
type: str type: str
choices: [ attribute, text ] choices: [attribute, text]
input_type: input_type:
description: description:
- Type of input for O(add_children) and O(set_children). - Type of input for O(add_children) and O(set_children).
type: str type: str
choices: [ xml, yaml ] choices: [xml, yaml]
default: yaml default: yaml
backup: backup:
description: description:
- Create a backup file including the timestamp information so you can get - Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly.
the original file back if you somehow clobbered it incorrectly.
type: bool type: bool
default: false default: false
strip_cdata_tags: strip_cdata_tags:
@ -128,46 +125,44 @@ options:
insertbefore: insertbefore:
description: description:
- Add additional child-element(s) before the first selected element for a given O(xpath). - Add additional child-element(s) before the first selected element for a given O(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 (for example C(children=ansible) to add an empty C(<ansible/>)
(for example C(children=ansible) to add an empty C(<ansible/>) child element), 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 O(xpath) to be set. - This parameter requires O(xpath) to be set.
type: bool type: bool
default: false default: false
insertafter: insertafter:
description: description:
- Add additional child-element(s) after the last selected element for a given O(xpath). - Add additional child-element(s) after the last selected element for a given O(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 (for example C(children=ansible) to add an empty C(<ansible/>)
(for example C(children=ansible) to add an empty C(<ansible/>) child element), 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 O(xpath) to be set. - This parameter requires O(xpath) to be set.
type: bool type: bool
default: false default: false
requirements: requirements:
- lxml >= 2.3.0 - lxml >= 2.3.0
notes: notes:
- Use the C(--check) and C(--diff) options when testing your expressions. - Use the C(--check) and C(--diff) options when testing your expressions.
- The diff output is automatically pretty-printed, so may not reflect the actual file content, only the file structure. - The diff output is automatically pretty-printed, so may not reflect the actual file content, only the file structure.
- 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 O(namespaces) parameter, see the examples. - Beware that in case your XML elements are namespaced, you need to use the O(namespaces) parameter, see the examples.
- 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.
seealso: seealso:
- name: Xml module development community wiki - name: XML module development community wiki (archived)
description: More information related to the development of this xml module. description: More information related to the development of this xml module.
link: https://github.com/ansible/community/wiki/Module:-xml link: https://github.com/ansible/community/wiki/Module:-xml
- name: Introduction to XPath - name: Introduction to XPath
description: A brief tutorial on XPath (w3schools.com). description: A brief tutorial on XPath (w3schools.com).
link: https://www.w3schools.com/xml/xpath_intro.asp link: https://www.w3schools.com/xml/xpath_intro.asp
- name: XPath Reference document - name: XPath Reference document
description: The reference documentation on XSLT/XPath (developer.mozilla.org). description: The reference documentation on XSLT/XPath (developer.mozilla.org).
link: https://developer.mozilla.org/en-US/docs/Web/XPath link: https://developer.mozilla.org/en-US/docs/Web/XPath
author: author:
- Tim Bielawa (@tbielawa) - Tim Bielawa (@tbielawa)
- Magnus Hedemark (@magnus919) - Magnus Hedemark (@magnus919)
- Dag Wieers (@dagwieers) - Dag Wieers (@dagwieers)
''' """
EXAMPLES = r''' EXAMPLES = r"""
# Consider the following XML file: # Consider the following XML file:
# #
# <business type="bar"> # <business type="bar">
@ -219,9 +214,9 @@ EXAMPLES = r'''
path: /foo/bar.xml path: /foo/bar.xml
xpath: /business/beers xpath: /business/beers
add_children: add_children:
- beer: Old Rasputin - beer: Old Rasputin
- beer: Old Motor Oil - beer: Old Motor Oil
- beer: Old Curmudgeon - beer: Old Curmudgeon
- name: Add several more beers to the 'beers' element and add them before the 'Rochefort 10' element - name: Add several more beers to the 'beers' element and add them before the 'Rochefort 10' element
community.general.xml: community.general.xml:
@ -229,9 +224,9 @@ EXAMPLES = r'''
xpath: '/business/beers/beer[text()="Rochefort 10"]' xpath: '/business/beers/beer[text()="Rochefort 10"]'
insertbefore: true insertbefore: true
add_children: add_children:
- beer: Old Rasputin - beer: Old Rasputin
- beer: Old Motor Oil - beer: Old Motor Oil
- beer: Old Curmudgeon - beer: Old Curmudgeon
# NOTE: The 'state' defaults to 'present' and 'value' defaults to 'null' for elements # NOTE: The 'state' defaults to 'present' and 'value' defaults to 'null' for elements
- name: Add a 'validxhtml' element to the 'website' element - name: Add a 'validxhtml' element to the 'website' element
@ -301,14 +296,14 @@ EXAMPLES = r'''
xpath: /business xpath: /business
add_children: add_children:
- building: - building:
# Attributes # Attributes
name: Scumm bar name: Scumm bar
location: Monkey island location: Monkey island
# Subnodes # Subnodes
_: _:
- floor: Pirate hall - floor: Pirate hall
- floor: Grog storage - floor: Grog storage
- construction_date: "1990" # Only strings are valid - construction_date: "1990" # Only strings are valid
- building: Grog factory - building: Grog factory
# Consider this XML for following example - # Consider this XML for following example -
@ -327,37 +322,37 @@ EXAMPLES = r'''
path: bar.xml path: bar.xml
xpath: /config/element[@name='test1'] xpath: /config/element[@name='test1']
state: absent state: absent
''' """
RETURN = r''' RETURN = r"""
actions: actions:
description: A dictionary with the original xpath, namespaces and state. description: A dictionary with the original xpath, namespaces and state.
type: dict type: dict
returned: success returned: success
sample: {xpath: xpath, namespaces: [namespace1, namespace2], state=present} sample: {xpath: xpath, namespaces: [namespace1, namespace2], state: present}
backup_file: backup_file:
description: The name of the backup file that was created description: The name of the backup file that was created.
type: str type: str
returned: when O(backup=true) returned: when O(backup=true)
sample: /path/to/file.xml.1942.2017-08-24@14:16:01~ sample: /path/to/file.xml.1942.2017-08-24@14:16:01~
count: count:
description: The count of xpath matches. description: The count of xpath matches.
type: int type: int
returned: when parameter 'count' is set returned: when parameter O(count) is set
sample: 2 sample: 2
matches: matches:
description: The xpath matches found. description: The xpath matches found.
type: list type: list
returned: when parameter 'print_match' is set returned: when parameter O(print_match) is set
msg: msg:
description: A message related to the performed action(s). description: A message related to the performed action(s).
type: str type: str
returned: always returned: always
xmlstring: xmlstring:
description: An XML string of the resulting output. description: An XML string of the resulting output.
type: str type: str
returned: when parameter 'xmlstring' is set returned: when parameter O(xmlstring) is set
''' """
import copy import copy
import json import json