Skip to content

Instantly share code, notes, and snippets.

@zulhfreelancer
Last active September 5, 2022 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zulhfreelancer/1b6e2ce30463efd7f6007520b81c0ec8 to your computer and use it in GitHub Desktop.
Save zulhfreelancer/1b6e2ce30463efd7f6007520b81c0ec8 to your computer and use it in GitHub Desktop.
How to list all root keys in YAML file?

Problem

How to list all root keys in YAML file using yq v4 CLI?

Solution

yq4 is my terminal alias for yq above

Let's print all the root keys if they have enabled sub-key e.g.

foo:
  enabled: true

Command:

$ yq4 e '.[] | select(has("enabled")) | path | .[]' <filename>

Example:

See full values.yaml file here

$ yq4 e '.[] | select(has("enabled")) | path | .[]' values.yaml
alertmanager
grafana
kubeApiServer
kubelet
kubeControllerManager
coreDns
kubeDns
kubeEtcd
kubeScheduler
kubeProxy
kubeStateMetrics
nodeExporter
prometheusOperator
prometheus
thanosRuler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment