---
- name: write the config file for the api server
  template: src=apiserver.j2 dest=/etc/kubernetes/apiserver
  notify:
          - restart apiserver

- name: write the config file for the controller-manager
  copy: src=controller-manager dest=/etc/kubernetes/controller-manager
  notify:
          - restart controller-manager

- name: write the config file for the scheduler
  copy: src=scheduler dest=/etc/kubernetes/scheduler
  notify:
          - restart scheduler

- name: Enable apiserver
  service: name=kube-apiserver enabled=yes state=started

- name: Enable controller-manager
  service: name=kube-controller-manager enabled=yes state=started

- name: Enable scheduler
  service: name=kube-scheduler enabled=yes state=started

- name: Copy minion definition json files to master
  template: src=node.j2 dest=/tmp/node-{{ item }}.json
  changed_when: false
  with_items:
          groups['minions']
  when: inventory_hostname == groups['masters'][0]

- name: Load minion definition into master
  command: /usr/bin/kubectl create -f /tmp/node-{{ item }}.json
  register: command_result
  failed_when: command_result.rc != 0 and 'already exists' not in command_result.stderr
  changed_when: "command_result.rc == 0"
  with_items:
          groups['minions']
  when: inventory_hostname == groups['masters'][0]

- name: Delete minion definitions from master
  file: path=/tmp/node-{{ item }}.json state=absent
  changed_when: false
  with_items:
          groups['minions']
  when: inventory_hostname == groups['masters'][0]

- include: firewalld.yml
  when: has_firewalld

- include: iptables.yml
  when: not has_firewalld and has_iptables
