Checkout branch locally in idempotent manner

This commit is contained in:
Ricardo Carrillo Cruz 2015-05-04 15:00:43 +02:00
parent 1b2aeebdbf
commit f72141acb2
1 changed files with 15 additions and 1 deletions

View File

@ -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 }}"