community.general/lib/ansible/modules/system
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
..
__init__.py package files 2016-12-08 11:22:22 -05:00
aix_devices.py new module: aix_devices, manage AIX devices (#32290) 2019-02-04 03:49:25 +01:00
aix_filesystem.py new module: Configure LVM and NFS file systems for AIX (#30810) 2019-01-05 02:18:12 +01:00
aix_inittab.py Fix parameter types and other fixes (#50111) 2019-01-18 03:24:47 +01:00
aix_lvg.py new module: AIX Volume Group creating, resizing, removing (#30381) 2019-02-04 03:30:10 +01:00
aix_lvol.py Fix parameter types and other fixes (#50111) 2019-01-18 03:24:47 +01:00
alternatives.py Fix parameter types and other fixes (#50111) 2019-01-18 03:24:47 +01:00
at.py Fix parameter types and other fixes (#50111) 2019-01-18 03:24:47 +01:00
authorized_key.py Fix parameter types and other fixes (#50111) 2019-01-18 03:24:47 +01:00
awall.py Fix parameter types and other fixes (#50111) 2019-01-18 03:24:47 +01:00
beadm.py Fix incorrect use of is for comparisons. 2019-02-12 16:33:13 -08:00
capabilities.py Fix parameter types and other fixes (#50111) 2019-01-18 03:24:47 +01:00
cron.py Introduce new 'required_by' argument_spec option (#28662) 2019-02-15 10:57:45 +10:00
cronvar.py Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
crypttab.py Ansible system module: sanity pep8 fixes (#32314) 2017-11-07 13:46:55 +01:00
dconf.py Use common functions for handling import errors (#51851) 2019-02-07 16:51:16 -05:00
debconf.py Update debconf example (#33397) 2017-11-30 18:07:11 +10:00
facter.py PEP8 fixes: Ansible system module and playbook base.py (#32322) 2017-11-07 09:38:59 +01:00
filesystem.py Extend functionality of filesystem module to support swap creation (#49456) 2018-12-04 12:01:29 +00:00
firewalld.py Introduce new 'required_by' argument_spec option (#28662) 2019-02-15 10:57:45 +10:00
gconftool2.py Convert to reduced list of known types (#50010) 2018-12-19 07:25:30 +10:00
getent.py getent: PEP8 compliancy and doc fixes (#30885) 2017-10-30 00:58:04 +01:00
group.py Fix parameter types and other fixes (#50111) 2019-01-18 03:24:47 +01:00
hostname.py add support for hostname on Raspbian (#51273) 2019-01-24 11:48:48 -05:00
interfaces_file.py Introduce new 'required_by' argument_spec option (#28662) 2019-02-15 10:57:45 +10:00
iptables.py E325 Removal - Part II (#49196) 2018-11-28 13:55:52 +05:30
java_cert.py java_cert: support of different keystore type (JKS, JCEKS) (#49953) 2019-02-07 10:45:28 -05:00
java_keystore.py Convert to reduced list of known types (#50010) 2018-12-19 07:25:30 +10:00
kernel_blacklist.py Fix invalid string escape sequences. 2017-11-21 20:59:08 -08:00
known_hosts.py Convert to reduced list of known types (#50010) 2018-12-19 07:25:30 +10:00
locale_gen.py correct message to have consistent pluralisation (#36897) 2018-11-26 13:45:38 -05:00
lvg.py Fix parameter types and other fixes (#50111) 2019-01-18 03:24:47 +01:00
lvol.py Documentation change for resizefs (#43224) 2018-07-25 00:22:24 +02:00
make.py Prefer to use gmake (if available) on non linux OS (#51294) 2019-01-26 15:28:55 +01:00
mksysb.py Convert to reduced list of known types (#50010) 2018-12-19 07:25:30 +10:00
modprobe.py Fix for the new 2.8 feature to have modprobe check for builtins. 2019-01-07 09:05:50 -08:00
mount.py Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
nosh.py Convert to reduced list of known types (#50010) 2018-12-19 07:25:30 +10:00
ohai.py Fix the docs link to Ohai in the Ohai module (#33788) 2018-03-08 17:00:17 -08:00
open_iscsi.py More validate module fixes (#39097) 2018-04-24 18:05:50 +01:00
openwrt_init.py Clean up module documentation (#36909) 2018-03-15 22:15:24 +01:00
osx_defaults.py Convert to reduced list of known types (#50010) 2018-12-19 07:25:30 +10:00
pam_limits.py Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
pamd.py Fix parameter types and other fixes (#50111) 2019-01-18 03:24:47 +01:00
parted.py Fix parameter types and other fixes (#50111) 2019-01-18 03:24:47 +01:00
ping.py Fix parameter types and other fixes (#50111) 2019-01-18 03:24:47 +01:00
puppet.py Add module parameter to control Puppet agent noop switch (#43678) 2018-12-04 12:30:19 +00:00
python_requirements_facts.py New module: Python Requirements Facts (#43108) 2018-08-21 09:19:10 +10:00
reboot.py Fix parameter types and other fixes (#50111) 2019-01-18 03:24:47 +01:00
runit.py Fixed spelling error in runit module (#35948) 2018-02-10 21:13:55 +05:30
seboolean.py Use common functions for handling import errors (#51851) 2019-02-07 16:51:16 -05:00
sefcontext.py Use common functions for handling import errors (#51851) 2019-02-07 16:51:16 -05:00
selinux.py Use common functions for handling import errors (#51851) 2019-02-07 16:51:16 -05:00
selinux_permissive.py Use common functions for handling import errors (#51851) 2019-02-07 16:51:16 -05:00
seport.py Use common functions for handling import errors (#51851) 2019-02-07 16:51:16 -05:00
service.py added docs for sleep/systemd interaction (#51336) 2019-01-29 15:19:29 -05:00
service_facts.py Provide both service state and status when possible in service_facts (#49618) 2018-12-26 13:24:03 +00:00
setup.py Validate DOCUMENTATION.author (#48993) 2018-11-21 17:29:29 +00:00
solaris_zone.py Clean up BOTMETA.yml (#44574) 2018-08-24 19:43:35 -04:00
svc.py Fix parameter types and other fixes (#50111) 2019-01-18 03:24:47 +01:00
sysctl.py Fixes the comment in the example of the sysctl module(#51547) 2019-02-12 14:30:21 +05:30
systemd.py Introduce new 'required_by' argument_spec option (#28662) 2019-02-15 10:57:45 +10:00
sysvinit.py Sysvinit - Enabling a service should use "defaults" if no runlevels are specified (#48724) 2018-11-15 09:53:10 -05:00
timezone.py Fix parameter types and other fixes (#50111) 2019-01-18 03:24:47 +01:00
ufw.py Introduce new 'required_by' argument_spec option (#28662) 2019-02-15 10:57:45 +10:00
user.py Use correct property name (#51511) 2019-01-30 17:26:23 -05:00
vdo.py Use common functions for handling import errors (#51851) 2019-02-07 16:51:16 -05:00
xfconf.py Convert to reduced list of known types (#50010) 2018-12-19 07:25:30 +10:00