- hosts: master
  become: yes
  tasks:
    - name: initialise the cluster
      shell: kubeadm init --pod-network-cidr=10.244.0.0/16 >> cluster_initialized.txt
      args:
        chdir: $HOME
        creates: cluster_initialized.txt
      become: yes
      become_user: root

    - name: create .kube directory
      become: yes
      become_user: ubuntu
      file:
        path: $HOME/.kube
        state: directory
        mode: 0755

    - name: copy admin.conf to user's kube config
      copy:
        src: /etc/kubernetes/admin.conf
        dest: /home/ubuntu/.kube/config
        remote_src: yes
        owner: ubuntu

    - name: copy Pod network config
      copy:
        src: ./kube-flannel.yml
        dest: /home/ubuntu/
        owner: ubuntu
        group: ubuntu
        mode: '0644' 

    - name: install Pod network
      become: yes
      become_user: ubuntu
      shell: kubectl apply -f kube-flannel.yml >> pod_network_setup.txt
      args:
        chdir: $HOME
        creates: pot_network_setup.txt

