powershell - powershell 向 AWX 调用 rest api
问题描述
上周或更长时间,我一直在努力从 powershell 发送 rest api 命令以在 AWX 中添加主机(来自 curl 正在工作)。当我发送一个参数是 worki 但我还需要发送变量
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Basic $VfAwxTokenX")
$Headers.Add('Content-Type', 'application/json')
$body = @{
name = '$vmname'
variables = 'test'
}| ConvertTo-Json
write-output $body
$response = Invoke-RestMethod 'https://awx/api/v2/inventories/2/hosts/' -Method 'POST' -Headers $headers -UseBasicParsing -Body $body
和我得到的错误:
{ "name": "wewewe", "variables": "test" } Invoke-RestMethod : {"variables":["Cannot parse as JSON (error: Expecting value: line 1 column 1 (char 0)) 或 YAML (错误:输入类型
str
不是字典)。"]} 在 line:32 char:13
- $response = Invoke-RestMethod 'https://awx/api ...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
- FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
也许任何一个用户都有这个问题,现在如何克服它?
解决方案
推荐阅读
- shell - 您可以通过读取该文件执行 shell 命令吗?
- javascript - 导致不兼容类型的乘法在 ES6 中引发错误
- html - 第一个孩子和列表中的列表
- ruby-on-rails - Rails (5.2.0) reCaptcha Devise (4.4.3) 未定义方法 users_url
- scala - 存储为字符串变量时如何执行spark sql多行查询?
- .net - 使用 ngen.exe 时 System.Numerics.Vector.IsHardwareAccelerated = false
- sql - SQL Server:CASE 语句中的 OR 语句
- spring-batch - Spring Batch 将运行哪个配置?
- javascript - 是否可以从 iframe 中重定向到新的来源?
- clojurescript - 在 ClojureScript 中使用 MathJax