Add git branch info to the list of default labels sent to the ARA Api
What is the idea ?
- component: ansible plugins
- linux distribution: All
- version of python: All
- version of ara and ansible: All
- how is ara installed: Any installation method Including the git branch info as a label sent to the api server would prove a great assistance to people who are testing changes and improvements in dev and feature branchs of their ansible repos. Adding this label would allow for better sorting and provide a great function to businesses as they would be able to see if a play is a production run or potentially a dev tested run.
It could be added as simply as
import subprocess
...
(line 250)
def get_branch_info(self):
command = "git symbolic-ref --short HEAD"
try:
out = subprocess.check_output(command.split())
branch = out.decode().rstrip()
except Exception as e:
print('Couldn\'t find git branch information, sending None')
print(e)
branch = "None"
return branch
(line 300)
argument_labels.append("git-branch:{0}".format(self.get_branch_info()))
I elected to use "None" as my fallback for when git is not accessible or in use.
Hi @lanceofwhichwedream and thanks for the issue.
Argument labels are meant to automatically apply labels based on the Ansible CLI arguments and so git information isn't in scope.
Depending on your use case, ara_record might work -- the example in the docs is in fact about recording git info.
Otherwise, if you'd rather have labels instead, you could pass labels dynamically in one of two ways:
ansible-playbook foo.yml -e "ara_playbook_labels=$(git rev-parse HEAD)"would set labels and have precedence ifara_playbook_labelsis defined elsewhere (because it's how extra-vars work in Ansible)export ARA_DEFAULT_LABELS="$(git rev-parse HEAD)"; ansible-playbook foo.ymldefines a list of extra labels to apply in addition toara_playbook_labels.
Would any of the above be good alternatives ?
@dmsimard
Thanks for taking a look at this. My idea was to have it as an automatic feature. In particular, I wanted to integrate it with an awx instance, however when I used my snippet I found that the branch was not named as I had expected it to be. Personally, I'm a fan of having it automated in this fashion still as it does save the need to have additional flags typed.
Maybe a compromise could be something to allow users to add in their own "label plugins"? That would still allow for the behavior I was intending while allowing users additional configurability.