--- - name: Setup all hosts for installation hosts: kubernetes become: true tasks: - name: Install dependencies for docker apt: name: "{{ item }}" state: present with_items: - "apt-transport-https" - "ca-certificates" - "software-properties-common" - "cron" - "curl" - name: Get upstream docker APT GPG key apt_key: url: https://download.docker.com/linux/debian/gpg state: "present" - name: Configure upstream APT repository for Debian x86_64 apt_repository: repo: "deb [arch=amd64] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} edge" state: "present" update_cache: True when: - ansible_distribution == "Debian" - ansible_architecture == "x86_64" - name: Configure upstream APT repository for Raspbian armhf apt_repository: repo: "deb [arch=armhf] https://download.docker.com/linux/{{ ansible_lsb.id | lower }} {{ ansible_distribution_release }} edge" state: "present" update_cache: True when: - ansible_lsb.id == "Raspbian" - name: Install Docker apt: name: "docker-ce=17.12.1~ce-0~{{ ansible_lsb.id | lower }}" state: "present" update_cache: True install_recommends: False - name: Get upstream kubernetes APT GPG key apt_key: url: https://packages.cloud.google.com/apt/doc/apt-key.gpg state: "present" - name: Configure upstream kubernetes APT repository apt_repository: repo: "deb http://apt.kubernetes.io/ kubernetes-xenial main" state: "present" update_cache: True - name: Install kubeadm apt: name: "kubeadm" state: "present" update_cache: True install_recommends: False - name: Remove swapfile from /etc/fstab mount: name: swap fstype: swap state: absent - name: Disable swap command: swapoff -a when: ansible_swaptotal_mb > 0 - name: Set up master node hosts: masters become: true tasks: - name: Check for admin.conf from kubeadm stat: path=/etc/kubernetes/admin.conf register: admin_conf - set_fact: running: admin_conf.stat.exists - name: Run kubeadm if admin.conf doesn't exist command: kubeadm init --pod-network-cidr 10.244.0.0/16 when: admin_conf.stat.exists == false - name: Create kubeadm join command shell: kubeadm token create --print-join-command register: results when: admin_conf.stat.exists == false - debug: var: results.stdout when: admin_conf.stat.exists == false - set_fact: token: "{{ results.stdout | regex_search(regexp, '\\2') | first }}" vars: regexp: '([^\s]+\s){4}([^\s]+)' when: admin_conf.stat.exists == false - debug: var: token when: admin_conf.stat.exists == false - set_fact: hash: "{{ results.stdout | regex_search(regexp, '\\2') | first }}" vars: regexp: '([^\s]+\s){6}([^\s]+)' when: admin_conf.stat.exists == false - debug: var: hash when: admin_conf.stat.exists == false - name: Install flannel networking for RPi shell: curl -sSL https://rawgit.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml | sed "s/amd64/arm/g" | kubectl --kubeconfig=/etc/kubernetes/admin.conf create -f - when: - ansible_lsb.id == "Raspbian" - admin_conf.stat.exists == false - name: Install flannel networking for x86_64 shell: curl -sSL https://rawgit.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml | kubectl --kubeconfig=/etc/kubernetes/admin.conf create -f - when: - ansible_distribution == "Debian" - ansible_architecture == "x86_64" - admin_conf.stat.exists == false - debug: msg: "kubeadm has probably already been run." when: admin_conf.stat.exists == true - name: Set up worker nodes hosts: nodes become: true tasks: - name: Install kubernetes on nodes command: kubeadm join 192.168.11.167:6443 --token "{{ hostvars['debian.ipa.champion']['token'] }}" --discovery-token-ca-cert-hash "{{ hostvars['debian.ipa.champion']['hash'] }}" when: hostvars['debian.ipa.champion']['running'] == false