- hosts: all become: yes tasks: - name: install Docker yum: name: docker state: present update_cache: true - name: start Docker service: name: docker enabled: yes state: started - name: Stop and disable firewalld. service: name: firewalld state: stopped enabled: False - name: disable SELinux command: setenforce 0 - name: disable SELinux on reboot selinux: state: disabled - 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: ensure net.bridge.bridge-nf-call-ip6tables is set to 1 sysctl: name: net.bridge.bridge-nf-call-ip6tables value: 1 state: present - name: ensure net.bridge.bridge-nf-call-iptables is set to 1 sysctl: name: net.bridge.bridge-nf-call-iptables value: 1 state: present - name: add Kubernetes' YUM repository yum_repository: name: Kubernetes description: Kubernetes YUM repository baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 gpgkey: https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg gpgcheck: yes - name: install kubelet yum: name: kubelet state: present update_cache: true - name: install kubeadm yum: name: kubeadm state: present - name: start kubelet service: name: kubelet enabled: yes state: started - name: install kubectl yum: name: kubectl state: present allow_downgrade: true - hosts: master become: yes tasks: - name: initialize the cluster shell: kubeadm init - name: create .kube directory become: yes become_user: root file: path: $HOME/.kube state: directory mode: 0755 - name: copy admin.conf to user's kube config copy: src: /etc/kubernetes/admin.conf dest: /root/.kube/config remote_src: yes owner: root - name: install Pod network become: yes become_user: root shell: kubectl apply -f https://raw.githubusercontent.com/thinkub/ansible-k8s-cluster/master/flannel.yml args: chdir: $HOME creates: pod_network_setup.txt - hosts: master become: yes gather_facts: false tasks: - name: get join command shell: kubeadm token create --print-join-command register: join_command_raw - name: set join command set_fact: join_command: "{{ join_command_raw.stdout_lines[0] }}" - hosts: nodes become: yes tasks: - name: join cluster shell: "{{ hostvars['master'].join_command }} --ignore-preflight-errors all >> node_joined.txt" args: chdir: $HOME creates: node_joined.txt