在Ansible塔CLI中同时启动和监控作业

时间:2017-12-05 21:15:07

标签: ansible ansible-tower

我们安装了Ansible Tower并实施了CLI工具。我们可以使用以下命令在CLI中启动作业 -

tower-cli job launch -J 5

这样返回输出 -

Resource changed.
=== ============ ======================== ======= ======= 
id  job_template         created          status  elapsed 
=== ============ ======================== ======= ======= 
119            5 2017-12-05T20:26:31.197Z pending 0.0
=== ============ ======================== ======= ======= 

然后我们可以像这样监控状态 -

tower-cli job monitor 119

是否可以以某种方式将ID的输入传递给monitor cli参数(或者是否可以同时运行两者)?由于我们在服务器上运行多个作业,因此我们需要能够每次都可靠地获取作业ID。

当我在http://tower-cli.readthedocs.io/en/latest/cli_ref/index.html阅读文档时,我没有看到任何相关信息。

感谢。

2 个答案:

答案 0 :(得分:2)

我使用的是tower-cli版本Tower CLI 3.3.0。我运行了tower-cli job launch --help,它提供了以下相关命令:

--monitor              If sent, immediately calls `job monitor` on the
                       newly launched job rather than exiting with a
                       success.
--wait                 Monitor the status of the job, but do not print
                       while job is in progress.

所以我认为您可以执行以下操作:

tower-cli job launch -J 5 --monitor

(在我的CI版本中运行此命令时,我会添加--wait命令,这就是我在上面添加它的原因)

答案 1 :(得分:1)

我通过执行以下操作来修复此问题 -

OUTPUT="$(tower-cli job launch -J 5 | grep -o '[0-9]*' | head -1 )"
tower-cli monitor $OUTPUT
相关问题