Questions tagged [yq]

yq is the name of two tools for interpreting and processing YAML (one Python based and one Go/CLI based).

yq is the name of two independent tools:

  • Python yq is a wrapper of that reads YAML in, transforms it into JSON and then executes the given commands via jq on it. It also supports processing XML via the executable xq. [GitHub, Documentation, Change log, Issues, PyPI]

  • Go yq implements actions similar to natively on YAML, which means that it can process YAML-specific entities like tags, which Python yq can't. [Github, Documentation]

The two tools do not share the same command line interface and are, in general, not interchangeable with each other. When asking questions about them, you should indicate which one you are using.

337 questions
18
votes
1 answer

How to read values with yq when the key has a dot?

I am having issues reading values from a YAML file when there's a dot in the key name. i.e. a: b.c: 2 Reading the a key works fine with cat mytext.yaml | yq r - a. However, when I tried reading a.b.c it doesn't give any output. I tried escaping…
fisdaf
  • 183
  • 1
  • 1
  • 4
11
votes
1 answer

Merging two yaml documents while concatenating arrays

I want to merge two yaml documents with the result containing all mapped values (with the last one taking precedence) concatenated arrays e.g. given this file # file1.yml animals: - elephant donkey flavours: sour: - lemon sweet: …
Joseph Tura
  • 6,290
  • 8
  • 47
  • 73
11
votes
2 answers

Yq: retrieve object keys names

I have a YAML file (docker-compose file in my case) that looks like this: networks: foo: some_opts: "covfefe" bar: some_opts: "such wow" services: apache: image: 'apache:1.0.0' restart: always mysql: image:…
Pierre
  • 2,552
  • 5
  • 26
  • 47
10
votes
3 answers

Print keys in yaml, so that they can be used for jsonpath

echo "apiVersion: v1 kind: Node metadata: name: host-cluster-control-plane-64j47 labels: beta.kubernetes.io/arch: amd64 " | yq -o p Result: apiVersion = v1 kind = Node metadata.name =…
guettli
  • 25,042
  • 81
  • 346
  • 663
10
votes
1 answer

Using yq to edit yaml files (--in-place, -i flag)

I'm having a big problem with the edit in place flag for yq version 2.12.0. We are trying to update a value for a variable in one of our .yaml scripts. The before looks like this... authentication: anonymous: enabled: false But we want…
iej94
  • 191
  • 1
  • 2
  • 8
10
votes
2 answers

How to prevent yq removing comments and empty lines?

Here Edit yaml objects in array with yq. Speed up Terminalizer's terminal cast (record) I asked about how to edit yaml with yq. I received the best answer. But by default yq removes comments and empty lines. How to prevent this behavior? input.yml #…
kyb
  • 7,233
  • 5
  • 52
  • 105
9
votes
7 answers

Using yq in for loop bash

I have a yaml array like below, identitymappings: - arn: "arn:aws:iam::12345567:role/AdmRole" group: "system:masters" user: "user1" - arn: "arn:aws:iam::12345567:role/TestRole" group: "system:masters" user: "user2" I am trying to parse this…
Rad4
  • 1,936
  • 8
  • 30
  • 50
8
votes
2 answers

Is jq installed and available on PATH?

I am trying to read a yaml file in gitlab CI. I installed jq==1.0.2 and yq==2.10.1 using pip in my CI job and I use python:3.7 image. When I tried to read the yaml file, it has the error yq: Error starting jq: FileNotFoundError: [Errno 2] No such…
Serena Xu
  • 219
  • 5
  • 10
8
votes
3 answers

Replace value in yaml if name : xxx with bash

I want to change yaml file value based on name: Example: spec: containers: - name: app1 image: imageurl.com command: [] env: - name: MONGO_HOST value: localhost Here you can see we have added an env for mongo…
Ranvijay Sachan
  • 2,407
  • 3
  • 30
  • 49
8
votes
4 answers

How to use `yq` to set a property to a multi-line string?

I have a certificate file that looks similar to: -------BEGIN CERTIFICATE------- asdoqijepoqjwe1i49i120941p2j4omslasdajsdqweqwe qwelqjwkasdlajsölkjasldkjakljsdlkjasdasdpiqwe -------END CERTIFICATE-------- I also have a YAML file (an OpenShift…
relief.melone
  • 3,042
  • 1
  • 28
  • 57
7
votes
2 answers

Update nested array value in yaml with yq

Given a yaml file (helmfile) like the following releases: - chart: ../charts/foo name: foo namespace: '{{ .Values.stack }}' values: - ../config/templates/foo-values.yaml.gotmpl set: - name: image.tag value: 22 …
Banjer
  • 8,118
  • 5
  • 46
  • 61
6
votes
1 answer

Update a specific object value under YAML based on a condition using yq

Using https://github.com/mikefarah/yq v4 Given a sample.yaml file like this: spec: chart: name: my-chart version: 0.0.1 --- spec: chart: name: something-else version: 0.0.2 I want to update the version value but only for the…
Crichard
  • 61
  • 1
  • 3
6
votes
1 answer

Error: yq@3 has been disabled because it is not maintained upstream! How to install a disabled brew Formulae?

I'm trying to install yq@3 on my Mac running brew install yq@3 and I get the error: Error: yq@3 has been disabled because it is not maintained upstream! I see that it's there on their website at https://formulae.brew.sh/formula/yq@3#default but it…
Claude Roy
  • 147
  • 2
  • 5
6
votes
2 answers

How to patch multi document yaml file on condition using yq?

Having YAML document something like: --- apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-scraping --- apiVersion: apps/v1 kind: Deployment metadata: name: allow-webhooks I am trying to get something…
Mike Chaliy
  • 25,801
  • 18
  • 67
  • 105
6
votes
1 answer

yq processing a string with quotation marks

Currently I am trying to exchange a string but WITH double quotes in a YAML file with the mikefarah/yq processor (version 3.1.2 on an Ubuntu machine) similar to the following: config: app: name: "string" So I tried to solve this classically…
DrRetro
  • 63
  • 1
  • 3
1
2 3
22 23