--- # 仅应用本仓库 local-path 实验室 ConfigMap(不安装 Longhorn)。在 k3s_server 上执行。 # 与 docs/03-05 中「方法一」一致,真源:ansible/files/03-05-local-path-config/local-path-config-lab.json - name: Apply local-path-config lab JSON hosts: k3s_server become: true run_once: true vars: k3s_kubeconfig: /etc/rancher/k3s/k3s.yaml local_path_json_src: "{{ playbook_dir }}/../files/03-05-local-path-config/local-path-config-lab.json" local_path_json_dest: /root/local-path-config-lab.json tasks: - name: Copy local-path lab json ansible.builtin.copy: src: "{{ local_path_json_src }}" dest: "{{ local_path_json_dest }}" mode: "0644" - name: Apply local-path-config ConfigMap ansible.builtin.shell: | set -e KUBECONFIG={{ k3s_kubeconfig }} kubectl -n kube-system create configmap local-path-config \ --from-file=config.json={{ local_path_json_dest }} \ --dry-run=client -o yaml | KUBECONFIG={{ k3s_kubeconfig }} kubectl apply -f - args: executable: /bin/bash changed_when: true - name: Restart local-path-provisioner if present ansible.builtin.shell: | KUBECONFIG={{ k3s_kubeconfig }} kubectl -n kube-system rollout restart deploy/local-path-provisioner args: executable: /bin/bash register: lp_restart failed_when: false changed_when: lp_restart.rc == 0