Using YQ for reading and editing YAML files

2021, Mar 21    

YQ

Where this might come handy? GitOps !

In cases like updating values.yaml files when using Helm charts. Updating docker image versions in CI/CD pipelines , to trigger changes & sync in K8S tools. Editing any other file yaml, which carry versions and etc.

Lets take sample YAML file , called “test.yaml” with following content :

# An employee record
name: Martin D'vloper
job: Developer
skill: Elite
employed: True
foods:
  - Apple
  - Orange
  - Strawberry
  - Mango

Lets select “martin” node

yq read test.yaml name 

Output

Martin D'vloper

Now lets try to edit “name” field within YAML file with YQ :

yq w -i test.yaml name "Chris OK"
# An employee record
name: Chris OK
job: Developer
skill: Elite
employed: True
foods:
  - Apple
  - Orange
  - Strawberry
  - Mango