I have a playbook which needs its own version at runtime to deploy various configuration.
Today I use a script which takes a version
parameter then git clone/checkout to this version and finally call ansible-playbook with -e project_version=$version
.
This is fine and all but now I would like to use AWX instead.
There is the "SCM Branch" parameter when launching a job, but it doesn't seem to be exposed during the playbook run.
Is there a proper way to do this?
Here are the (ugly) workarounds I could think of:
- Manually add the
project_version
extra variable when launching the AWX job (so the version has to be entered twice each time) - Change the playbook to retrieve the git tag/branch/commit label at runtime (which is not so simple because AWX does not do a proper git clone)
- Bypass AWX by making it checkout an intermediary project (closer to my existing script)
If you want to know the commit number you can use the variable
awx_project_revision
in AWX andtower_project_revision
in Ansible Tower. Those variables are added to the job environment automatically when you run your template.