Skip to content

EXAMPLE-tower-job-poll

EXAMPLE: AWX / Tower job via polling

Warning

THIS IS AN EXAMPLE - you must modify values to fit your local environment appropriately. Replace the bearer token, review the extra_vars payload, and confirm the URLs match your AWX / Tower deployment before applying to a real machine.

Launches an AWX / Tower job template and polls for completion using the exponential-backoff strategy. The example values target a generic tower.example.com host and job template id 399 with a sample network-fabric extra_vars payload; replace these for your site.

What this profile does

  1. POSTs to /api/v2/job_templates/399/launch/ with the configured extra_vars payload (datacenter, action, servers list).
  2. Captures the job ID from the launch response (top-level id field).
  3. Records id, url, and status from the launch response as inventory/tower/* adhoc Params on the Machine for audit.
  4. Polls /api/v2/jobs/<id>/ with exponential backoff:
    • Initial sleep: 10 seconds
    • Doubled each iteration: 10, 20, 40, 60, 60, ...
    • Capped at: 60 seconds (max-interval)
    • Total max wait: 900 seconds (15 minutes)
  5. Treats the top-level status field of each poll response as:
    • successful -> terminal success (exit 0, clear state)
    • pending / waiting / running -> continue waiting
    • failed / error / canceled -> terminal failure (exit 1, state=failure)
    • anything else -> terminal failure with "unexpected status"

The wait and failure slots are configured as arrays so the full AWX state machine (multiple non-terminal and multiple terminal-failure states) is handled cleanly. The first poll can land on pending or waiting without misclassification.

TLS verification

This profile leaves tower/skip-tls-verify at the default true, bypassing certificate validation. Set to false if the DRP endpoint trusts the certificate chain for your AWX / Tower host.

Required operator input

Before applying, replace the placeholder value of tower/bearer-token with a real AWX OAuth2 bearer token that has permission to launch job template 399. The placeholder is intentionally invalid so a forgotten replacement fails fast with a 401 at POST time.

Recovery after a non-success terminal

If polling times out (max-time-expired) or fails (failure), the machine retains tower/job-poll-state and tower/job-id. See the Operator Recovery section of the tower-invoke-curl task for the two recovery workflows (resume on existing job ID, or start fresh).

Objects that Reference EXAMPLE-tower-job-poll

Not used in current content packs

Objects used by EXAMPLE-tower-job-poll