fix(ansible): update cluster-rollout-update playbook

Signed-off-by: Devin Buhl <devin@buhl.casa>
This commit is contained in:
Devin Buhl committed 2023-07-19 08:27:00 -04:00
1 parent c48083ca6b
commit e4d1fa15d6
1 file changed
+15 -10
@@ -11,26 +11,26 @@
ansible.builtin.pause: ansible.builtin.pause:
seconds: 5 seconds: 5
tasks: tasks:
- name: Get the node's details - name: Details
ansible.builtin.command: "kubectl get node {% raw %}{{ inventory_hostname }}{% endraw %} -o json" ansible.builtin.command: "kubectl get node {% raw %}{{ inventory_hostname }}{% endraw %} -o json"
register: kubectl_get_node register: kubectl_get_node
delegate_to: "{% raw %}{{ groups['master'][0] }}{% endraw %}" delegate_to: "{% raw %}{{ groups['master'][0] }}{% endraw %}"
failed_when: false failed_when: false
changed_when: false changed_when: false
- name: Update node - name: Update
when: when:
# When status.conditions[x].type == Ready then check stats.conditions[x].status for True|False # When status.conditions[x].type == Ready then check stats.conditions[x].status for True|False
- kubectl_get_node['stdout'] | from_json | json_query("status.conditions[?type == 'Ready'].status") - kubectl_get_node['stdout'] | from_json | json_query("status.conditions[?type == 'Ready'].status")
# If spec.unschedulable is defined then the node is cordoned # If spec.unschedulable is defined then the node is cordoned
- not (kubectl_get_node['stdout'] | from_json).spec.unschedulable is defined - not (kubectl_get_node['stdout'] | from_json).spec.unschedulable is defined
block: block:
- name: Cordon node - name: Cordon
ansible.builtin.command: "kubectl cordon {% raw %}{{ inventory_hostname }}{% endraw %}" ansible.builtin.command: "kubectl cordon {% raw %}{{ inventory_hostname }}{% endraw %}"
delegate_to: "{% raw %}{{ groups['master'][0] }}{% endraw %}" delegate_to: "{% raw %}{{ groups['master'][0] }}{% endraw %}"
changed_when: false changed_when: false
- name: Wait for node to cordon - name: Wait for cordon
ansible.builtin.command: "kubectl get node {% raw %}{{ inventory_hostname }}{% endraw %} -o json" ansible.builtin.command: "kubectl get node {% raw %}{{ inventory_hostname }}{% endraw %} -o json"
register: wait_for_cordon register: wait_for_cordon
retries: 10 retries: 10
@@ -39,30 +39,35 @@
changed_when: false changed_when: false
until: (wait_for_cordon['stdout'] | from_json).spec.unschedulable until: (wait_for_cordon['stdout'] | from_json).spec.unschedulable
- name: Cordon & drain node - name: Drain
ansible.builtin.command: "kubectl drain --ignore-daemonsets --delete-emptydir-data --force {% raw %}{{ inventory_hostname }}{% endraw %}" ansible.builtin.command: "kubectl drain --ignore-daemonsets --delete-emptydir-data --force {% raw %}{{ inventory_hostname }}{% endraw %}"
delegate_to: "{% raw %}{{ groups['master'][0] }}{% endraw %}" delegate_to: "{{ groups['master'][0] }}"
changed_when: false changed_when: false
- name: Update all packages - name: Update
ansible.builtin.apt: ansible.builtin.apt:
upgrade: dist upgrade: dist
update_cache: true update_cache: true
- name: Check if reboot is required
ansible.builtin.stat:
path: /var/run/reboot-required
register: reboot_required
- name: Reboot - name: Reboot
when: reboot_required.stat.exists
ansible.builtin.reboot: ansible.builtin.reboot:
msg: Rebooting node msg: Rebooting node
post_reboot_delay: 60 post_reboot_delay: 60
reboot_timeout: 3600 reboot_timeout: 3600
- name: Uncordon node - name: Uncordon
ansible.builtin.command: "kubectl uncordon {% raw %}{{ inventory_hostname }}{% endraw %}" ansible.builtin.command: "kubectl uncordon {% raw %}{{ inventory_hostname }}{% endraw %}"
delegate_to: "{% raw %}{{ groups['master'][0] }}{% endraw %}" delegate_to: "{% raw %}{{ groups['master'][0] }}{% endraw %}"
changed_when: false changed_when: false
- name: Wait for node to uncordon - name: Wait for uncordon
ansible.builtin.command: "kubectl get node {% raw %}{{ inventory_hostname }}{% endraw %} -o json" ansible.builtin.command: "kubectl get node {% raw %}{{ inventory_hostname }}{% endraw %} -o json"
register: wait_for_uncordon
retries: 10 retries: 10
delay: 10 delay: 10
delegate_to: "{% raw %}{{ groups['master'][0] }}{% endraw %}" delegate_to: "{% raw %}{{ groups['master'][0] }}{% endraw %}"