对齐文件规范
This commit is contained in:
@@ -1,19 +1,62 @@
|
||||
- name: Deploy 03-05 local-path PVC demo
|
||||
---
|
||||
- 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
|
||||
manifest_src: "{{ playbook_dir }}/../../files/03-05-local-path-demo/local-path-pvc-demo.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 to server
|
||||
- name: Copy manifest
|
||||
ansible.builtin.copy:
|
||||
src: "{{ manifest_src }}"
|
||||
dest: "{{ manifest_dest }}"
|
||||
mode: "0644"
|
||||
|
||||
- name: kubectl apply
|
||||
- name: Apply manifest
|
||||
ansible.builtin.shell: |
|
||||
set -e
|
||||
KUBECONFIG={{ k3s_kubeconfig }} kubectl apply -f {{ manifest_dest }}
|
||||
@@ -21,32 +64,34 @@
|
||||
executable: /bin/bash
|
||||
changed_when: true
|
||||
|
||||
- name: Verify 03-05 local-path PVC demo
|
||||
- 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 nginx-local-pvc-demo deployment ready
|
||||
- name: Wait pvc Bound
|
||||
ansible.builtin.shell: |
|
||||
set -e
|
||||
KUBECONFIG={{ k3s_kubeconfig }} kubectl rollout status deployment/nginx-local-pvc-demo -n default --timeout=180s
|
||||
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: Assert PVC is Bound
|
||||
ansible.builtin.shell: |
|
||||
set -e
|
||||
phase=$(KUBECONFIG={{ k3s_kubeconfig }} kubectl get pvc local-pvc-demo -n default -o jsonpath='{.status.phase}')
|
||||
echo "pvc phase=$phase"
|
||||
test "$phase" = "Bound"
|
||||
args:
|
||||
executable: /bin/bash
|
||||
changed_when: false
|
||||
|
||||
- name: Teardown 03-05 local-path PVC demo (optional)
|
||||
- name: Teardown 03-05 local-path pvc demo (optional)
|
||||
hosts: k3s_server
|
||||
become: true
|
||||
run_once: true
|
||||
|
||||
Reference in New Issue
Block a user