0

带有回调 url 的用户数据,我用于使用 ansible tower 配置 linux ec2 实例:

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

上面,回调 url 在塔中工作并取回配置。

我如何使用 Windows ec2 实例执行此操作,如何使用我可以放入我的用户数据的 powershell 脚本发送相同类型的请求,该脚本可以在塔中打电话并取回配置。

4

1 回答 1

1

从 Powershell 第 3 版开始,我们有了一个叫做Invoke-WebRequest的东西。您可以利用它的美丽,并可以完成相应的工作。

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

您可以以不同的方式使用它。它有很多选择来完成工作。获取 RSS 提要的另一个不错的示例:

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

此外,这些是您可以参考的选项:

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>]
于 2016-11-28T06:44:06.333 回答