mirror of
https://github.com/ansible/awx.git
synced 2026-02-25 15:06:02 -03:30
get_one now also returns the name field, and modifying modules for get_one and added in some IDs in a handful of unit tests
This commit is contained in:
@@ -141,18 +141,18 @@ class TowerAPIModule(TowerModule):
|
|||||||
self.fail_json(msg="The endpoint did not provide count and results")
|
self.fail_json(msg="The endpoint did not provide count and results")
|
||||||
|
|
||||||
if response['json']['count'] == 0:
|
if response['json']['count'] == 0:
|
||||||
return None
|
return None, name_or_id
|
||||||
elif response['json']['count'] > 1:
|
elif response['json']['count'] > 1:
|
||||||
if name_or_id:
|
if name_or_id:
|
||||||
# Since we did a name or ID search and got > 1 return something if the id matches
|
# Since we did a name or ID search and got > 1 return something if the id matches
|
||||||
for asset in response['json']['results']:
|
for asset in response['json']['results']:
|
||||||
if asset['id'] == name_or_id:
|
if asset['id'] == name_or_id:
|
||||||
return asset
|
return asset, asset['id'][name_field]
|
||||||
# We got > 1 and either didn't find something by ID (which means multiple names)
|
# We got > 1 and either didn't find something by ID (which means multiple names)
|
||||||
# Or we weren't running with a or search and just got back too many to begin with.
|
# Or we weren't running with a or search and just got back too many to begin with.
|
||||||
self.fail_json(msg="An unexpected number of items was returned from the API ({0})".format(response['json']['count']))
|
self.fail_json(msg="An unexpected number of items was returned from the API ({0})".format(response['json']['count']))
|
||||||
|
|
||||||
return response['json']['results'][0]
|
return response['json']['results'][0], response['json']['results'][0][name_field]
|
||||||
|
|
||||||
def get_one_by_name_or_id(self, endpoint, name_or_id):
|
def get_one_by_name_or_id(self, endpoint, name_or_id):
|
||||||
name_field = self.get_name_field_from_endpoint(endpoint)
|
name_field = self.get_name_field_from_endpoint(endpoint)
|
||||||
|
|||||||
@@ -370,9 +370,7 @@ def main():
|
|||||||
if organization:
|
if organization:
|
||||||
lookup_data['organization'] = org_id
|
lookup_data['organization'] = org_id
|
||||||
|
|
||||||
credential = module.get_one('credentials', name_or_id=name, **{'data': lookup_data})
|
credential, name = module.get_one('credentials', name_or_id=name, **{'data': lookup_data})
|
||||||
# If we got an item back make sure the name field reflects the actual name (incase we were passed an ID)
|
|
||||||
name = credential['name'] if (credential) else name
|
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ def main():
|
|||||||
'target_credential': target_credential_id,
|
'target_credential': target_credential_id,
|
||||||
'input_field_name': input_field_name,
|
'input_field_name': input_field_name,
|
||||||
}
|
}
|
||||||
credential_input_source = module.get_one('credential_input_sources', **{'data': lookup_data})
|
credential_input_source, junk = module.get_one('credential_input_sources', **{'data': lookup_data})
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
module.delete_if_needed(credential_input_source)
|
module.delete_if_needed(credential_input_source)
|
||||||
|
|||||||
@@ -128,11 +128,7 @@ def main():
|
|||||||
credential_type_params['injectors'] = module.params.get('injectors')
|
credential_type_params['injectors'] = module.params.get('injectors')
|
||||||
|
|
||||||
# Attempt to look up credential_type based on the provided name
|
# Attempt to look up credential_type based on the provided name
|
||||||
credential_type = module.get_one('credential_types', **{
|
credential_type, name = module.get_one('credential_types', name_or_id=name)
|
||||||
'data': {
|
|
||||||
'name': name,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
||||||
|
|||||||
@@ -108,9 +108,8 @@ def main():
|
|||||||
inventory_id = module.resolve_name_to_id('inventories', inventory)
|
inventory_id = module.resolve_name_to_id('inventories', inventory)
|
||||||
|
|
||||||
# Attempt to look up the object based on the provided name and inventory ID
|
# Attempt to look up the object based on the provided name and inventory ID
|
||||||
group = module.get_one('groups', **{
|
group, name = module.get_one('groups', name_or_id=name, **{
|
||||||
'data': {
|
'data': {
|
||||||
'name': name,
|
|
||||||
'inventory': inventory_id
|
'inventory': inventory_id
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -136,8 +135,8 @@ def main():
|
|||||||
continue
|
continue
|
||||||
id_list = []
|
id_list = []
|
||||||
for sub_name in name_list:
|
for sub_name in name_list:
|
||||||
sub_obj = module.get_one(resource, **{
|
sub_obj, sub_name = module.get_one(resource, name_or_id=sub_name, **{
|
||||||
'data': {'inventory': inventory_id, 'name': sub_name}
|
'data': {'inventory': inventory_id},
|
||||||
})
|
})
|
||||||
if sub_obj is None:
|
if sub_obj is None:
|
||||||
module.fail_json(msg='Could not find {0} with name {1}'.format(resource, sub_name))
|
module.fail_json(msg='Could not find {0} with name {1}'.format(resource, sub_name))
|
||||||
|
|||||||
@@ -104,9 +104,8 @@ def main():
|
|||||||
inventory_id = module.resolve_name_to_id('inventories', inventory)
|
inventory_id = module.resolve_name_to_id('inventories', inventory)
|
||||||
|
|
||||||
# Attempt to look up host based on the provided name and inventory ID
|
# Attempt to look up host based on the provided name and inventory ID
|
||||||
host = module.get_one('hosts', **{
|
host, name = module.get_one('hosts', name_or_id=name, **{
|
||||||
'data': {
|
'data': {
|
||||||
'name': name,
|
|
||||||
'inventory': inventory_id
|
'inventory': inventory_id
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -109,11 +109,7 @@ def main():
|
|||||||
state = module.params.get('state')
|
state = module.params.get('state')
|
||||||
|
|
||||||
# Attempt to look up an existing item based on the provided data
|
# Attempt to look up an existing item based on the provided data
|
||||||
existing_item = module.get_one('instance_groups', **{
|
existing_item, name = module.get_one('instance_groups', name_or_id=name)
|
||||||
'data': {
|
|
||||||
'name': name,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if state is 'absent':
|
if state is 'absent':
|
||||||
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
||||||
|
|||||||
@@ -109,9 +109,8 @@ def main():
|
|||||||
org_id = module.resolve_name_to_id('organizations', organization)
|
org_id = module.resolve_name_to_id('organizations', organization)
|
||||||
|
|
||||||
# Attempt to look up inventory based on the provided name and org ID
|
# Attempt to look up inventory based on the provided name and org ID
|
||||||
inventory = module.get_one('inventories', **{
|
inventory, name = module.get_one('inventories', name_or_id=name, **{
|
||||||
'data': {
|
'data': {
|
||||||
'name': name,
|
|
||||||
'organization': org_id
|
'organization': org_id
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -202,17 +202,17 @@ def main():
|
|||||||
source_project = module.params.get('source_project')
|
source_project = module.params.get('source_project')
|
||||||
state = module.params.get('state')
|
state = module.params.get('state')
|
||||||
|
|
||||||
lookup_data = {'name': inventory}
|
<<<<<<< HEAD
|
||||||
|
lookup_data = {}
|
||||||
if organization:
|
if organization:
|
||||||
lookup_data['organization'] = module.resolve_name_to_id('organizations', organization)
|
lookup_data['organization'] = module.resolve_name_to_id('organizations', organization)
|
||||||
inventory_object = module.get_one('inventories', data=lookup_data)
|
inventory_object = module.get_one('inventories', name_or_id=inventory, data=lookup_data)
|
||||||
|
|
||||||
if not inventory_object:
|
if not inventory_object:
|
||||||
module.fail_json(msg='The specified inventory, {0}, was not found.'.format(lookup_data))
|
module.fail_json(msg='The specified inventory, {0}, was not found.'.format(lookup_data))
|
||||||
|
|
||||||
inventory_source_object = module.get_one('inventory_sources', **{
|
inventory_source_object = module.get_one('inventory_sources', name_or_id=name, **{
|
||||||
'data': {
|
'data': {
|
||||||
'name': name,
|
|
||||||
'inventory': inventory_object['id'],
|
'inventory': inventory_object['id'],
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ def main():
|
|||||||
fail_if_not_running = module.params.get('fail_if_not_running')
|
fail_if_not_running = module.params.get('fail_if_not_running')
|
||||||
|
|
||||||
# Attempt to look up the job based on the provided name
|
# Attempt to look up the job based on the provided name
|
||||||
job = module.get_one('jobs', **{
|
job, job_name = module.get_one('jobs', **{
|
||||||
'data': {
|
'data': {
|
||||||
'id': job_id,
|
'id': job_id,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -201,11 +201,7 @@ def main():
|
|||||||
post_data['credentials'].append(module.resolve_name_to_id('credentials', credential))
|
post_data['credentials'].append(module.resolve_name_to_id('credentials', credential))
|
||||||
|
|
||||||
# Attempt to look up job_template based on the provided name
|
# Attempt to look up job_template based on the provided name
|
||||||
job_template = module.get_one('job_templates', **{
|
job_template, name = module.get_one('job_templates', name_or_id=name)
|
||||||
'data': {
|
|
||||||
'name': name,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if job_template is None:
|
if job_template is None:
|
||||||
module.fail_json(msg="Unable to find job template by name {0}".format(name))
|
module.fail_json(msg="Unable to find job template by name {0}".format(name))
|
||||||
|
|||||||
@@ -409,7 +409,7 @@ def main():
|
|||||||
credentials.append(credential)
|
credentials.append(credential)
|
||||||
|
|
||||||
new_fields = {}
|
new_fields = {}
|
||||||
search_fields = {'name': name}
|
search_fields = {}
|
||||||
|
|
||||||
# Attempt to look up the related items the user specified (these will fail the module if not found)
|
# Attempt to look up the related items the user specified (these will fail the module if not found)
|
||||||
organization_id = None
|
organization_id = None
|
||||||
@@ -419,7 +419,7 @@ def main():
|
|||||||
search_fields['organization'] = new_fields['organization'] = organization_id
|
search_fields['organization'] = new_fields['organization'] = organization_id
|
||||||
|
|
||||||
# Attempt to look up an existing item based on the provided data
|
# Attempt to look up an existing item based on the provided data
|
||||||
existing_item = module.get_one('job_templates', **{'data': search_fields})
|
existing_item, name = module.get_one('job_templates', name_or_id=name, **{'data': search_fields})
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
||||||
@@ -453,9 +453,8 @@ def main():
|
|||||||
new_fields['inventory'] = module.resolve_name_to_id('inventories', inventory)
|
new_fields['inventory'] = module.resolve_name_to_id('inventories', inventory)
|
||||||
if project is not None:
|
if project is not None:
|
||||||
if organization_id is not None:
|
if organization_id is not None:
|
||||||
project_data = module.get_one('projects', **{
|
project_data, project = module.get_one('projects', name_or_id=project, **{
|
||||||
'data': {
|
'data': {
|
||||||
'name': project,
|
|
||||||
'organization': organization_id,
|
'organization': organization_id,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ def main():
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Attempt to look up job based on the provided id
|
# Attempt to look up job based on the provided id
|
||||||
job = module.get_one('jobs', **{
|
job, junk = module.get_one('jobs', **{
|
||||||
'data': {
|
'data': {
|
||||||
'id': job_id,
|
'id': job_id,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,9 +80,8 @@ def main():
|
|||||||
organization_id = module.resolve_name_to_id('organizations', organization)
|
organization_id = module.resolve_name_to_id('organizations', organization)
|
||||||
|
|
||||||
# Attempt to look up an existing item based on the provided data
|
# Attempt to look up an existing item based on the provided data
|
||||||
existing_item = module.get_one('labels', **{
|
existing_item, name = module.get_one('labels', name_or_id=name, **{
|
||||||
'data': {
|
'data': {
|
||||||
'name': name,
|
|
||||||
'organization': organization_id,
|
'organization': organization_id,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -380,9 +380,8 @@ def main():
|
|||||||
organization_id = module.resolve_name_to_id('organizations', organization)
|
organization_id = module.resolve_name_to_id('organizations', organization)
|
||||||
|
|
||||||
# Attempt to look up an existing item based on the provided data
|
# Attempt to look up an existing item based on the provided data
|
||||||
existing_item = module.get_one('notification_templates', **{
|
existing_item, name = module.get_one('notification_templates', name_or_id=name, **{
|
||||||
'data': {
|
'data': {
|
||||||
'name': name,
|
|
||||||
'organization': organization_id,
|
'organization': organization_id,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -117,11 +117,7 @@ def main():
|
|||||||
state = module.params.get('state')
|
state = module.params.get('state')
|
||||||
|
|
||||||
# Attempt to look up organization based on the provided name
|
# Attempt to look up organization based on the provided name
|
||||||
organization = module.get_one('organizations', **{
|
organization, name = module.get_one('organizations', name_or_id=name)
|
||||||
'data': {
|
|
||||||
'name': name,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
||||||
|
|||||||
@@ -239,9 +239,8 @@ def main():
|
|||||||
credential = module.resolve_name_to_id('credentials', credential)
|
credential = module.resolve_name_to_id('credentials', credential)
|
||||||
|
|
||||||
# Attempt to look up project based on the provided name and org ID
|
# Attempt to look up project based on the provided name and org ID
|
||||||
project = module.get_one('projects', **{
|
project, name = module.get_one('projects', name_or_id=name, **{
|
||||||
'data': {
|
'data': {
|
||||||
'name': name,
|
|
||||||
'organization': org_id
|
'organization': org_id
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -109,10 +109,10 @@ def main():
|
|||||||
module.fail_json(msg='Could not find Project with ID: {0}'.format(name))
|
module.fail_json(msg='Could not find Project with ID: {0}'.format(name))
|
||||||
project = results['json']['results'][0]
|
project = results['json']['results'][0]
|
||||||
else:
|
else:
|
||||||
lookup_data = {'name': name}
|
lookup_data = {}
|
||||||
if organization:
|
if organization:
|
||||||
lookup_data['organization'] = module.resolve_name_to_id('organizations', organization)
|
lookup_data['organization'] = module.resolve_name_to_id('organizations', organization)
|
||||||
project = module.get_one('projects', data=lookup_data)
|
project, name = module.get_one('projects', name_or_id=name, data=lookup_data)
|
||||||
if project is None:
|
if project is None:
|
||||||
module.fail_json(msg="Unable to find project")
|
module.fail_json(msg="Unable to find project")
|
||||||
|
|
||||||
|
|||||||
@@ -190,11 +190,7 @@ def main():
|
|||||||
unified_job_template_id = module.resolve_name_to_id('unified_job_templates', unified_job_template)
|
unified_job_template_id = module.resolve_name_to_id('unified_job_templates', unified_job_template)
|
||||||
|
|
||||||
# Attempt to look up an existing item based on the provided data
|
# Attempt to look up an existing item based on the provided data
|
||||||
existing_item = module.get_one('schedules', **{
|
existing_item, name = module.get_one('schedules', name_or_id=name)
|
||||||
'data': {
|
|
||||||
'name': name,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
# Create the data that gets sent for create and update
|
# Create the data that gets sent for create and update
|
||||||
new_fields = {}
|
new_fields = {}
|
||||||
|
|||||||
@@ -87,9 +87,8 @@ def main():
|
|||||||
org_id = module.resolve_name_to_id('organizations', organization)
|
org_id = module.resolve_name_to_id('organizations', organization)
|
||||||
|
|
||||||
# Attempt to look up team based on the provided name and org ID
|
# Attempt to look up team based on the provided name and org ID
|
||||||
team = module.get_one('teams', **{
|
team, name = module.get_one('teams', name_or_id=name, **{
|
||||||
'data': {
|
'data': {
|
||||||
'name': name,
|
|
||||||
'organization': org_id
|
'organization': org_id
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ def main():
|
|||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
if not existing_token:
|
if not existing_token:
|
||||||
existing_token = module.get_one('tokens', **{
|
existing_token, token_name = module.get_one('tokens', **{
|
||||||
'data': {
|
'data': {
|
||||||
'id': existing_token_id,
|
'id': existing_token_id,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,9 +134,7 @@ def main():
|
|||||||
# Attempt to look up the related items the user specified (these will fail the module if not found)
|
# Attempt to look up the related items the user specified (these will fail the module if not found)
|
||||||
|
|
||||||
# Attempt to look up an existing item based on the provided data
|
# Attempt to look up an existing item based on the provided data
|
||||||
existing_item = module.get_one('users', name_or_id=username)
|
existing_item, username = module.get_one('users', name_or_id=username)
|
||||||
# If we got an item back make sure the name field reflects the actual name (incase we were passed an ID)
|
|
||||||
username = existing_item['username'] if (existing_item) else username
|
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ def main():
|
|||||||
state = module.params.get('state')
|
state = module.params.get('state')
|
||||||
|
|
||||||
new_fields = {}
|
new_fields = {}
|
||||||
search_fields = {'name': name}
|
search_fields = {}
|
||||||
|
|
||||||
# Attempt to look up the related items the user specified (these will fail the module if not found)
|
# Attempt to look up the related items the user specified (these will fail the module if not found)
|
||||||
organization = module.params.get('organization')
|
organization = module.params.get('organization')
|
||||||
@@ -193,7 +193,7 @@ def main():
|
|||||||
search_fields['organization'] = new_fields['organization'] = organization_id
|
search_fields['organization'] = new_fields['organization'] = organization_id
|
||||||
|
|
||||||
# Attempt to look up an existing item based on the provided data
|
# Attempt to look up an existing item based on the provided data
|
||||||
existing_item = module.get_one('workflow_job_templates', **{'data': search_fields})
|
existing_item, name = module.get_one('workflow_job_templates', name_or_id=name, **{'data': search_fields})
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
||||||
|
|||||||
@@ -198,12 +198,14 @@ def main():
|
|||||||
workflow_job_template = module.params.get('workflow_job_template')
|
workflow_job_template = module.params.get('workflow_job_template')
|
||||||
workflow_job_template_id = None
|
workflow_job_template_id = None
|
||||||
if workflow_job_template:
|
if workflow_job_template:
|
||||||
wfjt_search_fields = {'name': workflow_job_template}
|
wfjt_search_fields = {}
|
||||||
organization = module.params.get('organization')
|
organization = module.params.get('organization')
|
||||||
if organization:
|
if organization:
|
||||||
organization_id = module.resolve_name_to_id('organizations', organization)
|
organization_id = module.resolve_name_to_id('organizations', organization)
|
||||||
wfjt_search_fields['organization'] = organization_id
|
wfjt_search_fields['organization'] = organization_id
|
||||||
wfjt_data = module.get_one('workflow_job_templates', **{'data': wfjt_search_fields})
|
wfjt_data, workflow_job_template = module.get_one('workflow_job_templates', name_or_id=workflow_job_template, **{
|
||||||
|
'data': wfjt_search_fields
|
||||||
|
})
|
||||||
if wfjt_data is None:
|
if wfjt_data is None:
|
||||||
module.fail_json(msg="The workflow {0} in organization {1} was not found on the Tower server".format(
|
module.fail_json(msg="The workflow {0} in organization {1} was not found on the Tower server".format(
|
||||||
workflow_job_template, organization
|
workflow_job_template, organization
|
||||||
@@ -212,7 +214,7 @@ def main():
|
|||||||
search_fields['workflow_job_template'] = new_fields['workflow_job_template'] = workflow_job_template_id
|
search_fields['workflow_job_template'] = new_fields['workflow_job_template'] = workflow_job_template_id
|
||||||
|
|
||||||
# Attempt to look up an existing item based on the provided data
|
# Attempt to look up an existing item based on the provided data
|
||||||
existing_item = module.get_one('workflow_job_template_nodes', **{'data': search_fields})
|
existing_item, junk = module.get_one('workflow_job_template_nodes', **{'data': search_fields})
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
||||||
@@ -249,7 +251,7 @@ def main():
|
|||||||
lookup_data = {'identifier': sub_name}
|
lookup_data = {'identifier': sub_name}
|
||||||
if workflow_job_template_id:
|
if workflow_job_template_id:
|
||||||
lookup_data['workflow_job_template'] = workflow_job_template_id
|
lookup_data['workflow_job_template'] = workflow_job_template_id
|
||||||
sub_obj = module.get_one(endpoint, **{'data': lookup_data})
|
sub_obj, junk = module.get_one(endpoint, **{'data': lookup_data})
|
||||||
if sub_obj is None:
|
if sub_obj is None:
|
||||||
module.fail_json(msg='Could not find {0} entry with name {1}'.format(association, sub_name))
|
module.fail_json(msg='Could not find {0} entry with name {1}'.format(association, sub_name))
|
||||||
id_list.append(sub_obj['id'])
|
id_list.append(sub_obj['id'])
|
||||||
|
|||||||
@@ -138,10 +138,10 @@ def main():
|
|||||||
post_data['inventory'] = module.resolve_name_to_id('inventories', inventory)
|
post_data['inventory'] = module.resolve_name_to_id('inventories', inventory)
|
||||||
|
|
||||||
# Attempt to look up job_template based on the provided name
|
# Attempt to look up job_template based on the provided name
|
||||||
lookup_data = {'name': name}
|
lookup_data = {}
|
||||||
if organization:
|
if organization:
|
||||||
lookup_data['organization'] = module.resolve_name_to_id('organizations', organization)
|
lookup_data['organization'] = module.resolve_name_to_id('organizations', organization)
|
||||||
workflow_job_template = module.get_one('workflow_job_templates', data=lookup_data)
|
workflow_job_template, name = module.get_one('workflow_job_templates', name_or_id=name, data=lookup_data)
|
||||||
|
|
||||||
if workflow_job_template is None:
|
if workflow_job_template is None:
|
||||||
module.fail_json(msg="Unable to find workflow job template")
|
module.fail_json(msg="Unable to find workflow job template")
|
||||||
|
|||||||
@@ -13,11 +13,11 @@
|
|||||||
url: "https://cyberark.example.com"
|
url: "https://cyberark.example.com"
|
||||||
app_id: "My-App-ID"
|
app_id: "My-App-ID"
|
||||||
organization: Default
|
organization: Default
|
||||||
register: result
|
register: src_cred_result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- "result is changed"
|
- "src_cred_result is changed"
|
||||||
|
|
||||||
- name: Add Tower credential Target
|
- name: Add Tower credential Target
|
||||||
tower_credential:
|
tower_credential:
|
||||||
@@ -27,17 +27,17 @@
|
|||||||
inputs:
|
inputs:
|
||||||
username: user
|
username: user
|
||||||
organization: Default
|
organization: Default
|
||||||
register: result
|
register: target_cred_result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- "result is changed"
|
- "target_cred_result is changed"
|
||||||
|
|
||||||
- name: Add credential Input Source
|
- name: Add credential Input Source
|
||||||
tower_credential_input_source:
|
tower_credential_input_source:
|
||||||
input_field_name: password
|
input_field_name: password
|
||||||
target_credential: "{{ target_cred_name }}"
|
target_credential: "{{ target_cred_result.id }}"
|
||||||
source_credential: "{{ src_cred_name }}"
|
source_credential: "{{ src_cred_result.id }}"
|
||||||
metadata:
|
metadata:
|
||||||
object_query: "Safe=MY_SAFE;Object=AWX-user"
|
object_query: "Safe=MY_SAFE;Object=AWX-user"
|
||||||
object_query_format: "Exact"
|
object_query_format: "Exact"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
- name: Remove a Tower credential type
|
- name: Remove a Tower credential type
|
||||||
tower_credential_type:
|
tower_credential_type:
|
||||||
name: "{{ cred_type_name }}"
|
name: "{{ result.id }}"
|
||||||
state: absent
|
state: absent
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
|||||||
@@ -14,11 +14,12 @@
|
|||||||
name: "{{ inv_name }}"
|
name: "{{ inv_name }}"
|
||||||
organization: Default
|
organization: Default
|
||||||
state: present
|
state: present
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Create a Group
|
- name: Create a Group
|
||||||
tower_group:
|
tower_group:
|
||||||
name: "{{ group_name1 }}"
|
name: "{{ group_name1 }}"
|
||||||
inventory: "{{ inv_name }}"
|
inventory: "{{ result.id }}"
|
||||||
state: present
|
state: present
|
||||||
variables:
|
variables:
|
||||||
foo: bar
|
foo: bar
|
||||||
@@ -30,7 +31,7 @@
|
|||||||
|
|
||||||
- name: Delete a Group
|
- name: Delete a Group
|
||||||
tower_group:
|
tower_group:
|
||||||
name: "{{ group_name1 }}"
|
name: "{{ result.id }}"
|
||||||
inventory: "{{ inv_name }}"
|
inventory: "{{ inv_name }}"
|
||||||
state: absent
|
state: absent
|
||||||
register: result
|
register: result
|
||||||
|
|||||||
@@ -9,11 +9,12 @@
|
|||||||
name: "{{ inv_name }}"
|
name: "{{ inv_name }}"
|
||||||
organization: Default
|
organization: Default
|
||||||
state: present
|
state: present
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Create a Host
|
- name: Create a Host
|
||||||
tower_host:
|
tower_host:
|
||||||
name: "{{ host_name }}"
|
name: "{{ host_name }}"
|
||||||
inventory: "{{ inv_name }}"
|
inventory: "{{ result.id }}"
|
||||||
state: present
|
state: present
|
||||||
variables:
|
variables:
|
||||||
foo: bar
|
foo: bar
|
||||||
@@ -25,7 +26,7 @@
|
|||||||
|
|
||||||
- name: Delete a Host
|
- name: Delete a Host
|
||||||
tower_host:
|
tower_host:
|
||||||
name: "{{ host_name }}"
|
name: "{{ result.id }}"
|
||||||
inventory: "{{ inv_name }}"
|
inventory: "{{ inv_name }}"
|
||||||
state: absent
|
state: absent
|
||||||
register: result
|
register: result
|
||||||
|
|||||||
@@ -19,11 +19,11 @@
|
|||||||
host: "https://openshift.org"
|
host: "https://openshift.org"
|
||||||
bearer_token: "asdf1234"
|
bearer_token: "asdf1234"
|
||||||
verify_ssl: false
|
verify_ssl: false
|
||||||
register: result
|
register: cred_result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- "result is changed"
|
- "cred_result is changed"
|
||||||
|
|
||||||
- name: Create an Instance Group
|
- name: Create an Instance Group
|
||||||
tower_instance_group:
|
tower_instance_group:
|
||||||
@@ -37,10 +37,22 @@
|
|||||||
that:
|
that:
|
||||||
- "result is changed"
|
- "result is changed"
|
||||||
|
|
||||||
|
- name: Update an Instance Group
|
||||||
|
tower_instance_group:
|
||||||
|
name: "{{ result.id }}"
|
||||||
|
policy_instance_percentage: 34
|
||||||
|
policy_instance_minimum: 24
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "result is changed"
|
||||||
|
|
||||||
- name: Create a container group
|
- name: Create a container group
|
||||||
tower_instance_group:
|
tower_instance_group:
|
||||||
name: "{{ group_name2 }}"
|
name: "{{ group_name2 }}"
|
||||||
credential: "{{ cred_name1 }}"
|
credential: "{{ cred_result.id }}"
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
tower_inventory:
|
tower_inventory:
|
||||||
name: "{{ inv_name1 }}"
|
name: "{{ inv_name1 }}"
|
||||||
organization: Default
|
organization: Default
|
||||||
insights_credential: "{{ cred_name1 }}"
|
insights_credential: "{{ results.id }}"
|
||||||
state: present
|
state: present
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
- name: Test Inventory module idempotency
|
- name: Test Inventory module idempotency
|
||||||
tower_inventory:
|
tower_inventory:
|
||||||
name: "{{ inv_name1 }}"
|
name: "{{ result.id }}"
|
||||||
organization: Default
|
organization: Default
|
||||||
insights_credential: "{{ cred_name1 }}"
|
insights_credential: "{{ cred_name1 }}"
|
||||||
state: present
|
state: present
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
host: https://example.org:5000
|
host: https://example.org:5000
|
||||||
password: passw0rd
|
password: passw0rd
|
||||||
domain: test
|
domain: test
|
||||||
|
register: credential_result
|
||||||
|
|
||||||
- name: Add a Tower inventory
|
- name: Add a Tower inventory
|
||||||
tower_inventory:
|
tower_inventory:
|
||||||
@@ -28,7 +29,7 @@
|
|||||||
name: "{{ openstack_inv_source }}"
|
name: "{{ openstack_inv_source }}"
|
||||||
description: Source for Test inventory
|
description: Source for Test inventory
|
||||||
inventory: "{{ openstack_inv }}"
|
inventory: "{{ openstack_inv }}"
|
||||||
credential: "{{ openstack_cred }}"
|
credential: "{{ credential_result.id }}"
|
||||||
overwrite: true
|
overwrite: true
|
||||||
update_on_launch: true
|
update_on_launch: true
|
||||||
source_vars:
|
source_vars:
|
||||||
@@ -42,7 +43,7 @@
|
|||||||
|
|
||||||
- name: Delete the inventory source with an invalid cred, source_project, sourece_script specified
|
- name: Delete the inventory source with an invalid cred, source_project, sourece_script specified
|
||||||
tower_inventory_source:
|
tower_inventory_source:
|
||||||
name: "{{ openstack_inv_source }}"
|
name: "{{ result.id }}"
|
||||||
inventory: "{{ openstack_inv }}"
|
inventory: "{{ openstack_inv }}"
|
||||||
credential: "Does Not Exit"
|
credential: "Does Not Exit"
|
||||||
source_project: "Does Not Exist"
|
source_project: "Does Not Exist"
|
||||||
|
|||||||
@@ -22,14 +22,14 @@
|
|||||||
state: present
|
state: present
|
||||||
scm_type: git
|
scm_type: git
|
||||||
scm_url: https://github.com/ansible/ansible-tower-samples.git
|
scm_url: https://github.com/ansible/ansible-tower-samples.git
|
||||||
|
register: proj_result
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: Create Credential1
|
- name: Create Credential1
|
||||||
tower_credential:
|
tower_credential:
|
||||||
name: "{{ cred1 }}"
|
name: "{{ cred1 }}"
|
||||||
organization: Default
|
organization: Default
|
||||||
kind: tower
|
kind: tower
|
||||||
|
register: cred1_result
|
||||||
|
|
||||||
- name: Create Credential2
|
- name: Create Credential2
|
||||||
tower_credential:
|
tower_credential:
|
||||||
@@ -84,19 +84,19 @@
|
|||||||
credentials: ["{{ cred1 }}", "{{ cred2 }}"]
|
credentials: ["{{ cred1 }}", "{{ cred2 }}"]
|
||||||
job_type: run
|
job_type: run
|
||||||
state: present
|
state: present
|
||||||
register: result
|
register: jt1_result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- "result is changed"
|
- "jt1_result is changed"
|
||||||
|
|
||||||
- name: Add a credential to this JT
|
- name: Add a credential to this JT
|
||||||
tower_job_template:
|
tower_job_template:
|
||||||
name: "{{ jt1 }}"
|
name: "{{ jt1 }}"
|
||||||
project: "{{ proj1 }}"
|
project: "{{ proj_result.id }}"
|
||||||
playbook: hello_world.yml
|
playbook: hello_world.yml
|
||||||
credentials:
|
credentials:
|
||||||
- "{{ cred1 }}"
|
- "{{ cred1_result.id }}"
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
@@ -105,7 +105,7 @@
|
|||||||
|
|
||||||
- name: Try to add the same credential to this JT
|
- name: Try to add the same credential to this JT
|
||||||
tower_job_template:
|
tower_job_template:
|
||||||
name: "{{ jt1 }}"
|
name: "{{ jt1_result.id }}"
|
||||||
project: "{{ proj1 }}"
|
project: "{{ proj1 }}"
|
||||||
playbook: hello_world.yml
|
playbook: hello_world.yml
|
||||||
credentials:
|
credentials:
|
||||||
|
|||||||
@@ -175,9 +175,8 @@ def main():
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
# Attempt to look up an existing item based on the provided data
|
# Attempt to look up an existing item based on the provided data
|
||||||
existing_item = module.get_one('{{ item_type }}', **{
|
existing_item, name = module.get_one('{{ item_type }}', name_or_id={{ name_option }}, **{
|
||||||
'data': {
|
'data': {
|
||||||
'{{ name_option }}': {{ name_option }},
|
|
||||||
{% if 'organization' in item['json']['actions']['POST'] and item['json']['actions']['POST']['organization']['type'] == 'id' %}
|
{% if 'organization' in item['json']['actions']['POST'] and item['json']['actions']['POST']['organization']['type'] == 'id' %}
|
||||||
'organization': org_id,
|
'organization': org_id,
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user