diff --git a/set-contained-proxy.yaml b/set-contained-proxy.yaml new file mode 100644 index 0000000..43682d0 --- /dev/null +++ b/set-contained-proxy.yaml @@ -0,0 +1,39 @@ +- name: Configure HTTP proxy for containerd + hosts: all + become: yes + user: root + tasks: + - name: Check if kubelet service is running + shell: systemctl is-active kubelet + register: kubelet_status + ignore_errors: yes + + - name: Create directory for containerd service override + file: + path: /etc/systemd/system/containerd.service.d + state: directory + when: kubelet_status.stdout == "active" + + - name: Create or edit http-proxy.conf for containerd + blockinfile: + path: /etc/systemd/system/containerd.service.d/http-proxy.conf + create: yes + block: | + [Service] + Environment="HTTP_PROXY=http://192.168.1.38:7890" + Environment="HTTPS_PROXY=http://192.168.1.38:7890" + Environment="NO_PROXY=localhost" + when: kubelet_status.stdout == "active" + + - name: Reload systemd daemon + command: systemctl daemon-reload + when: kubelet_status.stdout == "active" + + - name: Restart containerd and kubelet services + systemd: + name: "{{ item }}" + state: restarted + loop: + - containerd + - kubelet + when: kubelet_status.stdout == "active"