Conditional Module Parameter Help please.

Hi all,

I am attempting to create a custom module and when I am defining the custom parameters.

Example. I have this section defined and I only want to packagename required if someone passes “add_package_to_content_view” as an action.

`

fields = {
“organization”: {“required”: True, “type”: “str”},
“satelliteurl”: {“required”: True, “type”: “str”},
“cvname”: {“required”: True, “type”: “str”},
“action”: {“required”: True, “type”: “str”, “choices”: [“create_standard_content_view”,“create_custom_content_view”,“add_repo_to_content_view”,“add_package_to_content_view”]},
“packagename”: {“required”: False, “type”: “str”}
}

`

Is there a way to mark certain params as required in this above example or do I have to define the condition after everything is set?

Try this:
required_if = [ ('action', 'add_package_to_content_view', ['packagename']), ] module = AnsibleModule(argument_spec=argument_spec, required_if=required_if)