mirror of
https://github.com/k3s-io/k3s-ansible.git
synced 2025-12-25 00:12:37 +01:00
Check K3s installed version before download tasks (#297)
- [Agent : Download artefact only if needed](roles/k3s_agent/tasks/main.yml#L13) - [Server : Download artefact only if needed](roles/k3s_server/tasks/main.yml#L13) - [Upgrade : Upgrade node only if needed](roles/k3s_upgrade/tasks/main.yml#L14) Linked issue #264 k3s_server and k3s_agent tasks are not idempotent Signed-off-by: Loïc Dubard <loic97429@gmail.com>
This commit is contained in:
@@ -1,7 +1,23 @@
|
|||||||
---
|
---
|
||||||
|
- name: Get k3s installed version
|
||||||
|
ansible.builtin.command: k3s --version
|
||||||
|
register: k3s_version_output
|
||||||
|
changed_when: false
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Set k3s installed version
|
||||||
|
when: k3s_version_output.rc == 0
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
installed_k3s_version: "{{ k3s_version_output.stdout_lines[0].split(' ')[2] }}"
|
||||||
|
|
||||||
# If airgapped, all K3s artifacts are already on the node.
|
# If airgapped, all K3s artifacts are already on the node.
|
||||||
- name: Download K3s install script
|
# We should be downloading and installing the newer version only if we are in one of the following cases :
|
||||||
when: airgap_dir is undefined
|
# - we couldn't get k3s installed version in the first task of this role
|
||||||
|
# - the installed version of K3s on the nodes is older than the requested version in ansible vars
|
||||||
|
- name: Download artefact only if needed
|
||||||
|
when: k3s_version_output.rc != 0 or installed_k3s_version is version(k3s_version, '<') and airgap_dir is undefined
|
||||||
|
block:
|
||||||
|
- name: Download K3s install script
|
||||||
ansible.builtin.get_url:
|
ansible.builtin.get_url:
|
||||||
url: https://get.k3s.io/
|
url: https://get.k3s.io/
|
||||||
timeout: 120
|
timeout: 120
|
||||||
@@ -10,8 +26,7 @@
|
|||||||
group: root
|
group: root
|
||||||
mode: 0755
|
mode: 0755
|
||||||
|
|
||||||
- name: Download K3s binary
|
- name: Download K3s binary
|
||||||
when: airgap_dir is undefined
|
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: /usr/local/bin/k3s-install.sh
|
cmd: /usr/local/bin/k3s-install.sh
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
@@ -1,7 +1,23 @@
|
|||||||
---
|
---
|
||||||
|
- name: Get k3s installed version
|
||||||
|
ansible.builtin.command: k3s --version
|
||||||
|
register: k3s_version_output
|
||||||
|
changed_when: false
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Set k3s installed version
|
||||||
|
when: k3s_version_output.rc == 0
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
installed_k3s_version: "{{ k3s_version_output.stdout_lines[0].split(' ')[2] }}"
|
||||||
|
|
||||||
# If airgapped, all K3s artifacts are already on the node.
|
# If airgapped, all K3s artifacts are already on the node.
|
||||||
- name: Download K3s install script
|
# We should be downloading and installing the newer version only if we are in one of the following cases :
|
||||||
when: airgap_dir is undefined
|
# - we couldn't get k3s installed version in the first task of this role
|
||||||
|
# - the installed version of K3s on the nodes is older than the requested version in ansible vars
|
||||||
|
- name: Download artefact only if needed
|
||||||
|
when: k3s_version_output.rc != 0 or installed_k3s_version is version(k3s_version, '<') and airgap_dir is undefined
|
||||||
|
block:
|
||||||
|
- name: Download K3s install script
|
||||||
ansible.builtin.get_url:
|
ansible.builtin.get_url:
|
||||||
url: https://get.k3s.io/
|
url: https://get.k3s.io/
|
||||||
timeout: 120
|
timeout: 120
|
||||||
@@ -10,8 +26,7 @@
|
|||||||
group: root
|
group: root
|
||||||
mode: 0755
|
mode: 0755
|
||||||
|
|
||||||
- name: Download K3s binary
|
- name: Download K3s binary
|
||||||
when: airgap_dir is undefined
|
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: /usr/local/bin/k3s-install.sh
|
cmd: /usr/local/bin/k3s-install.sh
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
@@ -1,12 +1,26 @@
|
|||||||
---
|
---
|
||||||
# with_fileglob doesn't work with remote_src, it tries to find the file on the
|
# with_fileglob doesn't work with remote_src, it tries to find the file on the
|
||||||
# local control-plane instead of the remote host. Shell supports wildcards.
|
# local control-plane instead of the remote host. Shell supports wildcards.
|
||||||
- name: Save current K3s service
|
- name: Get k3s installed version
|
||||||
|
ansible.builtin.command: k3s --version
|
||||||
|
register: k3s_version_output
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Set k3s installed version
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
installed_k3s_version: "{{ k3s_version_output.stdout_lines[0].split(' ')[2] }}"
|
||||||
|
|
||||||
|
# We should be downloading and installing the newer version only if we are in the following case :
|
||||||
|
# - the installed version of K3s on the nodes is older than the requested version in ansible vars
|
||||||
|
- name: Update node only if needed
|
||||||
|
when: installed_k3s_version is version(k3s_version, '<')
|
||||||
|
block:
|
||||||
|
- name: Save current K3s service
|
||||||
ansible.builtin.shell:
|
ansible.builtin.shell:
|
||||||
cmd: "cp {{ systemd_dir }}/k3s*.service /tmp/"
|
cmd: "cp {{ systemd_dir }}/k3s*.service /tmp/"
|
||||||
changed_when: true
|
changed_when: true
|
||||||
|
|
||||||
- name: Install new K3s Version
|
- name: Install new K3s Version
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: /usr/local/bin/k3s-install.sh
|
cmd: /usr/local/bin/k3s-install.sh
|
||||||
environment:
|
environment:
|
||||||
@@ -14,19 +28,19 @@
|
|||||||
INSTALL_K3S_VERSION: "{{ k3s_version }}"
|
INSTALL_K3S_VERSION: "{{ k3s_version }}"
|
||||||
changed_when: true
|
changed_when: true
|
||||||
|
|
||||||
- name: Restore K3s service
|
- name: Restore K3s service
|
||||||
ansible.builtin.shell:
|
ansible.builtin.shell:
|
||||||
cmd: "mv /tmp/k3s*.service {{ systemd_dir }}/"
|
cmd: "mv /tmp/k3s*.service {{ systemd_dir }}/"
|
||||||
changed_when: true
|
changed_when: true
|
||||||
|
|
||||||
- name: Restart K3s service [server]
|
- name: Restart K3s service [server]
|
||||||
when: "'server' in group_names"
|
when: "'server' in group_names"
|
||||||
ansible.builtin.systemd:
|
ansible.builtin.systemd:
|
||||||
state: restarted
|
state: restarted
|
||||||
daemon_reload: true
|
daemon_reload: true
|
||||||
name: k3s
|
name: k3s
|
||||||
|
|
||||||
- name: Restart K3s service [agent]
|
- name: Restart K3s service [agent]
|
||||||
when: "'agent' in group_names"
|
when: "'agent' in group_names"
|
||||||
ansible.builtin.systemd:
|
ansible.builtin.systemd:
|
||||||
state: restarted
|
state: restarted
|
||||||
|
|||||||
Reference in New Issue
Block a user