mirror of
https://github.com/ansible/awx.git
synced 2026-02-17 19:20:05 -03:30
Updates to callback scripts that include retry functionality for bash and extra_vars handling for PowerShell
Signed-off-by: Rob Ruma <robruma@users.noreply.github.com>
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
Param(
|
||||
[string]$tower_url,
|
||||
[string]$host_config_key,
|
||||
[string]$job_template_id
|
||||
[string]$job_template_id,
|
||||
[string]$extra_vars
|
||||
)
|
||||
|
||||
Set-StrictMode -Version 2
|
||||
@@ -10,24 +11,36 @@ $ErrorActionPreference = "Stop"
|
||||
If(-not $tower_url -or -not $host_config_key -or -not $job_template_id)
|
||||
{
|
||||
Write-Host "Requests server configuration from Ansible Tower"
|
||||
Write-Host "Usage: $($MyInvocation.MyCommand.Name) <server address>[:server port] <host config key> <job template id>"
|
||||
Write-Host "Example: $($MyInvocation.MyCommand.Name) example.towerhost.net 44d7507f2ead49af5fca80aa18fd24bc 38"
|
||||
Write-Host "Usage: $($MyInvocation.MyCommand.Name) https://<server address>[:server port] <host config key> <job template id>"
|
||||
Write-Host "Example: $($MyInvocation.MyCommand.Name) https://example.towerhost.net 44d7507f2ead49af5fca80aa18fd24bc 38"
|
||||
Write-Host "Example with extra_vars: $($MyInvocation.MyCommand.Name) https://example.towerhost.net 44d7507f2ead49af5fca80aa18fd24bc 38 '{ key: value, dict: { key: value }}'"
|
||||
Exit 1
|
||||
}
|
||||
|
||||
$retry_attempts = 10
|
||||
$attempt = 0
|
||||
|
||||
$data = @{
|
||||
host_config_key=$host_config_key
|
||||
If(-not $extra_vars)
|
||||
{
|
||||
$data = @{
|
||||
host_config_key=$host_config_key
|
||||
}
|
||||
} Else {
|
||||
$data = @{
|
||||
host_config_key=$host_config_key
|
||||
extra_vars=$extra_vars
|
||||
}
|
||||
}
|
||||
|
||||
While ($attempt -lt $retry_attempts) {
|
||||
Try {
|
||||
$resp = Invoke-WebRequest -Method POST -Body $data -Uri http://$tower_url/api/v1/job_templates/$job_template_id/callback/ -UseBasicParsing
|
||||
$resp = Invoke-WebRequest -ContentType application/json -Method POST -Body (ConvertTo-Json $data) -Uri $tower_url/api/v2/job_templates/$job_template_id/callback/
|
||||
|
||||
If($resp.StatusCode -eq 202) {
|
||||
If ($resp.StatusCode -match '^2[0-9]+$') {
|
||||
Exit 0
|
||||
} ElseIf ($resp.StatusCode -eq 404) {
|
||||
Write-Host "$resp.StatusCode received... encountered problem, halting"
|
||||
Exit 1
|
||||
}
|
||||
}
|
||||
Catch {
|
||||
@@ -37,4 +50,4 @@ While ($attempt -lt $retry_attempts) {
|
||||
}
|
||||
Start-Sleep -Seconds 60
|
||||
}
|
||||
Exit 1
|
||||
Exit 1
|
||||
|
||||
Reference in New Issue
Block a user