---
- name: Check that node image is present
  command: 'docker images -q "{{ osn_image }}"'
  register: node_image

# This task runs async to save time while the node is being configured
- name: Pre-pull node image
  docker_image:
    name: "{{ osn_image }}"
  environment:
    NO_PROXY: "{{ openshift.common.no_proxy | default('') }}"
  when: node_image.stdout_lines == []
  # 10 minutes to pull the image
  async: 600
  poll: 0
  register: image_prepull

- name: Install the systemd units
  import_tasks: systemd_units.yml

- file:
    dest: "{{ l2_openshift_node_kubelet_args['config'] }}"
    state: directory
  when: ('config' in l2_openshift_node_kubelet_args) | bool

- name: Configure Node Environment Variables
  lineinfile:
    dest: /etc/sysconfig/{{ openshift_service_type }}-node
    regexp: "^{{ item.key }}="
    line: "{{ item.key }}={{ item.value }}"
    create: true
  with_dict: "{{ openshift_node_env_vars }}"

- name: Ensure the node static pod directory exists
  file:
    path: "{{ openshift.common.config_base }}/node/pods"
    state: directory
    mode: 0755

- name: Create flexvolume directory when running on atomic
  file:
    state: directory
    path: "/etc/origin/kubelet-plugins/volume/exec"
    mode: '0750'
  when: openshift_is_atomic | bool

- name: include aws provider credentials
  import_tasks: aws.yml
  when: not (openshift_node_use_instance_profiles | default(False))

- name: Check status of node image pre-pull
  async_status:
    jid: "{{ image_prepull.ansible_job_id }}"
  register: job_result
  until: job_result.finished
  when:
  - node_image.stdout_lines == []
  - not openshift_is_atomic | bool
  retries: 20
  delay: 30
  failed_when: false
