---
- name: Update systemd units
  import_tasks: ../systemd_units.yml
  when: openshift_is_containerized | bool

- name: Update oreg value
  yedit:
    src: "{{ openshift.common.config_base }}/node/node-config.yaml"
    key: 'imageConfig.format'
    value: "{{ oreg_url | default(oreg_url_node) }}"
  when: oreg_url is defined or oreg_url_node is defined

- name: Remove obsolete docker-sdn-ovs.conf
  file:
    path: "/etc/systemd/system/docker.service.d/docker-sdn-ovs.conf"
    state: absent

# https://bugzilla.redhat.com/show_bug.cgi?id=1513054
- name: Clean up dockershim data
  file:
    path: "/var/lib/dockershim/sandbox/"
    state: absent

# https://bugzilla.redhat.com/show_bug.cgi?id=1518912
- name: Clean up IPAM data
  file:
    path: "/var/lib/cni/networks/openshift-sdn/"
    state: absent

# https://docs.openshift.com/container-platform/3.4/admin_guide/overcommit.html#disabling-swap-memory
# swapoff is a custom module in lib_utils that comments out swap entries in
# /etc/fstab and runs swapoff -a, if necessary.
- name: Disable swap
  swapoff: {}

- name: Apply 3.6 dns config changes
  yedit:
    src: /etc/origin/node/node-config.yaml
    key: "{{ item.key }}"
    value: "{{ item.value }}"
  with_items:
  - key: "dnsBindAddress"
    value: "127.0.0.1:53"
  - key: "dnsRecursiveResolvConf"
    value: "/etc/origin/node/resolv.conf"

- name: Install Node service file
  template:
    dest: "/etc/systemd/system/{{ openshift_service_type }}-node.service"
    src: "node.service.j2"
  register: l_node_unit
  when: not openshift_is_containerized | bool

- name: Reset selinux context
  command: restorecon -RF {{ openshift_node_data_dir }}/openshift.local.volumes
  when:
  - ansible_selinux is defined
  - ansible_selinux.status == 'enabled'

# NOTE: This is needed to make sure we are using the correct set
#       of systemd unit files. The RPMs lay down defaults but
#       the install/upgrade may override them in /etc/systemd/system/.
# NOTE: We don't use the systemd module as some versions of the module
#       require a service to be part of the call.
- name: Reload systemd units
  command: systemctl daemon-reload
