---
- name: Copy template {{object_template}} to temporary file ({{tmpfile.path}})
  ansible.builtin.template: src={{roles_path}}/openshift-apps/{{object_app}}/templates/{{object_template}} dest=/etc/openshift_apps/{{object_os_app}}/{{object_objectname}}
  when: object_template is defined
  register: object_template_result

- name: Copy template {{object_template_fullpath}} to temporary file ({{tmpfile.path}})
  ansible.builtin.template: src={{object_template_fullpath}} dest=/etc/openshift_apps/{{object_os_app}}/{{object_objectname}}
  when: object_template_fullpath is defined and object_template is not defined
  register: object_template_fullpath_result

- name: Copy file {{object_file}} to temporary file ({{tmpfile.path}})
  ansible.builtin.copy: src={{roles_path}}/openshift-apps/{{object_app}}/files/{{object_file}} dest=/etc/openshift_apps/{{object_os_app}}/{{object_objectname}}
  when: object_file is defined and object_template is not defined and object_template_fullpath is not defined
  register: object_file_result

- name: Call `oc apply` on the copied file
  ansible.builtin.shell: oc -n {{object_os_app}} apply --validate=strict -f /etc/openshift_apps/{{object_os_app}}/{{object_objectname}}
  when: object_template_result.changed or object_template_fullpath_result.changed or object_file_result.changed or object_always_apply
