Skip to content

Commit

Permalink
Change debian repo to the new one. Remove usage of (deprecated) apt_key
Browse files Browse the repository at this point in the history
  • Loading branch information
Zempashi committed Nov 17, 2023
1 parent 5669f3d commit 8dec08f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
2 changes: 1 addition & 1 deletion roles/packages/tasks/find_version_Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
22 changes: 18 additions & 4 deletions roles/packages/tasks/kube_repo_Debian.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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 }}'
9 changes: 8 additions & 1 deletion roles/packages/tasks/pkg_Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
16 changes: 14 additions & 2 deletions roles/packages/vars/os_Debian.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/features/upgrade.feature
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ Feature: Upgrade
Examples:
| from_version | to_version |
| 1.21 | 1.22 |
| 1.23 | 1.24 |

0 comments on commit 8dec08f

Please sign in to comment.