1

We have installed Ansible Tower and have the CLI tools implemented. We can launch jobs in the CLI using the following -

tower-cli job launch -J 5

This returns the output like so -

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

And then we can monitor the status like this -

tower-cli job monitor 119.

Is it possible to pass the input of ID into the monitor cli argument in some way (or is it possible to run both at the same time)? Since we have multiple jobs running on the server, we would need to be able to reliably get the job id each time.

I didn't see anything about this when I read over the documentation at http://tower-cli.readthedocs.io/en/latest/cli_ref/index.html.

Thanks.

J. Doe
  • 1,479
  • 5
  • 25
  • 49

2 Answers2

3

I'm on tower-cli version Tower CLI 3.3.0. I ran tower-cli job launch --help which gave the following, related commands:

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

So I think you can just do the following:

tower-cli job launch -J 5 --monitor

(I add the --wait command when I'm running this in my CI build, which is why I included it above)

Patrick
  • 46
  • 4
2

I fixed this by doing the following -

OUTPUT="$(tower-cli job launch -J 5 | grep -o '[0-9]*' | head -1 )"
tower-cli monitor $OUTPUT
J. Doe
  • 1,479
  • 5
  • 25
  • 49