diff --git a/roles/packages/tasks/find_version_Debian.yml b/roles/packages/tasks/find_version_Debian.yml index e62085c..d5a524f 100644 --- a/roles/packages/tasks/find_version_Debian.yml +++ b/roles/packages/tasks/find_version_Debian.yml @@ -4,7 +4,7 @@ version: '{{ _target_kubeadm_version }}' when: - _target_kubeadm_version is defined - - not(kube_repo_just_added is changed and ansible_check_mode) + - not(_kube_repo_just_added is changed and ansible_check_mode) register: kubeadm_version - name: 'Display of complete version of kubeadm' diff --git a/roles/packages/tasks/kube_repo_Debian.yml b/roles/packages/tasks/kube_repo_Debian.yml index 2ff77f5..b7fd1ad 100644 --- a/roles/packages/tasks/kube_repo_Debian.yml +++ b/roles/packages/tasks/kube_repo_Debian.yml @@ -1,14 +1,28 @@ --- +- name: 'Create directory to store keys' + file: + dest: /etc/apt/keyrings + state: directory + - name: 'Add kubernetes repo signing key' - apt_key: + ansible.builtin.get_url: url: '{{ kubernetes_repository.gpg_url }}' - state: present + dest: '/etc/apt/keyrings/kubernetes-apt-keyring.asc' + force: true - name: 'Add the kubernetes repository' apt_repository: repo: '{{ kubernetes_repository.repo_url }}' state: present - register: kube_repo_just_added + update_cache: false + register: _kube_repo_just_added + +- name: 'Cleanup old kubernetes repository' + apt_repository: + repo: '{{ kubernetes_old_repository.repo_url }}' + state: absent + update_cache: false + when: kubernetes_repository.repo_url != kubernetes_old_repository.repo_url - name: 'refresh source list' apt: @@ -21,4 +35,4 @@ when: >- repo_refresh_time|int >= 0 or force_update vars: - force_update: '{{ force_apt_update|bool or kube_repo_just_added is changed }}' + force_update: '{{ force_apt_update|bool or _kube_repo_just_added is changed }}' diff --git a/roles/packages/tasks/pkg_Debian.yml b/roles/packages/tasks/pkg_Debian.yml index 5455fe0..ec2a6d4 100644 --- a/roles/packages/tasks/pkg_Debian.yml +++ b/roles/packages/tasks/pkg_Debian.yml @@ -25,4 +25,11 @@ name: "{{ kube_package_dict.keys() }}" state: "latest" allow_change_held_packages: "{{ ansible_check_mode if ansible_version.string is version('2.13', '>=') else omit }}" - when: not(kube_repo_just_added is changed and ansible_check_mode) + when: not(_kube_repo_just_added is changed and ansible_check_mode) + regsiter: _kubelet_installed + +- name: 'Restart kubelet' + service: + name: 'kubelet' + state: restarted + when: not(_kubelet_installed is changed and ansible_check_mode) diff --git a/roles/packages/vars/os_Debian.yml b/roles/packages/vars/os_Debian.yml index 31b016d..bea83a0 100644 --- a/roles/packages/vars/os_Debian.yml +++ b/roles/packages/vars/os_Debian.yml @@ -1,7 +1,19 @@ --- -kubernetes_repository: +_repo_version: '{{ (_target_kubeadm_version|regex_findall("(?:\d+)"))[0:2]|join(".") }}' +kubernetes_repository: >- + {%- if _repo_version is version("1.24", ">=") -%} + {{ kubernetes_new_repository }} + {%- else -%} + {{ kubernetes_old_repository }} + {%- endif -%} + +kubernetes_new_repository: + gpg_url: 'https://pkgs.k8s.io/core:/stable:/v{{ _repo_version }}/deb/Release.key' + repo_url: 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.asc] https://pkgs.k8s.io/core:/stable:/v{{ _repo_version }}/deb/ /' + +kubernetes_old_repository: gpg_url: 'https://packages.cloud.google.com/apt/doc/apt-key.gpg' - repo_url: 'deb https://apt.kubernetes.io/ kubernetes-xenial main' + repo_url: 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.asc] https://apt.kubernetes.io/ kubernetes-xenial main' repository_dependencies: - apt-transport-https diff --git a/tests/features/upgrade.feature b/tests/features/upgrade.feature index 1b6f0bd..111cd01 100644 --- a/tests/features/upgrade.feature +++ b/tests/features/upgrade.feature @@ -31,3 +31,4 @@ Feature: Upgrade Examples: | from_version | to_version | | 1.21 | 1.22 | + | 1.23 | 1.24 |