---
# clone our other repositories into this repo
# NOTE: since you can't loop against blocks (and we're using them for failure #
#       recovery when the request branch doesn't exist) we have to define each
#       of these separately rather than using a loop.
- name: Get Smart Gateway Operator
  block:
    - name: Try cloning same-named branch or override branch
      git:
        repo: https://github.com/infrawatch/smart-gateway-operator
        dest: working/smart-gateway-operator
        version: "{{ sgo_branch | default(branch, true) }}"
  rescue:
    - name: Get master branch because same-named doesn't exist
      git:
        repo: https://github.com/infrawatch/smart-gateway-operator
        dest: working/smart-gateway-operator
        version: master

- name: Get sg-core
  block:
    - name: Try cloning same-named branch or override branch
      git:
        repo: https://github.com/infrawatch/sg-core
        dest: working/sg-core
        version: "{{ sg_core_branch | default(branch, true) }}"
  rescue:
    - name: Get master branch because same-named doesn't exist
      git:
        repo: https://github.com/infrawatch/sg-core
        dest: working/sg-core
        version: master

- name: Get sg-bridge
  block:
    - name: Try cloning same-named branch or override branch
      git:
        repo: https://github.com/infrawatch/sg-bridge
        dest: working/sg-bridge
        version: "{{ sg_bridge_branch | default(branch, true) }}"
  rescue:
    - name: Get master branch because same-named doesn't exist
      git:
        repo: https://github.com/infrawatch/sg-bridge
        dest: working/sg-bridge
        version: master

- name: Get prometheus-webhook-snmp
  block:
    - name: Try cloning same-named branch or override branch
      git:
        repo: https://github.com/infrawatch/prometheus-webhook-snmp
        dest: working/prometheus-webhook-snmp
        version: "{{ prometheus_webhook_snmp_branch | default(branch, true) }}"
  rescue:
    - name: Get master branch because same-named doesn't exist
      git:
        repo: https://github.com/infrawatch/prometheus-webhook-snmp
        dest: working/prometheus-webhook-snmp
        version: master
