0

user data with call back url that i use to configure linux ec2 instances using ansible tower:

#!/bin/bash
curl --data "host_config_key=XXXXXXXXXXXXXXXXXXXXXXXXX"           
https://10.XX.XXX.XXX:443/api/v1/job_templates/646/callback/ -k

Above, the call back url works it phones in tower and gets back the config.

How do i do this with windows ec2 instances, how do i send the same kind of request using powershell script that i can put in my user data, that can phone in tower and get the configuration back.

chandra
  • 693
  • 3
  • 8
  • 21

1 Answers1

1

From Powershell Version 3 onwards, we have something called Invoke-WebRequest. You can utilize the beauty of it and can get the corresponding work done.

$postParams = @{host_config_key='XXXXXXXXXXXXXXXXXXXXXXXXX'}
Invoke-WebRequest -Uri https://10.XX.XXX.XXX:443/api/v1/job_templates/646/callback/ -Method POST -Body $postParams

You can use it in different ways. It has tons of option to get work done. Another nice Example for Getting RSS feed:

Invoke-RestMethod -Uri http://blogs.msdn.com/powershell/rss.aspx | Format-Table -Property Title, pubDate

Further, these are the options you can utilize for your reference:

Invoke-RestMethod [-Method <WebRequestMethod>] [-UseBasicParsing] [-Uri] <Uri>
 [-WebSession <WebRequestSession>] [-SessionVariable <String>] [-Credential <PSCredential>]
 [-UseDefaultCredentials] [-CertificateThumbprint <String>] [-Certificate <X509Certificate>]
 [-UserAgent <String>] [-DisableKeepAlive] [-TimeoutSec <Int32>] [-Headers <IDictionary>]
 [-MaximumRedirection <Int32>] [-Proxy <Uri>] [-ProxyCredential <PSCredential>] [-ProxyUseDefaultCredentials]
 [-Body <Object>] [-ContentType <String>] [-TransferEncoding <String>] [-InFile <String>] [-OutFile <String>]
 [-PassThru] [<CommonParameters>]
Ranadip Dutta
  • 8,857
  • 3
  • 29
  • 45