5

我有一个由另一个进程启动的 Ansible 工作。现在我需要检查 Ansible Tower 中当前正在运行的作业的状态。

我可以使用REST API跟踪状态是否正在运行/成功/失败/取消/jobs/{id}

但我还需要任务的控制台日志/输出信息进行处理。是否有相同的直接 API 调用?

4

3 回答 3

4

您可以通过类似于以下的链接访问作业日志:

https://tower.yourcompany.com/api/v1/jobs/12345/stdout?format=txt_download

您的 curl 命令类似于: curl -O -k -J -L -u ${username):${password} https://tower.company.com/api/v1/jobs/${jobnumber}/stdout?format=txt_download

显然用您自己的值替换 ${username}、${password} 和 ${jobnumber}

使用的 curl 标志:

  • -O :输出实际下载的文件名
  • -k :不安全的 SSL(不需要受信任的 CA)
  • -J : 文件下载的内容头https://curl.haxx.se/docs/manpage.html#-J
  • -L :跟随重定向
  • -u : 用户名和密码
于 2018-04-13T16:19:37.937 回答
2

你可以通过他们安静的电话来做到这一点。要获取工作编号,请使用 GET 反对https://yourtowerinstance/api/v2/job_templates/ 此操作将返回您的模板及其 ID

为了实时获取输出,我使用了这个 powershell 代码

    $stdouturl = "https://yourtowerinstance/api/v2/jobs/$($templateResult.id)/stdout/?format=txt"

$resultstd = Invoke-Restmethod -uri $stdouturl -Method 'Get' -Headers $authHeader
while ($resultstd -notmatch 'PLAY RECAP') {
    $resultstd = Invoke-Restmethod -uri $stdouturl -Method 'Get' -Headers $authHeader
    start-sleep -s 5
}
$resultstd
于 2018-08-22T15:34:48.457 回答
0

启动模板后,您将获得作业 ID 作为响应,但我认为没有 API 可以获取作业的输出。但是,您可以从作业部分下的仪表板下载单个作业输出。

于 2018-02-22T17:53:31.280 回答