1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/lib/ansible/module_utils
Dag Wieers cd9471ef17 Introduce new 'required_by' argument_spec option (#28662)
* Introduce new "required_by' argument_spec option

This PR introduces a new **required_by** argument_spec option which allows you to say *"if parameter A is set, parameter B and C are required as well"*.

- The difference with **required_if** is that it can only add dependencies if a parameter is set to a specific value, not when it is just defined.
- The difference with **required_together** is that it has a commutative property, so: *"Parameter A and B are required together, if one of them has been defined"*.

As an example, we need this for the complex options that the xml module provides. One of the issues we often see is that users are not using the correct combination of options, and then are surprised that the module does not perform the requested action(s).

This would be solved by adding the correct dependencies, and mutual exclusives. For us this is important to get this shipped together with the new xml module in Ansible v2.4. (This is related to bugfix https://github.com/ansible/ansible/pull/28657)

```python
    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'),
            set_children=dict(type='list'),
            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),
        ),
        supports_check_mode=True,
        required_by=dict(
            add_children=['xpath'],
            attribute=['value', 'xpath'],
            content=['xpath'],
            set_children=['xpath'],
            value=['xpath'],
        ),
        required_if=[
            ['count', True, ['xpath']],
            ['print_match', True, ['xpath']],
        ],
        required_one_of=[
            ['path', 'xmlstring'],
            ['add_children', 'content', 'count', 'pretty_print', 'print_match', 'set_children', 'value'],
        ],
        mutually_exclusive=[
            ['add_children', 'content', 'count', 'print_match','set_children', 'value'],
            ['path', 'xmlstring'],
        ],
    )
```

* Rebase and fix conflict

* Add modules that use required_by functionality

* Update required_by schema

* Fix rebase issue
2019-02-15 10:57:45 +10:00
..
aws Fix incorrect use of is for comparisons. 2019-02-12 16:33:13 -08:00
common Fix pycodestyle E117 issues. 2019-02-13 23:35:39 -08:00
compat Have update-bundled check for updates to all bundled code 2019-02-06 13:59:55 -08:00
csharp Ansible.Basic: make module options case insensitive with dep warning (#51583) 2019-02-13 21:55:43 -05:00
distro Changes to bundled distro to be Python-2.6 compatible 2018-12-17 11:01:01 -08:00
docker docker_*: always use client.fail() over module.fail_json(), allow to always return data on failure (#51999) 2019-02-13 14:10:23 -05:00
facts Fix pycodestyle E117 issues. 2019-02-13 23:35:39 -08:00
k8s k8s handle absent resources when waiting (#51682) 2019-02-11 21:43:42 +01:00
net_tools Fixes issue where uppercase named A_Record delete was getting skipped (#51539) 2019-01-31 21:02:46 +05:30
network Fix pycodestyle E117 issues. 2019-02-13 23:35:39 -08:00
parsing Improve convert_bool error message 2018-02-12 13:05:38 -05:00
powershell Windows Privileges - moved util code to it's own C# util (#48897) 2018-12-14 12:00:46 +10:00
remote_management Use common functions for handling import errors (#51851) 2019-02-07 16:51:16 -05:00
six Have update-bundled check for updates to all bundled code 2019-02-06 13:59:55 -08:00
storage New module for managing EMC VNX Block storage (#42945) 2018-08-09 10:38:26 -07:00
__init__.py Enhance empty __init__ code-smell to check module_utils (#33438) 2017-11-30 15:47:38 -08:00
_text.py Fix for to_text and to_bytes error handlers 2017-07-24 09:19:04 -07:00
acme.py ACME: add seealso references (#50320) 2018-12-26 13:26:46 +00:00
alicloud_ecs.py Add new module ali_instance (#36898) 2018-10-23 13:02:21 -05:00
ansible_release.py [AWS] Add Ansible Version to botocore user agent string (#39993) 2018-05-17 11:41:14 -04:00
ansible_tower.py tower modules: check that 'verify_ssl' defined in ~/.tower_cli.cfg isn't ignored (#50687) 2019-02-13 10:26:43 +00:00
api.py Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
azure_rm_common.py Fix pycodestyle E117 issues. 2019-02-13 23:35:39 -08:00
azure_rm_common_rest.py support lro in azure_rm_resource (#49919) 2018-12-17 13:21:25 +08:00
basic.py Introduce new 'required_by' argument_spec option (#28662) 2019-02-15 10:57:45 +10:00
cloud.py AWSRetry: allow retrying on additional ClientError exceptions (#28483) 2017-08-22 15:31:20 -04:00
cloudscale.py Cloudscale volume (#49887) 2019-01-07 22:29:01 +01:00
cloudstack.py cloudstack: ensure return api_timeout is int (#52191) 2019-02-13 23:11:22 +01:00
connection.py Allow AnsibleVaultEncryptedUnicode to pass through exec_jsonrpc (#48306) 2018-12-21 11:15:18 -05:00
crypto.py Relative time support for crypto modules (openssl_certificate) (#50570) 2019-01-22 20:41:02 +00:00
database.py Surround top-level function and class definitions with two blank lines. 2018-07-31 12:06:56 -07:00
digital_ocean.py Include Digital Ocean Token Alias (#36810) 2018-03-01 09:56:53 +05:30
dimensiondata.py Final round of moving modules to new import error msg (#51852) 2019-02-08 10:07:01 +10:00
ec2.py Final round of moving modules to new import error msg (#51852) 2019-02-08 10:07:01 +10:00
exoscale.py exo_dns_record: remove limitation for multiple records only for A type (#35173) 2018-02-05 22:40:02 +01:00
f5_utils.py Refactor common network shared and platform utils code into package (#33452) 2017-12-03 21:42:30 +05:30
firewalld.py refactor firewalld module, add firewalld module_util (#37603) 2018-04-30 15:33:28 -05:00
gcdns.py Collated PEP8 fixes (#25293) 2017-06-02 12:14:11 +01:00
gce.py Collated PEP8 fixes (#25293) 2017-06-02 12:14:11 +01:00
gcp.py removing libcloud secrets support for legacy gcp modules (#44932) 2018-08-31 08:28:32 -04:00
gcp_utils.py Fix gcp utils dict replace (#51426) 2019-01-29 15:52:31 -05:00
gitlab.py copyright: edit deprecated email (#51912) 2019-02-08 01:48:25 +01:00
heroku.py Final round of moving modules to new import error msg (#51852) 2019-02-08 10:07:01 +10:00
ibm_sa_utils.py Final round of moving modules to new import error msg (#51852) 2019-02-08 10:07:01 +10:00
infinibox.py Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
influxdb.py start getting modules to use shared import error code (#51787) 2019-02-06 12:39:17 -05:00
ipa.py identity: Add GSSAPI suport for FreeIPA authentication (#52031) 2019-02-13 15:38:13 +00:00
ismount.py fix typo 2016-02-08 19:10:04 +01:00
json_utils.py Remove use of simplejson throughout code base (#43548) 2018-08-10 11:13:29 -05:00
keycloak.py New module: keycloak_clienttemplate (#33419) 2018-01-31 13:12:53 +00:00
known_hosts.py Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
kubevirt.py kubevirt: Add new kubevirt_vm module (#50768) 2019-02-13 10:17:01 +00:00
ldap.py doc: fix maintainer's name (#44452) 2018-08-21 16:32:37 +02:00
linode.py Add new linode_v4 module. (#46151) 2018-11-16 12:39:05 +00:00
lxd.py Remove use of simplejson throughout code base (#43548) 2018-08-10 11:13:29 -05:00
manageiq.py Use common functions for handling import errors (#51851) 2019-02-07 16:51:16 -05:00
memset.py New facts module: Memset Memstore (#42387) 2018-10-29 12:27:03 +00:00
mysql.py Migrate from MySQLdb to PyMySQL (#40123) 2018-09-19 08:44:05 -07:00
netapp.py Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
netapp_elementsw_module.py Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
netapp_module.py New Options for Autosupport (#50773) 2019-01-23 18:18:07 +00:00
oneandone.py New module: manage 1&1 public ip (cloud/oneandone/oneandone_public_ip) (#35079) 2018-02-07 12:15:27 -06:00
oneview.py Use common functions for handling import errors (#51851) 2019-02-07 16:51:16 -05:00
online.py Add an Online servers fact 2018-09-24 21:03:50 +02:00
opennebula.py one_host environment variables, Fixes #44163 (#44568) 2018-08-27 10:55:04 -04:00
openstack.py openstack: fix parameter handling when cloud provided as dict (#42899) 2018-12-10 11:41:22 +00:00
ovirt.py Ovirt vm state running wait false (#51024) 2019-02-04 14:52:37 +00:00
postgres.py Remove wildcard imports and get_exception calls 2017-08-12 00:48:53 -07:00
pure.py Add user_agent into FlashBlade API calls (#46221) 2018-10-29 11:28:00 +00:00
pycompat24.py Enable pylint rules and fix exposed bugs. (#47219) 2018-10-19 08:32:52 -07:00
rabbitmq.py start getting modules to use shared import error code (#51787) 2019-02-06 12:39:17 -05:00
rax.py Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
redfish_utils.py Update GetBiosBootOrder to use standard spec resources (#51764) 2019-02-11 14:50:10 +00:00
redhat.py Miscellaneous pylint fixes. 2017-09-13 01:53:08 -07:00
scaleway.py Add a Scaleway load-balancer module (#51741) 2019-02-11 15:28:55 +00:00
service.py Fix typo of stderr 2018-07-31 13:23:05 -04:00
splitter.py Collated PEP8 fixes (#25293) 2017-06-02 12:14:11 +01:00
univention_umc.py Python 2.6 str.format() compatibility fixes. 2018-01-10 14:08:11 -08:00
urls.py identity: Add GSSAPI suport for FreeIPA authentication (#52031) 2019-02-13 15:38:13 +00:00
utm_utils.py Add optional headers to utm modules (#49856) 2019-01-17 19:06:50 +05:30
vca.py Final round of moving modules to new import error msg (#51852) 2019-02-08 10:07:01 +10:00
vmware.py Final round of moving modules to new import error msg (#51852) 2019-02-08 10:07:01 +10:00
vmware_rest_client.py VMware: Tag management to VMware object (#46945) 2019-02-12 16:53:33 +05:30
vultr.py vultr: fix for API returned unexpected empty list (#48036) 2018-11-04 11:23:36 +01:00
xenserver.py New module: xenserver_guest - manages XenServer VMs (#41041) 2018-11-19 01:50:20 -05:00
yumdnf.py dnf/yum - added install_weak_deps option (#50525) 2019-01-04 11:37:59 -05:00