---
- name: Create project directory
  file:
    path: /etc/openshift_apps/{{app}}
    state: directory
    owner: root
    group: root
    mode: 0750
    recurse: yes

- name: Determine if project already exists
  command: oc get project {{app}}
  register: project_exists
  failed_when: false
  changed_when: "'not found' in project_exists.stderr"

- name: Copy project template
  template:
    src="{{roles_path}}/openshift/project/templates/project.yml"
    dest=/etc/openshift_apps/{{app}}/project.yml

- name: Create project
  shell: oc apply -f /etc/openshift_apps/{{app}}/project.yml
  when: "'not found' in project_exists.stderr" 

- name: deployer.yml
  include_role:
    name: openshift/object
  vars:
    objectname: deployer.yml
    template_fullpath: "{{roles_path}}/openshift/project/templates/deployer.yml"

- name: imagebuilder.yml
  include_role:
    name: openshift/object
  vars:
    objectname: imagebuilder.yml
    template_fullpath: "{{roles_path}}/openshift/project/templates/imagebuilder.yml"

- name: imagepuller.yml
  include_role:
    name: openshift/object
  vars:
    objectname: imagepuller.yml
    template_fullpath: "{{roles_path}}/openshift/project/templates/imagepuller.yml"

- name: role-appowners.yml
  include_role:
    name: openshift/object
  vars:
    objectname: role-appowners.yml
    template_fullpath: "{{roles_path}}/openshift/project/templates/role-appowners.yml"

- name: appowners.yml
  include_role:
    name: openshift/object
  vars:
    objectname: appowners.yml
    template_fullpath: "{{roles_path}}/openshift/project/templates/appowners.yml"
