mutually exclusive options

Need some advice on module syntax

I want to do this:

cl_interface name=br0 bridgemems=(list of bridge ports) ipv4=‘10.1.1.1/24’
cl_interface name=bond0 bondmems=(list of bond members) ipv4=‘10.2.2.2/24’

the bondmems and bridgemems keywords are mutually exclusive.

Question: Can AnsibleModule handle this mutual exclusive condition, like I can with ‘docopt’. With docopt I can say ‘cl_interface [(–bridgemems | --bondmems)] [–ipv4]’.

If not, I guess I have to code this logic and execute AnsibleModule.fail_json to warn the user.

Or, is it better to write

cl_bridge name=br0 bridgemems=(list of bridges ports) ipv4=2.2.2.2/24
cl_bond name=br0 bondmems=(list of bonds) ipv4=1.1.1.1/24

I do prefer to use just ‘cl_interface’ keyword, because I can cover all types of switch interfaces, i.e bond, bridges, loopbacks, and management ports with one module.

Thanks in advance for your help

Stanley K.

Yes, when specifying the module arguments, you can use the mutually_exclusive option to specify options that should not be used together. For instance, from the library/cloud/ec2 module:

mutually_exclusive = [
[‘exact_count’, ‘count’],
[‘exact_count’, ‘state’],
[‘exact_count’, ‘instance_ids’]
],

You can grep for “mutually_exclusive” in the library/ directory to see how other modules are using.