How to validate all the pvc created by yml using ansible?

5/29/2019

We are creating pvc using yml file. The pvc entries are created dynamically based on user input. No of pvc to be created will be received as input and accordingly the number of pvc entries will be created in yml file then that yml file will be passed to Kubectl command to create pvc.

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pvc{{ currenttimestamp }}
  labels:
    ansible: {{ currenttimestamp }}
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: {{ local_volume_size | default('10') }}Gi
  storageClassName: sc{{ currenttimestamp }}
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pvc{{ timestamp }}
  labels:
    ansible: {{ currenttimestamp }}
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: {{ local_volume_size | default('10') }}Gi
  storageClassName: sc{{ currenttimestamp }}

For single PVC validation , i am using below Ansible code

- name: Verify whether the PVC is created
  command: "kubectl get pvc {{pvcname}} -o json"
  register: pvcresult

As the pvc generation yml is dynamic ,i need to get all the pvc name from yml then validate it. Is there any simple way there to check whether all the pvc mentioned in the yml is created?

-- Samselvaprabu
ansible
kubernetes

0 Answers