---
- name: Create CNI bin directory
  file:
    state: directory
    path: "{{ cni_bin_dir }}"
    mode: 0755
    owner: root
    group: root
    recurse: yes

- name: Create CNI extraction tempdir
  command: mktemp -d
  register: cni_tmpdir

- name: Download CNI
  get_url:
    url: "{{ cni_bin_url }}"
    checksum: "sha1:{{ cni_bin_checksum }}"
    mode: 0644
    dest: "{{ cni_tmpdir.stdout }}"
  register: downloaded_tarball

- name: Extract CNI
  become: yes
  unarchive:
    remote_src: True
    src: "{{ downloaded_tarball.dest }}"
    dest: "{{ cni_bin_dir }}"
  when: downloaded_tarball.changed

- name: Ensure CNI net.d exists
  file:
    path: /etc/cni/net.d
    recurse: yes
    state: directory

- name: Configure OpenShift node with disabled service proxy
  lineinfile:
    dest: "/etc/sysconfig/{{ openshift.common.service_type }}-node"
    regexp: '^OPTIONS="?(.*?)"?$'
    backrefs: yes
    backup: yes
    line: 'OPTIONS="\1 --disable dns,proxy,plugins"'

- name: force node restart to disable the proxy
  service:
    name: "{{ openshift.common.service_type }}-node"
    state: restarted
