---
- block:
    - name: Gather facts
      openshift_facts:
        role: common

    - name: Create the validation project
      command: "{{ openshift.common.client_binary }} new-project {{ project }}"

    - name: Create Hello world app
      shell: "{{ openshift.common.client_binary }} new-app {{ app }}"

    - name: Wait for build to complete
      shell: "{{ openshift.common.client_binary }} get pod | grep -v deploy | awk '/{{ app }}-1-build/{ print $3 }'"
      register: build_output
      until: build_output.stdout | search("Completed")
      retries: 30
      delay: 15

    - name: Wait for App to be running
      shell: "{{ openshift.common.client_binary }} get pod | grep -v deploy | grep -v build  | awk '/{{ app }}-1-*/{print $3}'"
      register: deployer_output
      until: deployer_output.stdout | search("Running")
      retries: 30
      delay: 15

    - name: Sleep to allow for route propegation
      pause:
        seconds: 10

    - name: check the status of the page
      uri:
        url: "http://{{ app }}-{{ project }}.{{ hostvars['localhost']['wildcard_zone'] }}"
        status_code: 200
        method: GET

  always:
    - name: Delete the Project
      command: "{{ openshift.common.client_binary }} delete project {{ project }}"
