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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With