From 3b83922517b48b0e38e8d610eda54b49c5c46b4e Mon Sep 17 00:00:00 2001 From: Matthew Sevey Date: Fri, 2 Sep 2022 11:37:41 -0400 Subject: [PATCH] handle git tags and git branches --- playbooks/tasks/ansible-repo-version-get.yml | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/playbooks/tasks/ansible-repo-version-get.yml b/playbooks/tasks/ansible-repo-version-get.yml index 31824362..9450aaee 100644 --- a/playbooks/tasks/ansible-repo-version-get.yml +++ b/playbooks/tasks/ansible-repo-version-get.yml @@ -14,11 +14,32 @@ cmd: git symbolic-ref --short HEAD run_once: True register: ans_git_branch + # Ignore errors here because if ansible-playbooks is on a tag this command + # will fail. In that case the block below will determine the tag. + ignore_errors: True - name: Set Ansible repo branch set_fact: local_ansible_repo_branch: "{{ ans_git_branch.stdout }}" run_once: True + when: ans_git_branch is defined + +- block: + # Do not ignore errors here, because we should be able to determine a tag in + # the even a branch is not used. + - name: Get Ansible repo tag + local_action: + module: ansible.builtin.command + cmd: git describe --tags + run_once: True + register: ans_git_tag + + - name: Set Ansible repo branch + set_fact: + local_ansible_repo_branch: "{{ ans_git_tag.stdout }}" + run_once: True + + when: ans_git_branch is not defined and local_ansible_repo_branch is not defined - name: Get Ansible repo commit local_action: