mirror of
https://github.com/ansible/awx.git
synced 2026-02-01 01:28:09 -03:30
Add PowerShell version of request_tower_configuration. From @nitzmahone.
This commit is contained in:
40
tools/scripts/request_tower_configuration.ps1
Normal file
40
tools/scripts/request_tower_configuration.ps1
Normal file
@@ -0,0 +1,40 @@
|
||||
Param(
|
||||
[string]$tower_url,
|
||||
[string]$host_config_key,
|
||||
[string]$job_template_id
|
||||
)
|
||||
|
||||
Set-StrictMode -Version 2
|
||||
$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"
|
||||
Exit 1
|
||||
}
|
||||
|
||||
$retry_attempts = 10
|
||||
$attempt = 0
|
||||
|
||||
$data = @{
|
||||
host_config_key=$host_config_key
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
If($resp.StatusCode -eq 202) {
|
||||
Exit 0
|
||||
}
|
||||
}
|
||||
Catch {
|
||||
$ex = $_
|
||||
$attempt++
|
||||
Write-Host "$([int]$ex.Exception.Response.StatusCode) received... retrying in 1 minute (Attempt $attempt)"
|
||||
}
|
||||
Start-Sleep -Seconds 60
|
||||
}
|
||||
Exit 1
|
||||
Reference in New Issue
Block a user