community.general/lib/ansible/modules/cloud
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
..
alicloud Fix incorrect use of is for comparisons. 2019-02-12 16:33:13 -08:00
amazon Introduce new 'required_by' argument_spec option (#28662) 2019-02-15 10:57:45 +10:00
atomic Convert to reduced list of known types (#50010) 2018-12-19 07:25:30 +10:00
azure Fix pycodestyle E117 issues. 2019-02-13 23:35:39 -08:00
centurylink Final round of moving modules to new import error msg (#51852) 2019-02-08 10:07:01 +10:00
cloudscale cloudscale: combine docs in fragment (#52069) 2019-02-13 13:52:01 -06:00
cloudstack Final round of moving modules to new import error msg (#51852) 2019-02-08 10:07:01 +10:00
digital_ocean fix debug msg in example (#51361) 2019-01-26 19:27:12 +00:00
dimensiondata Convert to reduced list of known types (#50010) 2018-12-19 07:25:30 +10:00
docker Also return some information in case the docker daemon does not run, is not in swarm mode or not a swarm manager. (#52189) 2019-02-13 16:49:45 -05:00
google Bug fixes for GCP modules (#51572) 2019-01-31 17:03:50 -05:00
heroku New module: heroku_collaborator (#39001) 2018-05-22 11:50:53 +02:00
kubevirt kubevirt: Add new kubevirt_vm module (#50768) 2019-02-13 10:17:01 +00:00
linode Final round of moving modules to new import error msg (#51852) 2019-02-08 10:07:01 +10:00
lxc Convert to reduced list of known types (#50010) 2018-12-19 07:25:30 +10:00
lxd Convert to reduced list of known types (#50010) 2018-12-19 07:25:30 +10:00
memset update github handle (#50235) 2018-12-21 23:59:37 +01:00
misc Fix incorrect use of is for comparisons. 2019-02-12 16:33:13 -08:00
oneandone E325 Removal - Part II (#49196) 2018-11-28 13:55:52 +05:30
online Add an Online servers fact 2018-09-24 21:03:50 +02:00
opennebula add range_start and range_end agrs when query vm by a single id (#50056) 2018-12-20 01:51:20 -05:00
openstack Introduce new 'required_by' argument_spec option (#28662) 2019-02-15 10:57:45 +10:00
ovh Fixed typo from adress to address (#52143) 2019-02-13 13:57:13 +05:30
ovirt Ovirt vm state running wait false (#51024) 2019-02-04 14:52:37 +00:00
packet E325 Removal - Part II (#49196) 2018-11-28 13:55:52 +05:30
profitbricks Bulk fix DOCUMENTATION.author (Part 1) (#48934) 2018-11-20 19:31:35 +00:00
pubnub E325 Removal - Part II (#49196) 2018-11-28 13:55:52 +05:30
rackspace Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
scaleway Add a description of the description attribute 2019-02-11 11:58:44 -08:00
smartos New Module for SmartOS: nictagadm (#35919) 2019-01-23 04:57:46 +01:00
softlayer Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
spotinst Spotinst - adding support for instance health check validation (#49211) 2019-01-18 20:30:03 +00:00
univention Fix GitHub handle, use keachi (#50043) 2018-12-17 19:35:49 +00:00
vmware Fix pycodestyle E117 issues. 2019-02-13 23:35:39 -08:00
vultr Fix pycodestyle E117 issues. 2019-02-13 23:35:39 -08:00
webfaction Convert more http links to https. 2018-04-25 23:12:46 -07:00
xenserver New module: xenserver_guest_facts - returns facts of XenServer VMs (#49426) 2019-02-12 16:56:49 +05:30
__init__.py package files 2016-12-08 11:22:22 -05:00