Closed zaskan closed 11 months ago
having trouble replicating on awx devel / ansible-devel, can you post a snippet from your playbook?
here is how I tested,
---
- name: playbook jt same name
hosts: localhost
connection: local
gather_facts: False
collections:
- awx.awx
tasks:
- name: Delete project
project:
name: PNAME
state: absent
- name: Delete jt
job_template:
name: PNAME
state: absent
- name: Create a project
project:
name: PNAME
copy_from: Demo Project
scm_type: git
description: here is a project
organization: Default
state: present
- name: Create a jt
job_template:
name: PNAME
copy_from: Demo Job Template
job_type: run
inventory: Demo Inventory
project: PNAME
organization: Default
playbook: hello_world.yml
state: present
- name: Launch it
job_launch:
name: PNAME
Hi, I have created an easier reproducer.
You need to create a project named "Test" sourcing this repo.
https://github.com/zaskan/test
Also, you need to create a job template with same name "Test" using previously created project "Test" and playbook.yaml
. Configure your Automation Hub credentials in order to download the requirements file.
If you run the template you will get the following.
{
"msg": "Request to /api/v2/unified_job_templates/?name=Test returned 2 items, expected 1",
"query": {
"name": "Test"
},
"response": {
"status_code": 200,
"json": {
"count": 2,
"next": null,
"previous": null,
"results": [
{
"id": 12,
"type": "project",
"url": "/api/v2/projects/12/",
"related": {
"created_by": "/api/v2/users/1/",
"modified_by": "/api/v2/users/1/",
"last_job": "/api/v2/project_updates/41/",
"teams": "/api/v2/projects/12/teams/",
"playbooks": "/api/v2/projects/12/playbooks/",
"inventory_files": "/api/v2/projects/12/inventories/",
"update": "/api/v2/projects/12/update/",
"project_updates": "/api/v2/projects/12/project_updates/",
"scm_inventory_sources": "/api/v2/projects/12/scm_inventory_sources/",
"schedules": "/api/v2/projects/12/schedules/",
"activity_stream": "/api/v2/projects/12/activity_stream/",
"notification_templates_started": "/api/v2/projects/12/notification_templates_started/",
"notification_templates_success": "/api/v2/projects/12/notification_templates_success/",
"notification_templates_error": "/api/v2/projects/12/notification_templates_error/",
"access_list": "/api/v2/projects/12/access_list/",
"object_roles": "/api/v2/projects/12/object_roles/",
"copy": "/api/v2/projects/12/copy/",
"organization": "/api/v2/organizations/1/",
"last_update": "/api/v2/project_updates/41/"
},
"summary_fields": {
"organization": {
"id": 1,
"name": "Default",
"description": ""
},
"last_job": {
"id": 41,
"name": "Test",
"description": "",
"finished": "2021-07-07T07:53:22.868369Z",
"status": "successful",
"failed": false
},
"last_update": {
"id": 41,
"name": "Test",
"description": "",
"status": "successful",
"failed": false
},
"created_by": {
"id": 1,
"username": "admin",
"first_name": "",
"last_name": ""
},
"modified_by": {
"id": 1,
"username": "admin",
"first_name": "",
"last_name": ""
},
"object_roles": {
"admin_role": {
"description": "Can manage all aspects of the project",
"name": "Admin",
"id": 52
},
"use_role": {
"description": "Can use the project in a job template",
"name": "Use",
"id": 53
},
"update_role": {
"description": "May update the project",
"name": "Update",
"id": 54
},
"read_role": {
"description": "May view settings for the project",
"name": "Read",
"id": 55
}
},
"user_capabilities": {
"edit": true,
"delete": true,
"start": true,
"schedule": true,
"copy": true
}
},
"created": "2021-07-07T07:00:08.973227Z",
"modified": "2021-07-07T07:14:22.503496Z",
"name": "Test",
"description": "",
"local_path": "_12__Test",
"scm_type": "git",
"scm_url": "https://github.com/zaskan/test.git",
"scm_branch": "",
"scm_refspec": "",
"scm_clean": false,
"scm_delete_on_update": true,
"credential": null,
"timeout": 0,
"scm_revision": "f4100cf9e152ddad99e3b636e210cfc910ee19ae",
"last_job_run": "2021-07-07T07:53:22.868369Z",
"last_job_failed": false,
"next_job_run": null,
"status": "successful",
"organization": 1,
"scm_update_on_launch": true,
"scm_update_cache_timeout": 0,
"allow_override": false,
"custom_virtualenv": null,
"last_update_failed": false,
"last_updated": "2021-07-07T07:53:22.868369Z"
},
{
"id": 13,
"type": "job_template",
"url": "/api/v2/job_templates/13/",
"related": {
"created_by": "/api/v2/users/1/",
"modified_by": "/api/v2/users/1/",
"labels": "/api/v2/job_templates/13/labels/",
"inventory": "/api/v2/inventories/1/",
"project": "/api/v2/projects/12/",
"organization": "/api/v2/organizations/1/",
"credentials": "/api/v2/job_templates/13/credentials/",
"current_job": "/api/v2/jobs/40/",
"last_job": "/api/v2/jobs/38/",
"jobs": "/api/v2/job_templates/13/jobs/",
"schedules": "/api/v2/job_templates/13/schedules/",
"activity_stream": "/api/v2/job_templates/13/activity_stream/",
"launch": "/api/v2/job_templates/13/launch/",
"webhook_key": "/api/v2/job_templates/13/webhook_key/",
"webhook_receiver": "",
"notification_templates_started": "/api/v2/job_templates/13/notification_templates_started/",
"notification_templates_success": "/api/v2/job_templates/13/notification_templates_success/",
"notification_templates_error": "/api/v2/job_templates/13/notification_templates_error/",
"access_list": "/api/v2/job_templates/13/access_list/",
"survey_spec": "/api/v2/job_templates/13/survey_spec/",
"object_roles": "/api/v2/job_templates/13/object_roles/",
"instance_groups": "/api/v2/job_templates/13/instance_groups/",
"slice_workflow_jobs": "/api/v2/job_templates/13/slice_workflow_jobs/",
"copy": "/api/v2/job_templates/13/copy/"
},
"summary_fields": {
"organization": {
"id": 1,
"name": "Default",
"description": ""
},
"inventory": {
"id": 1,
"name": "Demo Inventory",
"description": "",
"has_active_failures": true,
"total_hosts": 1,
"hosts_with_active_failures": 1,
"total_groups": 0,
"has_inventory_sources": false,
"total_inventory_sources": 0,
"inventory_sources_with_failures": 0,
"organization_id": 1,
"kind": ""
},
"project": {
"id": 12,
"name": "Test",
"description": "",
"status": "successful",
"scm_type": "git"
},
"last_job": {
"id": 38,
"name": "Test",
"description": "",
"finished": "2021-07-07T07:52:43.983784Z",
"status": "failed",
"failed": true
},
"last_update": {
"id": 38,
"name": "Test",
"description": "",
"status": "failed",
"failed": true
},
"current_update": {
"id": 40,
"name": "Test",
"description": "",
"status": "running",
"failed": false
},
"current_job": {
"id": 40,
"name": "Test",
"description": "",
"status": "running",
"failed": false
},
"created_by": {
"id": 1,
"username": "admin",
"first_name": "",
"last_name": ""
},
"modified_by": {
"id": 1,
"username": "admin",
"first_name": "",
"last_name": ""
},
"object_roles": {
"admin_role": {
"description": "Can manage all aspects of the job template",
"name": "Admin",
"id": 56
},
"execute_role": {
"description": "May run the job template",
"name": "Execute",
"id": 57
},
"read_role": {
"description": "May view settings for the job template",
"name": "Read",
"id": 58
}
},
"user_capabilities": {
"edit": true,
"delete": true,
"start": true,
"schedule": true,
"copy": true
},
"labels": {
"count": 0,
"results": []
},
"recent_jobs": [
{
"id": 40,
"status": "running",
"finished": null,
"canceled_on": null,
"type": "job"
},
{
"id": 38,
"status": "failed",
"finished": "2021-07-07T07:52:43.983784Z",
"canceled_on": null,
"type": "job"
},
{
"id": 36,
"status": "failed",
"finished": "2021-07-07T07:51:34.457730Z",
"canceled_on": null,
"type": "job"
},
{
"id": 34,
"status": "failed",
"finished": "2021-07-07T07:50:16.155347Z",
"canceled_on": null,
"type": "job"
},
{
"id": 26,
"status": "failed",
"finished": "2021-07-07T07:35:52.556898Z",
"canceled_on": null,
"type": "job"
},
{
"id": 24,
"status": "failed",
"finished": "2021-07-07T07:33:18.871046Z",
"canceled_on": null,
"type": "job"
},
{
"id": 13,
"status": "failed",
"finished": "2021-07-07T07:14:33.650837Z",
"canceled_on": null,
"type": "job"
},
{
"id": 12,
"status": "failed",
"finished": "2021-07-07T07:14:16.275078Z",
"canceled_on": null,
"type": "job"
},
{
"id": 11,
"status": "failed",
"finished": "2021-07-07T07:13:52.999169Z",
"canceled_on": null,
"type": "job"
},
{
"id": 10,
"status": "failed",
"finished": "2021-07-07T07:12:58.708359Z",
"canceled_on": null,
"type": "job"
}
],
"credentials": [
{
"id": 5,
"name": "Tower",
"description": "",
"kind": "tower",
"cloud": true
}
]
},
"created": "2021-07-07T07:00:39.723758Z",
"modified": "2021-07-07T07:53:09.790720Z",
"name": "Test",
"description": "",
"job_type": "run",
"inventory": 1,
"project": 12,
"playbook": "playbook.yaml",
"scm_branch": "",
"forks": 0,
"limit": "",
"verbosity": 3,
"extra_vars": "",
"job_tags": "",
"force_handlers": false,
"skip_tags": "",
"start_at_task": "",
"timeout": 0,
"use_fact_cache": false,
"organization": 1,
"last_job_run": "2021-07-07T07:52:43.983784Z",
"last_job_failed": true,
"next_job_run": null,
"status": "running",
"host_config_key": "",
"ask_scm_branch_on_launch": false,
"ask_diff_mode_on_launch": false,
"ask_variables_on_launch": false,
"ask_limit_on_launch": false,
"ask_tags_on_launch": false,
"ask_skip_tags_on_launch": false,
"ask_job_type_on_launch": false,
"ask_verbosity_on_launch": false,
"ask_inventory_on_launch": false,
"ask_credential_on_launch": false,
"survey_enabled": false,
"become_enabled": false,
"diff_mode": false,
"allow_simultaneous": false,
"custom_virtualenv": null,
"job_slice_count": 1,
"webhook_service": "",
"webhook_credential": null
},
"...more results snipped..."
]
}
},
"total_results": 2,
"invocation": {
"module_args": {
"name": "Schedule 1",
"state": "present",
"unified_job_template": "Test",
"rrule": "DTSTART:20191219T130551Z RRULE:FREQ=WEEKLY;INTERVAL=1;COUNT=1",
"tower_host": "https://127.0.0.1",
"tower_username": "admin",
"tower_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"validate_certs": false,
"tower_oauthtoken": "",
"tower_config_file": null,
"new_name": null,
"description": null,
"extra_data": null,
"inventory": null,
"scm_branch": null,
"job_type": null,
"job_tags": null,
"skip_tags": null,
"limit": null,
"diff_mode": null,
"verbosity": null,
"enabled": null
}
},
"_ansible_no_log": false,
"changed": false
}
In your playbook,
ansible.tower.tower_schedule:
name: "Schedule 1"
state: present
unified_job_template: "Test"
I see, yeah the module will call
unified_job_template_id = module.resolve_name_to_id('unified_job_templates', unified_job_template)
which will return 2 entries, and will fail.
I think ideally we could provide an id for this module option, then you could use the lookup plugin to get the id of the "Test" JT
@AlanCoding in collection do we have a pattern where users can provide either a name or an id?
Any updates on this? Sadly, I have the same problem. An Inventory will also be found by the unfied_job_template API entry point.
Yes, you can use the lookup plugin to lookup by whatever search you need and have that return an id, which will be respected.
Going to close this issue because the proposal is unclear, the lookup_plugin workaround works, and we have other issues that are more direct about improvements to name-based lookups.
ISSUE TYPE
SUMMARY
Setting same names to job template and its project causes tower_job_template to fail. It produces the following output:
ENVIRONMENT
STEPS TO REPRODUCE
Create a project and assign it to a job template with the same name. Run the job template.
ADDITIONAL INFORMATION
CUSTOMER CASE