---
- name: include package installs
  import_tasks: install_rpms.yml
  when: not (openshift_is_atomic | default(False) | bool)

- name: create the directory for node
  file:
    state: directory
    path: "/etc/systemd/system/{{ openshift_service_type }}-node.service.d"
  when: '"cloud-init" in r_openshift_node_image_prep_packages'

- name: laydown systemd override
  copy:
    dest: "/etc/systemd/system/{{ openshift_service_type }}-node.service.d/override.conf"
    content: |
      [Unit]
      After=cloud-init.service
  when: '"cloud-init" in r_openshift_node_image_prep_packages'

- name: update the sysconfig to have necessary variables
  lineinfile:
    dest: "/etc/sysconfig/{{ openshift_service_type }}-node"
    line: "{{ item.line | default(omit) }}"
    regexp: "{{ item.regexp }}"
    state: "{{ item.state | default('present') }}"
  with_items:
  # add the kubeconfig
  - line: "KUBECONFIG={{ openshift_node_config_dir }}/bootstrap.kubeconfig"
    regexp: "^KUBECONFIG=.*"

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

- name: "disable {{ openshift_service_type }}-node service"
  systemd:
    name: "{{ item }}"
    enabled: no
  with_items:
  - "{{ openshift_service_type }}-node.service"

- name: create directories for bootstrapping
  file:
    state: directory
    dest: "{{ item }}"
  with_items:
  - /root/openshift_bootstrap
  - /var/lib/origin/openshift.local.config
  - /var/lib/origin/openshift.local.config/node
  - "/etc/docker/certs.d/docker-registry.default.svc:5000"

- name: laydown the bootstrap.yml file for on boot configuration
  template:
    src: bootstrap.yml.j2
    dest: /root/openshift_bootstrap/bootstrap.yml

- name: Create a symlink to the node client CA for the docker registry
  file:
    src: "{{ openshift_node_config_dir }}/client-ca.crt"
    dest: "{{ item }}"
    state: link
    force: yes
    follow: no
  with_items:
  - "/etc/docker/certs.d/docker-registry.default.svc:5000/node-client-ca.crt"
  - "/etc/pki/ca-trust/source/anchors/node-client-ca.crt"
