--- - name: Apply local-path-config lab JSON (opt-in) hosts: k3s_server become: true run_once: true vars: k3s_kubeconfig: /etc/rancher/k3s/k3s.yaml local_path_apply_lab_config_enabled: "{{ local_path_apply_lab_config | default(false) | bool }}" local_path_json_src: "{{ playbook_dir }}/../../files/03-05/local-path-config-lab.json" local_path_json_dest: /root/local-path-config-lab.json pre_tasks: - name: Gate - skip apply local-path lab config when local_path_apply_lab_config=false when: not local_path_apply_lab_config_enabled block: - ansible.builtin.debug: msg: "[GATE] skipped doc_id=03-05 action=apply-local-path-config var=local_path_apply_lab_config" - meta: end_play 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 - name: Deploy 03-05 local-path pvc demo hosts: k3s_server become: true run_once: true vars: k3s_kubeconfig: /etc/rancher/k3s/k3s.yaml manifest_src: "{{ playbook_dir }}/../../files/03-05/local-path-pvc-demo.yaml" manifest_dest: /tmp/local-path-pvc-demo.yaml tasks: - name: Copy manifest ansible.builtin.copy: src: "{{ manifest_src }}" dest: "{{ manifest_dest }}" mode: "0644" - name: Apply manifest ansible.builtin.shell: | set -e KUBECONFIG={{ k3s_kubeconfig }} kubectl apply -f {{ manifest_dest }} args: executable: /bin/bash changed_when: true - name: Verify 03-05 local-path pvc demo hosts: k3s_server become: true run_once: true vars: k3s_kubeconfig: /etc/rancher/k3s/k3s.yaml tasks: - name: Wait pvc Bound ansible.builtin.shell: | set -e KUBECONFIG={{ k3s_kubeconfig }} kubectl get pvc local-pvc-demo -n default -o jsonpath='{.status.phase}' args: executable: /bin/bash register: pvc_phase changed_when: false until: pvc_phase.stdout | trim == "Bound" retries: 30 delay: 2 - name: Rollout status nginx-local-pvc-demo ansible.builtin.shell: | set -e KUBECONFIG={{ k3s_kubeconfig }} kubectl rollout status deployment/nginx-local-pvc-demo -n default --timeout=240s args: executable: /bin/bash changed_when: false - name: Teardown 03-05 local-path pvc demo (optional) hosts: k3s_server become: true run_once: true vars: k3s_kubeconfig: /etc/rancher/k3s/k3s.yaml verify_teardown: "{{ (VERIFY_TEARDOWN | default('1')) | string }}" manifest_dest: /tmp/local-path-pvc-demo.yaml tasks: - name: Delete resources when VERIFY_TEARDOWN=1 when: verify_teardown == "1" ansible.builtin.shell: | set -e KUBECONFIG={{ k3s_kubeconfig }} kubectl delete -f {{ manifest_dest }} --ignore-not-found=true args: executable: /bin/bash changed_when: true