Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #38219 - fix Ansible Tower API path based on AAP version #10445

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,20 @@ description: |
#!/bin/sh

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

# Attempt to use the /api/controller/v2 API for AAP 2.5 and higher. If successful, continue with newer API endpoints.
response=$(/usr/bin/curl -k -s --write-out "%{http_code}" -o /dev/null https://<%= host_param('ansible_tower_fqdn') %>/api/controller/v2/)

# If the /api/controller/v2 API fails, fallback to /api/v2 for older AAP versions.
if [ "$response" -eq 200 ]; then
api_base='/api/controller/v2/job_templates/' # Use newer API for AAP 2.5+
else
api_base='/api/v2/job_templates/' # Fallback to older API versions
fi

<% 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,17 @@ 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.
-%>

# Attempt to use the /api/controller/v2 API for AAP 2.5 and higher. If successful, continue with newer API endpoints.
response=$(/usr/bin/curl -k -s --write-out "%{http_code}" -o /dev/null https://<%= host_param('ansible_tower_fqdn') %>/api/controller/v2/)

# If the /api/controller/v2 API fails, fallback to /api/v2 for older AAP versions.
if [ "$response" -eq 200 ]; then
api_base='/api/controller/v2/job_templates/' # Use newer API for AAP 2.5+
else
api_base='/api/v2/job_templates/' # Fallback to older API versions
fi

[Unit]
Description=Provisioning callback to Ansible Tower
Wants=network-online.target
Expand All @@ -15,9 +26,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
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,18 @@ cat << EOF-9f037ba1 > /root/ansible_provisioning_call.sh
#!/bin/sh

echo "Calling Ansible AWX/Tower provisioning callback..."
/usr/bin/curl -v -k -s --data "host_config_key=" https:///api/v2/job_templates//callback/

# Attempt to use the /api/controller/v2 API for AAP 2.5 and higher. If successful, continue with newer API endpoints.
response=$(/usr/bin/curl -k -s --write-out "%{http_code}" -o /dev/null https:///api/controller/v2/)

# If the /api/controller/v2 API fails, fallback to /api/v2 for older AAP versions.
if [ "$response" -eq 200 ]; then
api_base='/api/controller/v2/job_templates/' # Use newer API for AAP 2.5+
else
api_base='/api/v2/job_templates/' # Fallback to older API versions
fi

/usr/bin/curl -v -k -s --data "host_config_key=" https://${api_base}/callback/
echo "DONE"
EOF-9f037ba1
chmod +x /root/ansible_provisioning_call.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,25 @@ iface $real inet dhcp
EOF

cat << EOF-2929810d > /etc/systemd/system/ansible-callback.service

# Attempt to use the /api/controller/v2 API for AAP 2.5 and higher. If successful, continue with newer API endpoints.
response=$(/usr/bin/curl -k -s --write-out "%{http_code}" -o /dev/null https:///api/controller/v2/)

# If the /api/controller/v2 API fails, fallback to /api/v2 for older AAP versions.
if [ "$response" -eq 200 ]; then
api_base='/api/controller/v2/job_templates/' # Use newer API for AAP 2.5+
else
api_base='/api/v2/job_templates/' # Fallback to older API versions
fi

[Unit]
Description=Provisioning callback to Ansible Tower
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https:///api/v2/job_templates//callback/
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https://${api_base}/callback/
ExecStartPost=/usr/bin/systemctl disable ansible-callback

[Install]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,25 @@ iface $real inet dhcp
EOF

cat << EOF-2929810d > /etc/systemd/system/ansible-callback.service

# Attempt to use the /api/controller/v2 API for AAP 2.5 and higher. If successful, continue with newer API endpoints.
response=$(/usr/bin/curl -k -s --write-out "%{http_code}" -o /dev/null https:///api/controller/v2/)

# If the /api/controller/v2 API fails, fallback to /api/v2 for older AAP versions.
if [ "$response" -eq 200 ]; then
api_base='/api/controller/v2/job_templates/' # Use newer API for AAP 2.5+
else
api_base='/api/v2/job_templates/' # Fallback to older API versions
fi

[Unit]
Description=Provisioning callback to Ansible Tower
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https:///api/v2/job_templates//callback/
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https://${api_base}/callback/
ExecStartPost=/usr/bin/systemctl disable ansible-callback

[Install]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,25 @@ echo "Performing initial puppet run for --tags no_such_tag"


cat << EOF-2929810d > /etc/systemd/system/ansible-callback.service

# Attempt to use the /api/controller/v2 API for AAP 2.5 and higher. If successful, continue with newer API endpoints.
response=$(/usr/bin/curl -k -s --write-out "%{http_code}" -o /dev/null https:///api/controller/v2/)

# If the /api/controller/v2 API fails, fallback to /api/v2 for older AAP versions.
if [ "$response" -eq 200 ]; then
api_base='/api/controller/v2/job_templates/' # Use newer API for AAP 2.5+
else
api_base='/api/v2/job_templates/' # Fallback to older API versions
fi

[Unit]
Description=Provisioning callback to Ansible Tower
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https:///api/v2/job_templates//callback/
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https://${api_base}/callback/
ExecStartPost=/usr/bin/systemctl disable ansible-callback

[Install]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,25 @@ echo "Performing initial puppet run for --tags no_such_tag"


cat << EOF-2929810d > /etc/systemd/system/ansible-callback.service

# Attempt to use the /api/controller/v2 API for AAP 2.5 and higher. If successful, continue with newer API endpoints.
response=$(/usr/bin/curl -k -s --write-out "%{http_code}" -o /dev/null https:///api/controller/v2/)

# If the /api/controller/v2 API fails, fallback to /api/v2 for older AAP versions.
if [ "$response" -eq 200 ]; then
api_base='/api/controller/v2/job_templates/' # Use newer API for AAP 2.5+
else
api_base='/api/v2/job_templates/' # Fallback to older API versions
fi

[Unit]
Description=Provisioning callback to Ansible Tower
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https:///api/v2/job_templates//callback/
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https://${api_base}/callback/
ExecStartPost=/usr/bin/systemctl disable ansible-callback

[Install]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,25 @@ echo "Performing initial puppet run for --tags no_such_tag"


cat << EOF-2929810d > /etc/systemd/system/ansible-callback.service

# Attempt to use the /api/controller/v2 API for AAP 2.5 and higher. If successful, continue with newer API endpoints.
response=$(/usr/bin/curl -k -s --write-out "%{http_code}" -o /dev/null https:///api/controller/v2/)

# If the /api/controller/v2 API fails, fallback to /api/v2 for older AAP versions.
if [ "$response" -eq 200 ]; then
api_base='/api/controller/v2/job_templates/' # Use newer API for AAP 2.5+
else
api_base='/api/v2/job_templates/' # Fallback to older API versions
fi

[Unit]
Description=Provisioning callback to Ansible Tower
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https:///api/v2/job_templates//callback/
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https://${api_base}/callback/
ExecStartPost=/usr/bin/systemctl disable ansible-callback

[Install]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,25 @@ echo "Performing initial puppet run for --tags no_such_tag"


cat << EOF-2929810d > /etc/systemd/system/ansible-callback.service

# Attempt to use the /api/controller/v2 API for AAP 2.5 and higher. If successful, continue with newer API endpoints.
response=$(/usr/bin/curl -k -s --write-out "%{http_code}" -o /dev/null https:///api/controller/v2/)

# If the /api/controller/v2 API fails, fallback to /api/v2 for older AAP versions.
if [ "$response" -eq 200 ]; then
api_base='/api/controller/v2/job_templates/' # Use newer API for AAP 2.5+
else
api_base='/api/v2/job_templates/' # Fallback to older API versions
fi

[Unit]
Description=Provisioning callback to Ansible Tower
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https:///api/v2/job_templates//callback/
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https://${api_base}/callback/
ExecStartPost=/usr/bin/systemctl disable ansible-callback

[Install]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,25 @@ echo "Performing initial puppet run for --tags no_such_tag"


cat << EOF-2929810d > /etc/systemd/system/ansible-callback.service

# Attempt to use the /api/controller/v2 API for AAP 2.5 and higher. If successful, continue with newer API endpoints.
response=$(/usr/bin/curl -k -s --write-out "%{http_code}" -o /dev/null https:///api/controller/v2/)

# If the /api/controller/v2 API fails, fallback to /api/v2 for older AAP versions.
if [ "$response" -eq 200 ]; then
api_base='/api/controller/v2/job_templates/' # Use newer API for AAP 2.5+
else
api_base='/api/v2/job_templates/' # Fallback to older API versions
fi

[Unit]
Description=Provisioning callback to Ansible Tower
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https:///api/v2/job_templates//callback/
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https://${api_base}/callback/
ExecStartPost=/usr/bin/systemctl disable ansible-callback

[Install]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,25 @@ echo "Performing initial puppet run for --tags no_such_tag"


cat << EOF-2929810d > /etc/systemd/system/ansible-callback.service

# Attempt to use the /api/controller/v2 API for AAP 2.5 and higher. If successful, continue with newer API endpoints.
response=$(/usr/bin/curl -k -s --write-out "%{http_code}" -o /dev/null https:///api/controller/v2/)

# If the /api/controller/v2 API fails, fallback to /api/v2 for older AAP versions.
if [ "$response" -eq 200 ]; then
api_base='/api/controller/v2/job_templates/' # Use newer API for AAP 2.5+
else
api_base='/api/v2/job_templates/' # Fallback to older API versions
fi

[Unit]
Description=Provisioning callback to Ansible Tower
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https:///api/v2/job_templates//callback/
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https://${api_base}/callback/
ExecStartPost=/usr/bin/systemctl disable ansible-callback

[Install]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,25 @@ echo "Performing initial puppet run for --tags no_such_tag"


cat << EOF-2929810d > /etc/systemd/system/ansible-callback.service

# Attempt to use the /api/controller/v2 API for AAP 2.5 and higher. If successful, continue with newer API endpoints.
response=$(/usr/bin/curl -k -s --write-out "%{http_code}" -o /dev/null https:///api/controller/v2/)

# If the /api/controller/v2 API fails, fallback to /api/v2 for older AAP versions.
if [ "$response" -eq 200 ]; then
api_base='/api/controller/v2/job_templates/' # Use newer API for AAP 2.5+
else
api_base='/api/v2/job_templates/' # Fallback to older API versions
fi

[Unit]
Description=Provisioning callback to Ansible Tower
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https:///api/v2/job_templates//callback/
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https://${api_base}/callback/
ExecStartPost=/usr/bin/systemctl disable ansible-callback

[Install]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,25 @@ echo "Performing initial puppet run for --tags no_such_tag"


cat << EOF-2929810d > /etc/systemd/system/ansible-callback.service

# Attempt to use the /api/controller/v2 API for AAP 2.5 and higher. If successful, continue with newer API endpoints.
response=$(/usr/bin/curl -k -s --write-out "%{http_code}" -o /dev/null https:///api/controller/v2/)

# If the /api/controller/v2 API fails, fallback to /api/v2 for older AAP versions.
if [ "$response" -eq 200 ]; then
api_base='/api/controller/v2/job_templates/' # Use newer API for AAP 2.5+
else
api_base='/api/v2/job_templates/' # Fallback to older API versions
fi

[Unit]
Description=Provisioning callback to Ansible Tower
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https:///api/v2/job_templates//callback/
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https://${api_base}/callback/
ExecStartPost=/usr/bin/systemctl disable ansible-callback

[Install]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#!/bin/sh

echo "Calling Ansible AWX/Tower provisioning callback..."
/usr/bin/curl -v -k -s --data "host_config_key=" https:///api/v2/job_templates//callback/

# Attempt to use the /api/controller/v2 API for AAP 2.5 and higher. If successful, continue with newer API endpoints.
response=$(/usr/bin/curl -k -s --write-out "%{http_code}" -o /dev/null https:///api/controller/v2/)

# If the /api/controller/v2 API fails, fallback to /api/v2 for older AAP versions.
if [ "$response" -eq 200 ]; then
api_base='/api/controller/v2/job_templates/' # Use newer API for AAP 2.5+
else
api_base='/api/v2/job_templates/' # Fallback to older API versions
fi

/usr/bin/curl -v -k -s --data "host_config_key=" https://${api_base}/callback/
echo "DONE"
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@

# Attempt to use the /api/controller/v2 API for AAP 2.5 and higher. If successful, continue with newer API endpoints.
response=$(/usr/bin/curl -k -s --write-out "%{http_code}" -o /dev/null https:///api/controller/v2/)

# If the /api/controller/v2 API fails, fallback to /api/v2 for older AAP versions.
if [ "$response" -eq 200 ]; then
api_base='/api/controller/v2/job_templates/' # Use newer API for AAP 2.5+
else
api_base='/api/v2/job_templates/' # Fallback to older API versions
fi

[Unit]
Description=Provisioning callback to Ansible Tower
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https:///api/v2/job_templates//callback/
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https://${api_base}/callback/
ExecStartPost=/usr/bin/systemctl disable ansible-callback

[Install]
Expand Down
Loading
Loading