-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1273 from tu1h/add_extra_dependencies_sprayjob
Add playbook to set containerd registry mirrors
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Copyright 2023 Authors of kubean-io | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
--- | ||
- name: Set containerd registry mirrors | ||
hosts: all | ||
any_errors_fatal: "{{ any_errors_fatal | default(true) }}" | ||
vars: | ||
containerd_config_path: /etc/containerd/config.toml | ||
#containerd_mirror: | ||
# override: false | ||
# mirror: docker.io | ||
# endpoints: | ||
# - 192.168.1.1 | ||
tasks: | ||
- name: containerd_mirror must not be empty | ||
assert: | ||
that: containerd_mirror is defined and containerd_mirror | ||
|
||
- name: fetch containerd config toml | ||
ansible.builtin.slurp: | ||
src: "{{ containerd_config_path }}" | ||
register: containerd_config_file | ||
|
||
- name: parse containerd config toml | ||
set_fact: | ||
containerd_config: "{{ containerd_config_file['content'] | b64decode | sivel.toiletwater.from_toml }}" | ||
|
||
- name: detect if mirror is already defined | ||
set_fact: | ||
mirror_exists: "{{ (containerd_mirror.mirror in (containerd_config.plugins['io.containerd.grpc.v1.cri'].registry.mirrors | default([]))) }}" | ||
|
||
- name: update containerd_config | ||
set_fact: | ||
containerd_config: >- | ||
{{ | ||
containerd_config | combine({ | ||
"plugins": { | ||
"io.containerd.grpc.v1.cri": { | ||
"registry": { | ||
"mirrors": (containerd_config.plugins['io.containerd.grpc.v1.cri'].registry.mirrors | default({})) | combine({ | ||
containerd_mirror.mirror: { | ||
"endpoint": containerd_mirror.endpoints + (containerd_config.plugins['io.containerd.grpc.v1.cri'].registry.mirrors[containerd_mirror.mirror].endpoint if (mirror_exists | default(false)) and not (containerd_mirror.override | default(false)) else []) | ||
} | ||
}) | ||
}, | ||
}, | ||
} | ||
}, recursive=True) | ||
}} | ||
- name: writeback containerd config toml | ||
copy: | ||
dest: "{{ containerd_config_path }}" | ||
mode: 0644 | ||
content: "{{ containerd_config | sivel.toiletwater.to_toml }}" | ||
backup: true | ||
become: true |