From f72141acb28de4a4f36602b15617e1468e011405 Mon Sep 17 00:00:00 2001 From: Ricardo Carrillo Cruz Date: Mon, 4 May 2015 15:00:43 +0200 Subject: [PATCH] Checkout branch locally in idempotent manner --- .../tasks/clone_system_config_locally.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 }}"