5

I have written an Ansible playbook that needs as one of its parameters the job number that is running it so that I make add a reference to the job to a database that I maintain. How can I get the Tower template to pass this to the playbook?

Here is my current solution which is not ideal:

I first kick off the template which contains my playbook using tower-cli at which point the job number is returned to me. I then pass the job number as a parameter to another template which calls a playbook that writes the job number to the database.

Ideally I want to be able to run a single playbook via tower-cli and not worry about the job number when doing so. I would like Tower to pass the job number to the original playbook so as not to require a second playbook. Any other solutions to this problem would also be appreciated.

U880D
  • 8,601
  • 6
  • 24
  • 40
user11466558
  • 127
  • 3
  • 10

1 Answers1

6

Not sure what 'Job number' means. But, assuming you mean 'Job ID', Tower automatically adds the variables to job environment, you can get tower job id by using {{ tower_job_id }} anywhere in the playbook.

You also have access to various other variables set by tower, refer to following documentation.

Documentation

Uttam
  • 576
  • 5
  • 17