fix: kubectl version check failed

Signed-off-by: William Wang <williamw0825@gmail.com>
This commit is contained in:
William Wang 2025-12-01 11:03:44 +08:00
parent d5c928b61d
commit 0c39ac1d17
2 changed files with 14 additions and 4 deletions

View File

@ -30,12 +30,17 @@
- name: Check if kubectl is installed
ignore_errors: true
command: kubectl version --short
command: |
{{- if .kubernetes.kube_version | semverCompare ">=v1.28.0" -}}
kubectl version --client
{{- else -}}
kubectl version --client --short
{{- end -}}
register: kubectl_install_version
register_type: yaml
- name: Sync kubectl to remote
when: |
or (.kubectl_install_version.error | empty | not) ((get .kubectl_install_version.stdout "Server Version") | ne .kube_version)
or (.kubectl_install_version.error | empty | not) ((get .kubectl_install_version.stdout "Client Version") | ne .kube_version)
copy:
src: >-
{{ .binary_dir }}/kube/{{ .kube_version }}/{{ .binary_type }}/kubectl

View File

@ -32,13 +32,18 @@
- name: Binary | Check if kubectl is installed
ignore_errors: true
command: kubectl version --short
command: |
{{- if .kubernetes.kube_version | semverCompare ">=v1.28.0" -}}
kubectl version --client
{{- else -}}
kubectl version --client --short
{{- end -}}
register: kubectl_install_version
register_type: yaml
- name: Binary | Install kubectl if not present or version mismatch
when: |
or (.kubectl_install_version.error | empty | not) ((get .kubectl_install_version.stdout "Server Version") | ne .kubernetes.kube_version)
or (.kubectl_install_version.error | empty | not) ((get .kubectl_install_version.stdout "Client Version") | ne .kubernetes.kube_version)
copy:
src: >-
{{ .binary_dir }}/kube/{{ .kubernetes.kube_version }}/{{ .binary_type }}/kubectl