---
- name: install repositories
  include: yum_repos.yml
  static: yes

- name: install needed rpm(s)
  package:
    name: "{{ item }}"
    state: present
  with_items: "{{ r_openshift_ami_prep_packages }}"

- name: create the directory for node
  file:
    state: directory
    path: "/etc/systemd/system/{{ r_openshift_ami_prep_node }}.service.d"

- name: laydown systemd override
  copy:
    dest: "/etc/systemd/system/{{ r_openshift_ami_prep_node }}.service.d/override.conf"
    content: |
      [Unit]
      After=cloud-init.service

- name: update the sysconfig to have KUBECONFIG
  lineinfile:
    dest: "/etc/sysconfig/{{ r_openshift_ami_prep_node }}"
    line: "KUBECONFIG=/root/csr_kubeconfig"
    regexp: "^KUBECONFIG=.*"

- name: update the ExecStart to have bootstrap
  lineinfile:
    dest: "/usr/lib/systemd/system/{{ r_openshift_ami_prep_node }}.service"
    line: "{% raw %}ExecStart=/usr/bin/openshift start node --bootstrap --kubeconfig=${KUBECONFIG} $OPTIONS{% endraw %}"
    regexp: "^ExecStart=.*"

- name: systemctl enable origin-node
  systemd:
    name: "{{ item }}"
    enabled: no
  with_items:
  - "{{ r_openshift_ami_prep_node }}.service"
  - "{{ r_openshift_ami_prep_master }}.service"
