From 558784e1fdffd268f159ed64a68dbb1deb3cf6d9 Mon Sep 17 00:00:00 2001 From: buxiaomo <95112082@qq.com> Date: Thu, 14 Nov 2024 19:04:20 +0800 Subject: [PATCH] fix containerd proxy not setting --- roles/containerd/tasks/main.yml | 21 +++++++++++++++++++++ roles/containerd/templates/proxy.conf.j2 | 12 ++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 roles/containerd/templates/proxy.conf.j2 diff --git a/roles/containerd/tasks/main.yml b/roles/containerd/tasks/main.yml index d2efdf040..8f4c58eca 100644 --- a/roles/containerd/tasks/main.yml +++ b/roles/containerd/tasks/main.yml @@ -187,6 +187,26 @@ - upgrade - update +- name: Create systemd service.d + ansible.builtin.file: + name: /etc/systemd/system/containerd.service.d + state: directory + mode: "0755" + when: proxy_env is defined + notify: restart containerd + tags: + - update + +- name: Install systemd file proxy.conf + ansible.builtin.template: + src: proxy.conf.j2 + dest: /etc/systemd/system/containerd.service.d/proxy.conf + register: containerd_systemd_d + when: proxy_env is defined + notify: restart containerd + tags: + - update + - name: Populate service facts ansible.builtin.service_facts: @@ -202,6 +222,7 @@ crictl_pkg.changed or containerd_cfg.changed or containerd_systemd.changed or + containerd_systemd_d.changed or ansible_facts.services['containerd.service']['state'] != 'running' - name: Install crictl completion diff --git a/roles/containerd/templates/proxy.conf.j2 b/roles/containerd/templates/proxy.conf.j2 new file mode 100644 index 000000000..95acb3c07 --- /dev/null +++ b/roles/containerd/templates/proxy.conf.j2 @@ -0,0 +1,12 @@ +{% if proxy_env is defined %} +{% if proxy_env.http_proxy is defined and proxy_env.http_proxy != "" %} +[Service] +Environment="HTTP_PROXY={{ proxy_env.http_proxy }}" +{% endif %} +{% if proxy_env.https_proxy is defined and proxy_env.https_proxy != "" %} +Environment="HTTPS_PROXY={{ proxy_env.https_proxy }}" +{% endif %} +{% if proxy_env.no_proxy is defined and proxy_env.no_proxy != "" %} +Environment="NO_PROXY={{ proxy_env.no_proxy }}" +{% endif %} +{% endif %} \ No newline at end of file