Conditional Module Parameter Help please.

12 views
Skip to first unread message

Joe Rosiak

unread,
Sep 13, 2019, 4:58:19 PM9/13/19
to Ansible Development
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?


Philip Douglass

unread,
Nov 22, 2019, 10:14:18 AM11/22/19
to Ansible Development
Try this:
    required_if = [
       
('action', 'add_package_to_content_view', ['packagename']),
   
]
   
module = AnsibleModule(argument_spec=argument_spec,
                           required_if
=required_if)
Reply all
Reply to author
Forward
0 new messages