Fix label syntax;Add retries;Sort list;Housekeeping
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Danny Bessems 2023-02-04 12:00:10 +01:00
parent a020ac0e15
commit 6d5b8e2d96
7 changed files with 26 additions and 13 deletions

View File

@ -63,14 +63,14 @@
jq -r '.Tags[0]'
chdir: /opt/metacluster/container-images
register: registry_artifacts
loop: "{{ query('ansible.builtin.fileglob', '/opt/metacluster/container-images/*.tar') }}"
loop: "{{ query('ansible.builtin.fileglob', '/opt/metacluster/container-images/*.tar') | sort }}"
loop_control:
label: "{{ item | basename }}"
- name: Get source registries of all artifacts
ansible.builtin.set_fact:
source_registries: "{{ (source_registries | default([]) + [(item | split('/'))[0]]) | unique | sort }}"
loop: "{{ registry_artifacts | json_query('results[*].stdout') | select }}"
loop: "{{ registry_artifacts | json_query('results[*].stdout') | select | sort }}"
- name: Configure K3s node for private registry
ansible.builtin.template:

View File

@ -71,5 +71,13 @@
definition:
metadata:
labels:
vm_id: "{{ moref_id }}"
ova.airgappedk8s/moref_id: "{{ moref_id }}"
kubeconfig: "{{ kubeconfig.path }}"
register: patch_result
until:
- patch_result is not failed
retries: "{{ playbook.retries }}"
delay: "{{ playbook.delay.short }}"
- debug:
msg: "{{ patch_result }}"

View File

@ -1,12 +1,12 @@
- name: Cordon node
kubernetes.core.k8s_drain:
name: "{{ decom_node }}"
name: "{{ decom_nodename }}"
state: cordon
kubeconfig: "{{ kubeconfig.path }}"
- name: Drain node
kubernetes.core.k8s_drain:
name: "{{ decom_node }}"
name: "{{ decom_nodename }}"
state: drain
delete_options:
ignore_daemonsets: true
@ -17,7 +17,7 @@
- name: Delete node
kubernetes.core.k8s:
name: "{{ decom_node }}"
name: "{{ decom_nodename }}"
kind: node
state: absent
wait: true

View File

@ -1,15 +1,15 @@
- name: Lookup node name and moref id for decommissioning
- name: Lookup node name and moref-id for decommissioning
ansible.builtin.set_fact:
decom_node: >-
decom_nodename: >-
{{
lookup('kubernetes.core.k8s', kind='Node', kubeconfig=(kubeconfig.path)) |
json_query('[? metadata.name != `' ~ ansible_facts.nodename ~ '`].metadata.name') |
first
}}
decom_vmid: >-
decom_morefid: >-
{{
lookup('kubernetes.core.k8s', kind='Node', kubeconfig=(kubeconfig.path)) |
json_query('[? metadata.name != `' ~ ansible_facts.nodename ~ '`].metadata.labels.vm_id') |
json_query('[? metadata.name != `' ~ ansible_facts.nodename ~ '`].metadata.labels."ova.airgappedk8s/moref_id"') |
first
}}

View File

@ -1,6 +1,6 @@
- name: Disable disk scheduling and evict replicas
kubernetes.core.k8s:
name: "{{ decom_node }}"
name: "{{ decom_nodename }}"
namespace: longhorn-system
kind: nodes.longhorn.io
state: patched

View File

@ -2,7 +2,7 @@
- name: Lookup VM name
community.vmware.vmware_guest_info:
moid: "{{ decom_vmid }}"
moid: "{{ decom_morefid }}"
register: virtualmachine_details
- name: Power off VM

View File

@ -71,5 +71,10 @@
definition:
metadata:
labels:
vm_id: "{{ moref_id }}"
ova.airgappedk8s/moref_id: "{{ moref_id }}"
kubeconfig: "{{ kubeconfig.path }}"
register: patch_result
until:
- patch_result is not failed
retries: "{{ playbook.retries }}"
delay: "{{ playbook.delay.short }}"