diff --git a/changelogs/fragments/719-manageiq-resource_id.yml b/changelogs/fragments/719-manageiq-resource_id.yml new file mode 100644 index 0000000000..bbeef5ff82 --- /dev/null +++ b/changelogs/fragments/719-manageiq-resource_id.yml @@ -0,0 +1,2 @@ +minor_changes: + - manageiq_tags and manageiq_policies - added new parameter ``resource_id``. This parameter can be used instead of parameter ``resource_name`` (https://github.com/ansible-collections/community.general/pull/719). \ No newline at end of file diff --git a/plugins/modules/remote_management/manageiq/manageiq_policies.py b/plugins/modules/remote_management/manageiq/manageiq_policies.py index 600c0bfff6..8bbe05bc5e 100644 --- a/plugins/modules/remote_management/manageiq/manageiq_policies.py +++ b/plugins/modules/remote_management/manageiq/manageiq_policies.py @@ -37,7 +37,7 @@ options: resource_type: type: str description: - - the type of the resource to which the profile should be [un]assigned + - The type of the resource to which the profile should be [un]assigned. required: true choices: ['provider', 'host', 'vm', 'blueprint', 'category', 'cluster', 'data store', 'group', 'resource pool', 'service', 'service template', @@ -45,8 +45,14 @@ options: resource_name: type: str description: - - the name of the resource to which the profile should be [un]assigned - required: true + - The name of the resource to which the profile should be [un]assigned. + - Must be specified if I(resource_id) is not set. Both options are mutually exclusive. + resource_id: + type: int + description: + - The ID of the resource to which the profile should be [un]assigned. + - Must be specified if I(resource_name) is not set. Both options are mutually exclusive. + version_added: 2.2.0 ''' EXAMPLES = ''' @@ -296,7 +302,8 @@ def main(): actions = {'present': 'assign', 'absent': 'unassign', 'list': 'list'} argument_spec = dict( policy_profiles=dict(type='list'), - resource_name=dict(required=True, type='str'), + resource_id=dict(required=False, type='int'), + resource_name=dict(required=False, type='str'), resource_type=dict(required=True, type='str', choices=list(manageiq_entities().keys())), state=dict(required=False, type='str', @@ -307,6 +314,8 @@ def main(): module = AnsibleModule( argument_spec=argument_spec, + mutually_exclusive=[["resource_id", "resource_name"]], + required_one_of=[["resource_id", "resource_name"]], required_if=[ ('state', 'present', ['policy_profiles']), ('state', 'absent', ['policy_profiles']) @@ -314,6 +323,7 @@ def main(): ) policy_profiles = module.params['policy_profiles'] + resource_id = module.params['resource_id'] resource_type_key = module.params['resource_type'] resource_name = module.params['resource_name'] state = module.params['state'] @@ -325,7 +335,8 @@ def main(): manageiq = ManageIQ(module) # query resource id, fail if resource does not exist - resource_id = manageiq.find_collection_resource_or_fail(resource_type, name=resource_name)['id'] + if resource_id is None: + resource_id = manageiq.find_collection_resource_or_fail(resource_type, name=resource_name)['id'] manageiq_policies = ManageIQPolicies(manageiq, resource_type, resource_id) diff --git a/plugins/modules/remote_management/manageiq/manageiq_tags.py b/plugins/modules/remote_management/manageiq/manageiq_tags.py index 68de232499..d1fa900079 100644 --- a/plugins/modules/remote_management/manageiq/manageiq_tags.py +++ b/plugins/modules/remote_management/manageiq/manageiq_tags.py @@ -37,7 +37,7 @@ options: resource_type: type: str description: - - the relevant resource type in manageiq + - The relevant resource type in manageiq. required: true choices: ['provider', 'host', 'vm', 'blueprint', 'category', 'cluster', 'data store', 'group', 'resource pool', 'service', 'service template', @@ -45,8 +45,14 @@ options: resource_name: type: str description: - - the relevant resource name in manageiq - required: true + - The name of the resource at which tags will be controlled. + - Must be specified if I(resource_id) is not set. Both options are mutually exclusive. + resource_id: + description: + - The ID of the resource at which tags will be controlled. + - Must be specified if I(resource_name) is not set. Both options are mutually exclusive. + type: int + version_added: 2.2.0 ''' EXAMPLES = ''' @@ -65,6 +71,21 @@ EXAMPLES = ''' password: 'smartvm' validate_certs: False +- name: Create new tags for a provider in ManageIQ + community.general.manageiq_tags: + resource_id: 23000000790497 + resource_type: 'provider' + tags: + - category: environment + name: prod + - category: owner + name: prod_ops + manageiq_connection: + url: 'http://127.0.0.1:3000' + username: 'admin' + password: 'smartvm' + validate_certs: False + - name: Remove tags for a provider in ManageIQ community.general.manageiq_tags: state: absent @@ -241,7 +262,8 @@ def main(): actions = {'present': 'assign', 'absent': 'unassign', 'list': 'list'} argument_spec = dict( tags=dict(type='list'), - resource_name=dict(required=True, type='str'), + resource_id=dict(required=False, type='int'), + resource_name=dict(required=False, type='str'), resource_type=dict(required=True, type='str', choices=list(manageiq_entities().keys())), state=dict(required=False, type='str', @@ -252,6 +274,8 @@ def main(): module = AnsibleModule( argument_spec=argument_spec, + mutually_exclusive=[["resource_id", "resource_name"]], + required_one_of=[["resource_id", "resource_name"]], required_if=[ ('state', 'present', ['tags']), ('state', 'absent', ['tags']) @@ -259,6 +283,7 @@ def main(): ) tags = module.params['tags'] + resource_id = module.params['resource_id'] resource_type_key = module.params['resource_type'] resource_name = module.params['resource_name'] state = module.params['state'] @@ -270,7 +295,8 @@ def main(): manageiq = ManageIQ(module) # query resource id, fail if resource does not exist - resource_id = query_resource_id(manageiq, resource_type, resource_name) + if resource_id is None: + resource_id = query_resource_id(manageiq, resource_type, resource_name) manageiq_tags = ManageIQTags(manageiq, resource_type, resource_id)