- name: Copy template {{template}} to temporary file ({{tmpfile.path}})
  template: src={{roles_path}}/openshift-apps/{{app}}/templates/{{template}} dest=/etc/openshift_apps/{{os_app}}/{{objectname}}
  when: template is defined
  register: object_template

- name: Copy template {{template_fullpath}} to temporary file ({{tmpfile.path}})
  template: src={{template_fullpath}} dest=/etc/openshift_apps/{{os_app}}/{{objectname}}
  when: template_fullpath is defined and template is not defined
  register: object_template_fullpath

- name: Copy file {{file}} to temporary file ({{tmpfile.path}})
  copy: src={{roles_path}}/openshift-apps/{{app}}/files/{{file}} dest=/etc/openshift_apps/{{os_app}}/{{objectname}}
  when: file is defined and template is not defined and template_fullpath is not defined
  register: object_file

- name: Call `oc apply` on the copied file
  shell: oc -n {{os_app}} apply -f /etc/openshift_apps/{{os_app}}/{{objectname}}
  when: object_template.changed or object_template_fullpath.changed or object_file.changed
