Skip to content

Commit

Permalink
Fixes #38219 - fix Ansible Tower API path based on version
Browse files Browse the repository at this point in the history
  • Loading branch information
nofaralfasi committed Feb 17, 2025
1 parent 71fc34b commit 3487aaa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@ description: |
#!/bin/sh

echo "Calling Ansible AWX/Tower provisioning callback..."

<%
api_base = if host_param('ansible_tower_version').to_f >= 2.5
'/api/controller/v2/job_templates'
else
'/api/v2/job_templates'
end
-%>

<% if host_param('ansible_extra_vars') -%>
/usr/bin/curl -v -k -s -H 'Content-Type: application/json' --data '{"host_config_key":"<%= host_param('ansible_host_config_key') %>", "extra_vars": <%=host_param('ansible_extra_vars') %>}' https://<%= host_param('ansible_tower_fqdn') %>/api/v2/job_templates/<%= host_param('ansible_job_template_id') %>/callback/
/usr/bin/curl -v -k -s -H 'Content-Type: application/json' --data '{"host_config_key":"<%= host_param('ansible_host_config_key') %>", "extra_vars": <%=host_param('ansible_extra_vars') %>}' https://<%= host_param('ansible_tower_fqdn') %><%= api_base %>/<%= host_param('ansible_job_template_id') %>/callback/
<% else -%>
/usr/bin/curl -v -k -s --data "host_config_key=<%= host_param('ansible_host_config_key') %>" https://<%= host_param('ansible_tower_fqdn') %>/api/v2/job_templates/<%= host_param('ansible_job_template_id') %>/callback/
/usr/bin/curl -v -k -s --data "host_config_key=<%= host_param('ansible_host_config_key') %>" https://<%= host_param('ansible_tower_fqdn') %><%= api_base %>/<%= host_param('ansible_job_template_id') %>/callback/
<% end -%>
echo "DONE"
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ description: |
The content of a systemd service for running Ansible Tower / AWX callback script one-time.
Used in the ansible_provisioning_callback snippet for systemd enabled systems.
-%>

<%
api_base = if host_param('ansible_tower_version').to_f >= 2.5
'/api/controller/v2/job_templates'
else
'/api/v2/job_templates'
end
-%>

[Unit]
Description=Provisioning callback to Ansible Tower
Wants=network-online.target
Expand All @@ -15,9 +24,9 @@ After=network-online.target
[Service]
Type=oneshot
<% if host_param('ansible_extra_vars') -%>
ExecStart=/usr/bin/curl -k -s -H 'Content-Type: application/json' --data '{"host_config_key":"<%= host_param('ansible_host_config_key') %>", "extra_vars": <%=host_param('ansible_extra_vars') %>}' https://<%= host_param('ansible_tower_fqdn') %>/api/v2/job_templates/<%= host_param('ansible_job_template_id') %>/callback/
ExecStart=/usr/bin/curl -k -s -H 'Content-Type: application/json' --data '{"host_config_key":"<%= host_param('ansible_host_config_key') %>", "extra_vars": <%=host_param('ansible_extra_vars') %>}' https://<%= host_param('ansible_tower_fqdn') %><%= api_base %>/<%= host_param('ansible_job_template_id') %>/callback/
<% else -%>
ExecStart=/usr/bin/curl -k -s --data "host_config_key=<%= host_param('ansible_host_config_key') -%>" https://<%= host_param('ansible_tower_fqdn') -%>/api/v2/job_templates/<%= host_param('ansible_job_template_id') -%>/callback/
ExecStart=/usr/bin/curl -k -s --data "host_config_key=<%= host_param('ansible_host_config_key') -%>" https://<%= host_param('ansible_tower_fqdn') -%><%= api_base %>/<%= host_param('ansible_job_template_id') -%>/callback/
<% end -%>
ExecStartPost=/usr/bin/systemctl disable ansible-callback

Expand Down

0 comments on commit 3487aaa

Please sign in to comment.