#!/usr/bin/ansible-playbook --module-path=../../../library/
# ./oc_project.yml -M ../../../library -e "cli_master_test=$OPENSHIFT_MASTER
---
- hosts: "{{ cli_master_test }}"
  gather_facts: no

  tasks:
  - name: create a project
    oc_project:
      display_name: operations project
      name: operations
      state: present
      description: All things operations
      node_selector:
      - ops_only=true
    register: projout
  - debug: var=projout

  - assert:
      that:
      - "projout.module_results.results['metadata']['name'] == 'operations'"
      - projout.changed
      msg: project create failed.

  - name: create a project
    oc_project:
      display_name: operations project
      name: operations
      state: present
      description: All things operations
      node_selector:
      - ops_only=true
    register: projout
  - debug: var=projout

  - assert:
      that:
      - "projout.module_results.results['metadata']['name'] == 'operations'"
      - projout.changed == False
      msg: oc_project is not idempotent

  - name: update a project
    oc_project:
      display_name: operations project one
      name: operations
      state: present
      description: All things operations
      node_selector:
      - ops_only=true
    register: projout
  - debug: var=projout

  - assert:
      that:
      - "projout.module_results.results['metadata']['annotations']['openshift.io/display-name'] == 'operations project one'"
      - projout.changed == True
      msg: project create failed.

  - name: update a project
    oc_project:
      name: operations
      state: list
    register: projout
  - debug: var=projout

  - assert:
      that:
      - "projout.module_results['metadata']['annotations']['openshift.io/display-name'] == 'operations project one'"
      - projout.changed == False
      - projout.state == 'list'
      msg: project list failed.

  - name: delete a project
    oc_project:
      name: operations
      state: absent
    register: projout
  - debug: var=projout

  - assert:
      that:
      - projout.changed == True
      msg: project delete failed.
