#!/usr/bin/ansible-playbook --module-path=../../../library/
# ./oc_env.yml -e "cli_master_test=$OPENSHIFT_MASTER
---
- hosts: "{{ cli_master_test }}"
  gather_facts: no
  user: root
  vars:
    my_env_var:
      SOMEKEY: SOMEVALUE

    check_env_var:
      name: DEFAULT_CERTIFICATE_DIR
      value: /etc/pki/tls/private

  tasks:
  - name: list environment variables from router dc
    oc_env:
      state: list
      name: router
      namespace: default
      kind: dc
    register: envout
  - debug: var=envout

  - assert:
      that:
      - "'{{ check_env_var.name }}' == '{{ envout.results[0].name }}'"
      - "{{ envout.results|length }} > 0"
      msg: "Did not find environment variables."

  - name: list environment variables from router dc
    oc_env:
      state: present
      name: router
      namespace: default
      kind: dc
      env_vars: "{{ my_env_var }}"
    register: envout
  - debug: var=envout

  - assert:
      that:
      - "'SOMEKEY' == '{{ envout.results[-1].name }}'"
      - "'SOMEVALUE' == '{{ envout.results[-1].value }}'"
      msg: "Did not find updated environment variables."

  - name: remove environment variables from router dc
    oc_env:
      state: absent
      name: router
      namespace: default
      kind: dc
      env_vars: "{{ my_env_var }}"
    register: envout
  - debug: var=envout

  - assert:
      that:
      - envout.changed == True
      msg: "state: Absent failed."

  - name: list environment variables from router dc
    oc_env:
      state: list
      name: router
      namespace: default
      kind: dc
    register: envout
  - debug: var=envout

  - assert:
      that:
      - "'SOMEKEY' != '{{ envout.results[-1].name }}'"
      - "'SOMEVALUE' != '{{ envout.results[-1].value }}'"
      msg: "Did find updated environment variables."
