Created
February 4, 2020 16:28
-
-
Save nccurry/16deb8a478f22a4d00ab2cddfd7fb455 to your computer and use it in GitHub Desktop.
Delete all trident pvcs with go templatews
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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 }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related template to filter clusterserviceversions
'{{ range .items }}{{ if eq (printf "%.13s" .metadata.name) "elasticsearch" }}{{ "- name: " }}{{ .metadata.name }} {{ "\n namespace: " }}{{ .metadata.namespace }}{{ "\n" }}{{ end }}{{ end }}'