diff --git a/roles/deploy_system_config/tasks/clone_system_config_locally.yml b/roles/deploy_system_config/tasks/clone_system_config_locally.yml index 3159b21..f444eb8 100644 --- a/roles/deploy_system_config/tasks/clone_system_config_locally.yml +++ b/roles/deploy_system_config/tasks/clone_system_config_locally.yml @@ -2,7 +2,21 @@ # Clone system-config locally in the command machine - git: repo="{{ system_config_repo_url }}" dest=/tmp/infra-ansible/system-config/production - version="{{ system_config_branch }}" accept_hostkey=True force=True tags: clone_system_config_locally + +- command: git symbolic-ref --short -q HEAD + args: + chdir: /tmp/infra-ansible/system-config/production + register: checked_out_branch + +- command: git show-ref --verify --quiet "{{ system_config_branch }}" + register: system_config_branch_exists + ignore_errors: True + +- command: git checkout -b "{{ system_config_branch }}" + when: system_config_branch_exists|failed + +- command: git checkout "{{ system_config_branch }}" + when: system_config_branch_exists|success and checked_out_branch.stdout != "{{ system_config_branch }}"