Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ansible tower pass job number to playbook

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.

like image 893
user11466558 Avatar asked May 30 '19 23:05

user11466558


People also ask

How do you pass variables in Ansible Tower?

To pass a value to nodes, use the --extra-vars or -e option while running the Ansible playbook, as seen below. This ensures you avoid accidental running of the playbook against hardcoded hosts.

How do I find my job ID in Ansible Tower?

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.

How do I add credentials in Ansible Tower?

Ansible Tower credentials have the following inputs that are required: Ansible Tower Hostname: The base URL or IP address of the other Tower instance to connect to. Username: The username to use to connect to it. Password: The password to use to connect to it.


1 Answers

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

like image 126
Uttam Avatar answered Sep 29 '22 10:09

Uttam