-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrolling-updates.yaml
79 lines (71 loc) · 2.4 KB
/
rolling-updates.yaml
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
68
69
70
71
72
73
74
75
76
77
78
79
- name: Rolling upgrade of all nodes
hosts: all
serial: 3 # only do three nodes at a time
order: shuffle # choose the nodes randomly
strategy: free # don't wait for the previous batch to finish
vars:
masters: "{{ groups['k8s1masters'] }}"
tasks:
- name: Get the list of k8s nodes
shell: kubectl get nodes -o jsonpath='{.items[*].metadata.name}'
register: nodes
delegate_to: localhost
until: nodes is succeeded
retries: 3
delay: 10
- name: Check if the current host is a k8s node
set_fact:
is_node: "{{ inventory_hostname in nodes.stdout.split() }}"
ignore_errors: true
- name: Cordon the k8s node
shell: kubectl cordon {{ inventory_hostname }}
delegate_to: localhost
register: result
when: is_node
until: result is succeeded
retries: 3
delay: 10
- name: Drain the node if it is a k8s node
shell: kubectl drain {{ inventory_hostname }} --ignore-daemonsets --delete-emptydir-data
when: is_node
delegate_to: localhost
register: result
until: result is succeeded
retries: 3
delay: 10
- name: Update packages and reboot hosts
block:
- name: Update homebrew on macOS
homebrew:
update_homebrew: yes
upgrade_all: yes
when: ansible_os_family == "Darwin"
tags: update
- name: Update software on macOS
command: softwareupdate -i -a
when: ansible_os_family == "Darwin"
become: true
- name: Full upgrade packages on Debian-based systems
ansible.builtin.apt:
update_cache: yes
upgrade: full
dpkg_options: 'force-confdef,force-confold'
autoremove: yes
environment:
DEBIAN_FRONTEND: noninteractive
when: ansible_os_family == "Debian"
become: true
- name: Reboot the node
ansible.builtin.reboot:
become: true
when:
- inventory_hostname != "shiraz" # This is the nas.. it would be bad as many hosts boot from it
- inventory_hostname != "gw" # This is the gw.. it would be bad as... internet...
- name: Uncordon the k8s node
shell: kubectl uncordon {{ inventory_hostname }}
delegate_to: localhost
when: is_node
register: result
until: result is succeeded
retries: 3
delay: 10