---
- name: Create temp directory for doing work in
  command: mktemp -d /tmp/openshift-hosted-ansible-XXXXXX
  register: mktempHosted
  changed_when: False
  check_mode: no

- name: Generate GlusterFS registry endpoints
  template:
    src: "glusterfs-registry-endpoints.yml.j2"
    dest: "{{ mktempHosted.stdout }}/glusterfs-registry-endpoints.yml"

- name: Generate GlusterFS registry service
  template:
    src: "glusterfs-registry-service.yml.j2"
    dest: "{{ mktempHosted.stdout }}/glusterfs-registry-service.yml"

- name: Create GlusterFS registry service and endpoint
  command: >
    {{ openshift_client_binary }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig
    apply -f {{ item }} -n {{ openshift_hosted_registry_namespace | default('default') }}
  with_items:
  - "{{ mktempHosted.stdout }}/glusterfs-registry-service.yml"
  - "{{ mktempHosted.stdout }}/glusterfs-registry-endpoints.yml"

- name: Delete temp directory
  file:
    name: "{{ mktempHosted.stdout }}"
    state: absent
  changed_when: False
  check_mode: no
