---
# tasks file for ansible-ansible-openshift-ansible
#

- name: Install required packages
  package: name="{{ item }}" state=present
  with_items:
    - ansible
    - git
    - pyOpenSSL
    - ca-certificates
  tags:
  - ansible-ansible-openshift-ansible
  - ansible-ansible-openshift-ansible-config

- name: git clone the openshift-ansible repo
  git:
    repo: "https://github.com/openshift/openshift-ansible.git"
    dest: "{{ openshift_ansible_path }}"
    version: "{{ openshift_ansible_version }}"
  tags:
  - ansible-ansible-openshift-ansible
  - ansible-ansible-openshift-ansible-config
  ignore_errors: true

- name: generate the inventory file (staging)
  template:
    src: "cluster-inventory-stg.j2"
    dest: "{{ openshift_ansible_path }}/{{ cluster_inventory_filename }}"
  tags:
  - ansible-ansible-openshift-ansible
  - ansible-ansible-openshift-ansible-config
  when: env == 'staging' and inventory_hostname.startswith('os-')

- name: generate the inventory file (production) (iad2)
  template:
    src: "cluster-inventory-iad2-prod.j2"
    dest: "{{ openshift_ansible_path }}/{{ cluster_inventory_filename }}"
  tags:
  - ansible-ansible-openshift-ansible
  - ansible-ansible-openshift-ansible-config
  when: env == 'production' and inventory_hostname.startswith('os-') and datacenter == 'iad2'

- name: generate the inventory file (osbs)
  template:
    src: "cluster-inventory-osbs.j2"
    dest: "{{ openshift_ansible_path }}/{{ cluster_inventory_filename }}"
  tags:
  - ansible-ansible-openshift-ansible
  - ansible-ansible-openshift-ansible-config
  when: inventory_hostname.startswith('osbs')

- name: run ansible prereqs playbook
  shell: "ansible-playbook {{ openshift_ansible_pre_playbook }} -i {{ cluster_inventory_filename }}"
  args:
    chdir: "{{ openshift_ansible_path }}"
  register: run_ansible_out
  when: openshift_ansible_pre_playbook is defined and openshift_ansible_upgrading is defined
  tags:
  - ansible-ansible-openshift-ansible

- name: run ansible
  shell: "ansible-playbook {{ openshift_ansible_playbook }} -i {{ cluster_inventory_filename }}"
  args:
    chdir: "{{ openshift_ansible_path }}"
  register: run_ansible_out
  tags:
  - ansible-ansible-openshift-ansible
  when: openshift_ansible_upgrading is defined

- name: display run ansible stdout_lines
  debug:
    var: run_ansible_out.stdout_lines
  tags:
  - ansible-ansible-openshift-ansible

- name: display run ansible stderr
  debug:
    var: run_ansible_out.stderr
  tags:
  - ansible-ansible-openshift-ansible
