|
|
@ -29,15 +29,17 @@ description:
|
|
|
|
options:
|
|
|
|
options:
|
|
|
|
state:
|
|
|
|
state:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- absent - tags should not exist, present - tags should be.
|
|
|
|
- absent - tags should not exist,
|
|
|
|
|
|
|
|
- present - tags should be,
|
|
|
|
|
|
|
|
- list - list current tags.
|
|
|
|
required: False
|
|
|
|
required: False
|
|
|
|
choices: ['absent', 'present']
|
|
|
|
choices: ['absent', 'present', 'list']
|
|
|
|
default: 'present'
|
|
|
|
default: 'present'
|
|
|
|
tags:
|
|
|
|
tags:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- tags - list of dictionaries, each includes 'name' and 'category' keys.
|
|
|
|
- tags - list of dictionaries, each includes 'name' and 'category' keys.
|
|
|
|
- categories - tag categories.
|
|
|
|
- required if state is present or absent.
|
|
|
|
required: true
|
|
|
|
required: false
|
|
|
|
default: null
|
|
|
|
default: null
|
|
|
|
resource_type:
|
|
|
|
resource_type:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
@ -85,6 +87,17 @@ EXAMPLES = '''
|
|
|
|
username: 'admin'
|
|
|
|
username: 'admin'
|
|
|
|
password: 'smartvm'
|
|
|
|
password: 'smartvm'
|
|
|
|
verify_ssl: False
|
|
|
|
verify_ssl: False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: List current tags for a provider in ManageIQ
|
|
|
|
|
|
|
|
manageiq_tags:
|
|
|
|
|
|
|
|
state: list
|
|
|
|
|
|
|
|
resource_name: 'EngLab'
|
|
|
|
|
|
|
|
resource_type: 'provider'
|
|
|
|
|
|
|
|
manageiq_connection:
|
|
|
|
|
|
|
|
url: 'http://127.0.0.1:3000'
|
|
|
|
|
|
|
|
username: 'admin'
|
|
|
|
|
|
|
|
password: 'smartvm'
|
|
|
|
|
|
|
|
verify_ssl: False
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
RETURN = '''
|
|
|
|
RETURN = '''
|
|
|
@ -205,19 +218,23 @@ class ManageIQTags(object):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
actions = {'present': 'assign', 'absent': 'unassign'}
|
|
|
|
actions = {'present': 'assign', 'absent': 'unassign', 'list': 'list'}
|
|
|
|
|
|
|
|
|
|
|
|
module = AnsibleModule(
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec=dict(
|
|
|
|
argument_spec=dict(
|
|
|
|
manageiq_connection=dict(required=True, type='dict',
|
|
|
|
manageiq_connection=dict(required=True, type='dict',
|
|
|
|
options=manageiq_argument_spec()),
|
|
|
|
options=manageiq_argument_spec()),
|
|
|
|
tags=dict(required=True, type='list'),
|
|
|
|
tags=dict(type='list'),
|
|
|
|
resource_name=dict(required=True, type='str'),
|
|
|
|
resource_name=dict(required=True, type='str'),
|
|
|
|
resource_type=dict(required=True, type='str',
|
|
|
|
resource_type=dict(required=True, type='str',
|
|
|
|
choices=manageiq_entities().keys()),
|
|
|
|
choices=manageiq_entities().keys()),
|
|
|
|
state=dict(required=False, type='str',
|
|
|
|
state=dict(required=False, type='str',
|
|
|
|
choices=['present', 'absent'], default='present'),
|
|
|
|
choices=['present', 'absent', 'list'], default='present'),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
|
|
|
|
required_if=[
|
|
|
|
|
|
|
|
('state', 'present', ['tags']),
|
|
|
|
|
|
|
|
('state', 'absent', ['tags'])
|
|
|
|
|
|
|
|
],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
tags = module.params['tags']
|
|
|
|
tags = module.params['tags']
|
|
|
@ -236,8 +253,13 @@ def main():
|
|
|
|
|
|
|
|
|
|
|
|
manageiq_tags = ManageIQTags(manageiq, resource_type, resource_id)
|
|
|
|
manageiq_tags = ManageIQTags(manageiq, resource_type, resource_id)
|
|
|
|
|
|
|
|
|
|
|
|
# assign or unassign the tags
|
|
|
|
if action == 'list':
|
|
|
|
res_args = manageiq_tags.assign_or_unassign_tags(tags, action)
|
|
|
|
# return a list of current tags for this object
|
|
|
|
|
|
|
|
current_tags = manageiq_tags.query_resource_tags()
|
|
|
|
|
|
|
|
res_args = dict(changed=False, tags=current_tags)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
# assign or unassign the tags
|
|
|
|
|
|
|
|
res_args = manageiq_tags.assign_or_unassign_tags(tags, action)
|
|
|
|
|
|
|
|
|
|
|
|
module.exit_json(**res_args)
|
|
|
|
module.exit_json(**res_args)
|
|
|
|
|
|
|
|
|
|
|
|