Ansible Custom Module: How to implement conditional parameter?

144 Views Asked by At

I want to create a Custom Module call API which will take

  • action: get or search
  • resource: car/truck/plane/ship
  • optional parameters - dynamic parameter based on action and resource

For example if action is get and resource is car, then I want to add wheels, doors as module parameter.

module_args = {
        'action': {'required': True, 'type': 'str', choice:['get','search']},
        'resource': {'required': True, 'type': 'str', choice: ['car', 'truck', 'ship']},
         }

module = AnsibleModule(argument_spec=module_args,
         required_if('resource', 'car', ('wheels', 'doors'))
         supports_check_mode=True
         )

Is there a way to put required_if on two options i.e if action == 'search' and resource =='car' then use different set of arguments?

0

There are 0 best solutions below