forked from istvano/ansible_role_microk8s
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfigure-HA.yml
67 lines (60 loc) · 2.07 KB
/
configure-HA.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
- name: Enumerate all cluster hosts within the hosts file
ansible.builtin.blockinfile:
dest: /etc/hosts
marker: "# {mark} ANSIBLE MANAGED: microk8s HA Cluster Hosts"
# yamllint disable rule:line-length
content: |
{% for host in groups[microk8s_group_ha] %}
{{ hostvars[host].ansible_default_ipv4.address }} {{ hostvars[host].ansible_hostname }}
{% endfor %}
# yamllint enable rule:line-length
tags:
- microk8s
- microk8s.ha
- microk8s.ha.hosts
- name: Find the designated host
ansible.builtin.set_fact:
microk8s_designated_host: '{{ (groups[microk8s_group_ha]|sort)[0] }}'
tags:
- always
- microk8s
- microk8s.ha
- block:
- name: Waiting for microk8s to be ready on microk8s host master
ansible.builtin.command:
cmd: microk8s status --wait-ready
delegate_to: "{{ microk8s_designated_host }}"
delegate_facts: true
changed_when: false
- name: Get the microk8s join command from the microk8s master
ansible.builtin.shell:
cmd: >-
microk8s add-node |
grep -E -m1 'microk8s join {{ microk8s_ip_regex_ha }}'
delegate_to: "{{ microk8s_designated_host }}"
delegate_facts: true
changed_when: false
register: microk8s_join_command
- name: Get microk8s cluster nodes
ansible.builtin.command:
cmd: kubectl get nodes --no-headers -o custom-columns=:.metadata.name
delegate_to: "{{ microk8s_designated_host }}"
delegate_facts: true
changed_when: false
register: microk8s_cluster_node
- name: Waiting for microk8s to be ready on microk8s host node
ansible.builtin.command:
cmd: microk8s status --wait-ready
changed_when: false
- name: Set the microk8s join command on the microk8s node
ansible.builtin.command:
cmd: "{{ microk8s_join_command.stdout }} --skip-verify"
when:
- inventory_hostname not in microk8s_cluster_node.stdout
when: inventory_hostname != microk8s_designated_host
tags:
- microk8s
- microk8s.ha
- microk8s.ha.join
...