---
- name: Check that EFS File System ID is set
  fail: msg='the openshift_provisioners_efs_fsid variable is required'
  when: (openshift_provisioners_efs | bool) and openshift_provisioners_efs_fsid is not defined

- name: Check that EFS region is set
  fail: msg='the openshift_provisioners_efs_region variable is required'
  when: (openshift_provisioners_efs | bool) and openshift_provisioners_efs_region is not defined

- name: Check that EFS AWS access key id is set
  fail: msg='the openshift_provisioners_efs_aws_access_key_id variable is required'
  when: (openshift_provisioners_efs | bool) and openshift_provisioners_efs_aws_access_key_id is not defined

- name: Check that EFS AWS secret access key is set
  fail: msg='the openshift_provisioners_efs_aws_secret_access_key variable is required'
  when: (openshift_provisioners_efs | bool) and openshift_provisioners_efs_aws_secret_access_key is not defined

- name: Ensure that Provisioners has nodes to run on
  import_role:
    name: openshift_master
    tasks_from: ensure_nodes_matching_selector.yml
  vars:
    openshift_master_ensure_nodes_selector: "{{ openshift_provisioners_efs_nodeselector | map_to_pairs }}"
    openshift_master_ensure_nodes_service: Provisioners

- name: Install support
  include_tasks: install_support.yaml

- name: Install EFS
  include_tasks: install_efs.yaml
  when: openshift_provisioners_efs | bool

- find: paths={{ mktemp.stdout }}/templates patterns=*.yaml
  register: object_def_files
  changed_when: no

- slurp: src={{item}}
  register: object_defs
  with_items: "{{object_def_files.files | map(attribute='path') | list | sort}}"
  changed_when: no

- name: Create objects
  include_tasks: oc_apply.yaml
  vars:
  - kubeconfig: "{{ mktemp.stdout }}/admin.kubeconfig"
  - namespace: "{{ openshift_provisioners_project }}"
  - file_name: "{{ file.source }}"
  - file_content: "{{ file.content | b64decode | from_yaml }}"
  with_items: "{{ object_defs.results }}"
  loop_control:
    loop_var: file
  when: not ansible_check_mode

- name: Printing out objects to create
  debug: msg={{file.content | b64decode }}
  with_items: "{{ object_defs.results }}"
  loop_control:
    loop_var: file
  when: ansible_check_mode

- name: Scaling up cluster
  include_tasks: start_cluster.yaml
  when: start_cluster | default(true) | bool
