--- # 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. - name: Get k3s installed version ansible.builtin.command: k3s --version register: k3s_upgrade_version_output changed_when: false check_mode: false - name: Set k3s installed version ansible.builtin.set_fact: k3s_upgrade_current_version: "{{ k3s_upgrade_version_output.stdout_lines[0].split(' ')[2] }}" check_mode: false # 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: k3s_upgrade_current_version is version(k3s_version, '<') block: - name: Find K3s service files # noqa var-naming[no-role-prefix] ansible.builtin.find: paths: "{{ systemd_dir }}" patterns: "k3s*.service*" register: k3s_service_files - name: Save current K3s service ansible.builtin.copy: src: "{{ item.path }}" dest: "{{ item.path }}.bak" remote_src: true mode: preserve force: true loop: "{{ k3s_service_files.files }}" - name: Stage airgap artifacts for upgrade when: airgap_dir is defined ansible.builtin.include_role: name: airgap tasks_from: main.yml apply: tags: - distribute_artifacts - name: Install new K3s Version # For some reason, ansible-lint thinks using enviroment with command is an error # even though its valid https://ansible.readthedocs.io/projects/lint/rules/inline-env-var/#correct-code ansible.builtin.command: # noqa inline-env-var cmd: /usr/local/bin/k3s-install.sh environment: >- {{ extra_install_envs | combine({ "INSTALL_K3S_SKIP_START": "true", "INSTALL_K3S_VERSION": k3s_version, }) | combine(airgap_dir is defined and {"INSTALL_K3S_SKIP_DOWNLOAD": "true"} or {}) }} changed_when: true - name: Restore K3s service ansible.builtin.copy: src: "{{ item.path }}.bak" dest: "{{ item.path }}" remote_src: true mode: preserve force: true loop: "{{ k3s_service_files.files }}" - name: Clean up temporary K3s service backups ansible.builtin.file: path: "{{ item.path }}.bak" state: absent loop: "{{ k3s_service_files.files }}" - name: Restart K3s service [server] when: "server_group in group_names" ansible.builtin.systemd: state: restarted daemon_reload: true name: k3s - name: Restart K3s service [agent] when: "agent_group in group_names" ansible.builtin.systemd: state: restarted daemon_reload: true name: k3s-agent