Ansible Tower returning an outdated Job ID in the response to ServiceNow

We have an integration between ServiceNow and Ansible Tower, with Ansible Tower endpoints configured in ServiceNow.
We use a customized catalog in ServiceNow for Ansible automation. ServiceNow sends payloads to Ansible for the customized catalog details, and Ansible returns the entire response to ServiceNow, including the Job ID.
Recently, however, Ansible has been returning an outdated Job ID in the response to ServiceNow’s POST method. For example, while the latest Job ID in Ansible is 11805, the Job ID received in ServiceNow’s response is 11107.
Although ServiceNow shows a 201 OK status code, no job is triggered in Ansible Tower for the new request submitted from the customized catalog.

Ansible tower Version is :- 3.7.4
Service Now version:- XANADU
Actually don’t have any error or logs to highlight this issue.

It might help if you could show us how Ansible Tower is sending a response to ServiceNow? Is this through a task in a job, a notification, or some other integration? Can you show us code samples or screenshots/snippets of what you see on both sides? (please use triple backticks: ```, to format blocks of code or logs)

My only suspicion I have to go off of right now is that maybe you’re using set_fact for the Job ID you’re sending in a response to ServiceNow, but that fact is getting cached and thus becomes stale in subsequent jobs until the cache decides that the fact itself is stale (which could be never, depending on your cache settings). Clearing the fact cache with the meta module would manually force the fact to be refreshed on the next job, but you would need to make sure the fact stops getting cached in the first place to prevent a recurring issue.

If you’re not setting a Job ID fact, then I will wait until you share some more information with us before pondering other issues.


Also, side note, Ansible Tower has been EoL for some time now. If you’re still paying for it, you should migrate to a supported version sooner than later.

Ansible Tower Endpoint Configuration in ServiceNow Catalog.

Endpoint:- https://loadbalancer IP/api/v2/job_templates/45/launch
Note:- Our load balancer is configured with three Ansible Towers.

Response from Ansible to ServiceNow after Data Post:-
Response body {“job”:11163,“ignored_fields”:{},“id”:11163,“type”:“job”,“url”:“/api/v2/jobs/11163/”,“related”:{“created_by”:“/api/v2/users/1/”,“modified_by”:“/api/v2/users/1/”,“labels”:“/api/v2/jobs/11163/labels/”,“inventory”:“/api/v2/inventories/1/”,“project”:“/api/v2/projects/4/”,“organization”:“/api/v2/organizations/1/”,“extra_credentials”:“/api/v2/jobs/11163/extra_credentials/”,“credentials”:“/api/v2/jobs/11163/credentials/”,“unified_job_template”:“/api/v2/job_templates/45/”,“stdout”:“/api/v2/jobs/11163/stdout/”,“job_events”:“/api/v2/jobs/11163/job_events/”,“job_host_summaries”:“/api/v2/jobs/11163/job_host_summaries/”,“activity_stream”:“/api/v2/jobs/11163/activity_stream/”,“notifications”:“/api/v2/jobs/11163/notifications/”,“create_schedule”:“/api/v2/jobs/11163/create_schedule/”,“job_template”:“/api/v2/job_templates/45/”,“cancel”:“/api/v2/jobs/11163/cancel/”,“relaunch”:“/api/v2/jobs/11163/relaunch/”},“summary_fields”:{“organization”:{“id”:1,“name”:“AACB CMP”,“description”:“”},“inventory”:{“id”:1,“name”:“AACB Inventory”,“description”:“”,“has_active_failures”:false,“total_hosts”:0,“hosts_with_active_failures”:0,“total_groups”:0,“has_inventory_sources”:false,“total_inventory_sources”:0,“inventory_sources_with_failures”:0,“organization_id”:1,“kind”:“”},“project”:{“id”:4,“name”:“AACB CMP Project”,“description”:" CMP Project",“status”:“ok”,“scm_type”:“”},“job_template”:{“id”:45,“name”:“Linux DMZ VM build-RHEL8”,“description”:“Linux DMZ VM build-RHEL8”},“unified_job_template”:{“id”:45,“name”:“Linux DMZ VM build-RHEL8”,“description”:“Linux DMZ VM build-RHEL8”,“unified_job_type”:“job”},“created_by”:{“id”:1,“username”:“admin”,“first_name”:“”,“last_name”:“”},“modified_by”:{“id”:1,“username”:“admin”,“first_name”:“”,“last_name”:“”},“user_capabilities”:{“delete”:true,“start”:true},“labels”:{“count”:0,“results”:},“extra_credentials”:,“credentials”:[{“id”:1,“name”:“Prod credentials”,“description”:“Prod credentials”,“kind”:“ssh”,“cloud”:false}]},“created”:“2024-10-07T12:43:44.803687Z”,“modified”:“2024-10-07T12:43:44.851977Z”,“name”:“Linux DMZ VM build-RHEL8”,“description”:“Linux DMZ VM build-RHEL8”,“job_type”:“run”,“inventory”:1,“project”:4,“playbook”:“test_play/IaaS-Playbooks/prod/linux/NewVM/RHEL8_DMZ/dmz_build_rhel8.yml”,“scm_branch”:“”,“forks”:0,“limit”:“”,“verbosity”:0,“extra_vars”:“{"name": "gbvleuaacuaap01", "template": "RHEL8_GoldenTemplate", "size": "30", "size_1": "20", "ram": "16384", "cpu": "4", "ritm": "SCTASK0499743", "ip_adr": null, "server_role": null, "app": "Ansible Automation Platform ", "dev": "u", "ser": null, "siteid": null, "vmtype": null, "iteration": "1", "tier": "", "protection": "", "epg": "LON-EDMZNP-ANSIBL01", "applicationref": "aap", "network": "EDMZ", "justification": "As per Request Number xyz.", "user": "Marek ", "serviceclass": "Bronze"}”,“job_tags”:“”,“force_handlers”:false,“skip_tags”:“”,“start_at_task”:“”,“timeout”:0,“use_fact_cache”:true,“organization”:1,“unified_job_template”:45,“launch_type”:“manual”,“status”:“pending”,“failed”:false,“started”:null,“finished”:null,“canceled_on”:null,“elapsed”:0.0,“job_args”:“”,“job_cwd”:“”,“job_env”:{},“job_explanation”:“”,“execution_node”:“”,“controller_node”:“”,“result_traceback”:“”,“event_processing_finished”:false,“job_template”:45,“passwords_needed_to_start”:,“allow_simultaneous”:true,“artifacts”:{},“scm_revision”:“”,“instance_group”:null,“diff_mode”:false,“job_slice_number”:0,“job_slice_count”:1,“webhook_service”:“”,“webhook_credential”:null,“webhook_guid”:“”}

This output doesn’t really help answer any of my questions. All I know is that this job ran on Monday according to Ansible Tower. Did ServiceNow run this today and get a response about an older job? It’s returning a job from the correct Job Template at least.

Since you’re using a load balanced Ansible Tower, is there a single shared postgresql instance or does each tower have its own postgres backend?

1 Like