Skip to content

Instantly share code, notes, and snippets.

@nccurry
Created February 4, 2020 16:28
Show Gist options
  • Save nccurry/16deb8a478f22a4d00ab2cddfd7fb455 to your computer and use it in GitHub Desktop.
Save nccurry/16deb8a478f22a4d00ab2cddfd7fb455 to your computer and use it in GitHub Desktop.
Delete all trident pvcs with go templatews
- name: Get a list of all pvcs using trident
vars:
# !unsafe tag tells ansible not to interpret any special characters
go_template: !unsafe '{{ range .items }}{{ if eq .spec.storageClassName "trident" }}{{ "- name: " }}{{ .metadata.name }} {{ "\n namespace: " }}{{ .metadata.namespace }}{{ "\n" }}{{ end }}{{ end }}'
shell: "oc get pvc
--all-namespaces
-o go-template='{{ go_template }}'"
register: get_pvcs
changed_when: false
- name: Delete all pvcs using trident
k8s:
state: absent
resource_definition:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: "{{ item.name }}"
namespace: "{{ item.namespace }}"
loop: "{{ get_pvcs.stdout | from_yaml }}"
@nccurry
Copy link
Author

nccurry commented Feb 4, 2020

Related template to filter clusterserviceversions
'{{ range .items }}{{ if eq (printf "%.13s" .metadata.name) "elasticsearch" }}{{ "- name: " }}{{ .metadata.name }} {{ "\n namespace: " }}{{ .metadata.namespace }}{{ "\n" }}{{ end }}{{ end }}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment