2016-11-27 27 views
0

用户数据:电源外壳等效的命令,此命令与回调网址,我使用使用ansible塔配置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脚本发送相同类型的请求,我可以将这些请求放入我的用户数据中,这可以在塔中打电话并返回配置。

回答

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>]