role_microk8s/tasks/main.yml

115 lines
3.9 KiB
YAML

---
# tasks file for main.yml
###########################################################
- name: Check to make sure we have at least {{ minhosts }} target hosts (if cluster)
fail:
msg: "You need to have at least {{ minhosts }} target hosts for a cluster!"
when: (do_cluster == true) and (minhosts > numhosts)
###########################################################
- name: Check for Ubuntu
fail:
msg: "This playbook is only set up to work on Ubuntu hosts."
when: ansible_distribution != "Ubuntu"
###########################################################
- name: Check for Ubuntu LTS >= 16.04
fail:
msg: "This playbook requires Ubuntu LTS, 16.04 or later."
when: not (ansible_distribution_version == "16.04" or
ansible_distribution_version == "18.04" or
ansible_distribution_version == "20.04")
###########################################################
- name: Make sure snapd is installed
apt:
name:
- snapd
state: present
###########################################################
- name: Install microk8s
snap:
name: microk8s
classic: true
channel: "{{ microk8s_version }}"
###########################################################
- name: Add user "{{ username }}" to microk8s group
user:
name: "{{ username }}"
groups: "microk8s"
append: true
when: username != "root"
###########################################################
- name: Set ownership of /home/{{ username }}/.kube
file:
path: "/home/{{ username }}/.kube"
owner: "{{ username }}"
group: "{{ username }}"
recurse: true
when: username != "root"
###########################################################
- name: Get cluster-cidr IP range from /var/snap/microk8s/current/args/kube-proxy
shell:
cmd: grep "cluster-cidr" /var/snap//microk8s/current/args/kube-proxy | cut -d'=' -f2
register: cluster_cidr
when: do_proxy == true
###########################################################
- name: Get service-cluster-ip IP range from /var/snap/microk8s/current/args/kube-apiserver
shell:
cmd: grep "service-cluster-ip" /var/snap//microk8s/current/args/kube-apiserver | cut -d'=' -f2
register: service_cluster_ip
when: do_proxy == true
###########################################################
- name: Config proxy for microk8s
blockinfile:
path: /var/snap/microk8s/current/args/containerd-env
block: |
# proxy configuration
HTTPS_PROXY={{ proxy_host }}
NO_PROXY={{ net_cidrs }},{{ cluster_cidr.stdout }},{{ service_cluster_ip.stdout }}
when: do_proxy == true
###########################################################
- name: Restart microk8s to apply proxy config
shell:
cmd: /usr/bin/snap restart microk8s
when: do_proxy == true
###########################################################
- name: Wait for microk8s ready status
shell: source /etc/profile.d/apps-bin-path.sh && microk8s.status --wait-ready
args:
executable: /bin/bash
###########################################################
- name: Run add-node command on master node "{{ hostvars[groups['master'][0]].inventory_hostname }}"
shell: source /etc/profile.d/apps-bin-path.sh && microk8s.add-node
args:
executable: /bin/bash
register: add_node_cmd
delegate_to: "{{ hostvars[groups['master'][0]].inventory_hostname }}"
when: do_cluster == true
###########################################################
- name: Run join command on worker nodes
shell: source /etc/profile.d/apps-bin-path.sh && {{ add_node_cmd.stdout_lines[1] }}
args:
executable: /bin/bash
when: (do_cluster == true) and ('workers' in group_names)
###########################################################
- name: Wait for microk8s ready status
shell: source /etc/profile.d/apps-bin-path.sh && microk8s.status --wait-ready
args:
executable: /bin/bash
when: (do_cluster == true) and ('workers' in group_names)
# EOF