I'm in the process of migrating Ansible playbooks into Ansible AWX projects.
Previously I'd checkout the Ansible playbook from git, then run it from the command line.
In this specific case I have a Ansible Playbook that creates VMware virtual machines. I use the following tasks to gather information about the git repo and current git commit hash, and use this info in the VM annotations, so that it can be later used to identify the exact instructions used to create the VM.
- name: return git commit hash
command: git rev-parse HEAD
register: gitCommitHash
delegate_to: localhost
become: false
become_user: "{{ lookup('env','USER') }}"
- name: get remote git repo
command: git config --get remote.origin.url
register: gitRemote
delegate_to: localhost
become: false
become_user: "{{ lookup('env','USER') }}"
I realize that playbooks run in AWX run as the awx
user.
Is there anyway, in a playbook, I can get the AWX user that is running the AWX template, and can I get the url for the Ansible AWX project?
Update
I found I can get the AWX that is running the template by using the {{awx_user_name}}
, but have not yet found out how to get the git remote url of the project/playbook.