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]' jq -r '.Tags[0]'
chdir: /opt/metacluster/container-images chdir: /opt/metacluster/container-images
register: registry_artifacts 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: loop_control:
label: "{{ item | basename }}" label: "{{ item | basename }}"
- name: Get source registries of all artifacts - name: Get source registries of all artifacts
ansible.builtin.set_fact: ansible.builtin.set_fact:
source_registries: "{{ (source_registries | default([]) + [(item | split('/'))[0]]) | unique | sort }}" 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 - name: Configure K3s node for private registry
ansible.builtin.template: ansible.builtin.template:

View File

@ -71,5 +71,13 @@
definition: definition:
metadata: metadata:
labels: labels:
vm_id: "{{ moref_id }}" ova.airgappedk8s/moref_id: "{{ moref_id }}"
kubeconfig: "{{ kubeconfig.path }}" 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 - name: Cordon node
kubernetes.core.k8s_drain: kubernetes.core.k8s_drain:
name: "{{ decom_node }}" name: "{{ decom_nodename }}"
state: cordon state: cordon
kubeconfig: "{{ kubeconfig.path }}" kubeconfig: "{{ kubeconfig.path }}"
- name: Drain node - name: Drain node
kubernetes.core.k8s_drain: kubernetes.core.k8s_drain:
name: "{{ decom_node }}" name: "{{ decom_nodename }}"
state: drain state: drain
delete_options: delete_options:
ignore_daemonsets: true ignore_daemonsets: true
@ -17,7 +17,7 @@
- name: Delete node - name: Delete node
kubernetes.core.k8s: kubernetes.core.k8s:
name: "{{ decom_node }}" name: "{{ decom_nodename }}"
kind: node kind: node
state: absent state: absent
wait: true 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: ansible.builtin.set_fact:
decom_node: >- decom_nodename: >-
{{ {{
lookup('kubernetes.core.k8s', kind='Node', kubeconfig=(kubeconfig.path)) | lookup('kubernetes.core.k8s', kind='Node', kubeconfig=(kubeconfig.path)) |
json_query('[? metadata.name != `' ~ ansible_facts.nodename ~ '`].metadata.name') | json_query('[? metadata.name != `' ~ ansible_facts.nodename ~ '`].metadata.name') |
first first
}} }}
decom_vmid: >- decom_morefid: >-
{{ {{
lookup('kubernetes.core.k8s', kind='Node', kubeconfig=(kubeconfig.path)) | 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 first
}} }}

View File

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

View File

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

View File

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