mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-06-10 18:15:39 +00:00
move common argument specs to shared module_utils
This commit is contained in:
parent
91ef50cef7
commit
125dc6f5e2
3 changed files with 35 additions and 33 deletions
|
|
@ -29,6 +29,19 @@ with deps.declare("lxml"):
|
|||
from lxml import etree # type: ignore[no-redef]
|
||||
|
||||
|
||||
COMMON_ARGUMENT_SPEC = dict(
|
||||
path=dict(type="path", aliases=["dest", "file"]),
|
||||
xmlstring=dict(type="str"),
|
||||
xpath=dict(type="str"),
|
||||
namespaces=dict(type="dict", default={}),
|
||||
count=dict(type="bool", default=False),
|
||||
print_match=dict(type="bool", default=False),
|
||||
content=dict(type="str", choices=["attribute", "text"]),
|
||||
strip_cdata_tags=dict(type="bool", default=False),
|
||||
huge_tree=dict(type="bool", default=False),
|
||||
)
|
||||
|
||||
|
||||
def check_lxml(module: AnsibleModule) -> None:
|
||||
deps.validate(module, "lxml")
|
||||
version_str = ".".join(str(f) for f in etree.LXML_VERSION)
|
||||
|
|
|
|||
|
|
@ -323,6 +323,7 @@ from ansible.module_utils.basic import AnsibleModule, json_dict_bytes_to_unicode
|
|||
from ansible.module_utils.common.text.converters import to_bytes
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils._xml import (
|
||||
COMMON_ARGUMENT_SPEC,
|
||||
check_lxml,
|
||||
collect_element_attr,
|
||||
collect_element_text,
|
||||
|
|
@ -796,29 +797,22 @@ def finish(module, tree, xpath, namespaces, changed=False, msg="", hitcount=0, m
|
|||
|
||||
|
||||
def main():
|
||||
argument_spec = copy.deepcopy(COMMON_ARGUMENT_SPEC)
|
||||
argument_spec.update(
|
||||
state=dict(type="str", default="present", choices=["absent", "present"], aliases=["ensure"]),
|
||||
value=dict(type="raw"),
|
||||
attribute=dict(type="raw"),
|
||||
add_children=dict(type="list", elements="raw"),
|
||||
set_children=dict(type="list", elements="raw"),
|
||||
pretty_print=dict(type="bool", default=False),
|
||||
input_type=dict(type="str", default="yaml", choices=["xml", "yaml"]),
|
||||
backup=dict(type="bool", default=False),
|
||||
insertbefore=dict(type="bool", default=False),
|
||||
insertafter=dict(type="bool", default=False),
|
||||
create_if_missing=dict(type="bool", default=True),
|
||||
)
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
path=dict(type="path", aliases=["dest", "file"]),
|
||||
xmlstring=dict(type="str"),
|
||||
xpath=dict(type="str"),
|
||||
namespaces=dict(type="dict", default={}),
|
||||
state=dict(type="str", default="present", choices=["absent", "present"], aliases=["ensure"]),
|
||||
value=dict(type="raw"),
|
||||
attribute=dict(type="raw"),
|
||||
add_children=dict(type="list", elements="raw"),
|
||||
set_children=dict(type="list", elements="raw"),
|
||||
count=dict(type="bool", default=False),
|
||||
print_match=dict(type="bool", default=False),
|
||||
pretty_print=dict(type="bool", default=False),
|
||||
content=dict(type="str", choices=["attribute", "text"]),
|
||||
input_type=dict(type="str", default="yaml", choices=["xml", "yaml"]),
|
||||
backup=dict(type="bool", default=False),
|
||||
strip_cdata_tags=dict(type="bool", default=False),
|
||||
huge_tree=dict(type="bool", default=False),
|
||||
insertbefore=dict(type="bool", default=False),
|
||||
insertafter=dict(type="bool", default=False),
|
||||
create_if_missing=dict(type="bool", default=True),
|
||||
),
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True,
|
||||
required_by=dict(
|
||||
add_children=["xpath"],
|
||||
|
|
|
|||
|
|
@ -135,9 +135,12 @@ matches:
|
|||
returned: when parameter O(print_match) or O(content) is set
|
||||
"""
|
||||
|
||||
import copy
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils._xml import (
|
||||
COMMON_ARGUMENT_SPEC,
|
||||
check_lxml,
|
||||
collect_element_attr,
|
||||
collect_element_text,
|
||||
|
|
@ -149,18 +152,10 @@ from ansible_collections.community.general.plugins.module_utils._xml import (
|
|||
|
||||
|
||||
def main():
|
||||
argument_spec = copy.deepcopy(COMMON_ARGUMENT_SPEC)
|
||||
argument_spec["xpath"]["required"] = True
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
path=dict(type="path", aliases=["dest", "file"]),
|
||||
xmlstring=dict(type="str"),
|
||||
xpath=dict(type="str", required=True),
|
||||
namespaces=dict(type="dict", default={}),
|
||||
count=dict(type="bool", default=False),
|
||||
print_match=dict(type="bool", default=False),
|
||||
content=dict(type="str", choices=["attribute", "text"]),
|
||||
strip_cdata_tags=dict(type="bool", default=False),
|
||||
huge_tree=dict(type="bool", default=False),
|
||||
),
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True,
|
||||
required_one_of=[
|
||||
["path", "xmlstring"],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue