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
6
votes
2 answers

yq to get values from key value pair

I have a simple values.yaml file which has below data: images: tags: one: abc:v0.3-16-07 two: xyz:ng-0.23.0 pq: qaa:0df1e21e752b3d3.2020-04-27_1 Using yq -r --yaml-output ".images.tags" values.yaml I can get below output one:…
Saurabh Arora
  • 377
  • 2
  • 4
  • 11
5
votes
1 answer

Filer an array of objects with yq

I have a yaml file that looks like this: apiVersion: v1 entries: blue-green-toggle: - description: Used to toggle an application between blue and green name: blue-green-toggle version: 1.0.17 apiVersion: v2 - description: Used to…
Vaccano
  • 78,325
  • 149
  • 468
  • 850
5
votes
2 answers

Programatically apply a single resource from a multi resource Kubernetes YAML file

I have a file with three configmaps in it, like the one below. apiVersion: v1 data: TEST: "one" kind: ConfigMap metadata: name: test-config-one --- apiVersion: v1 data: TEST: "two" kind: ConfigMap metadata: name:…
dan
  • 1,944
  • 1
  • 15
  • 22
5
votes
3 answers

How to insert or add a field in a yaml after a specific key in yq

I have a k8s yaml file with below block spec: replicas: 1 strategy: type: Recreate and I want to add below block after "spec:" selector: matchLabels: app: test-app The file is huge and has many "spec:" fields, so it should be added…
karthik101
  • 1,619
  • 4
  • 17
  • 23
4
votes
0 answers

Use yq to add a new root

I am trying to add a new root to an existing yaml. I have a values.yaml file with the following content key1: value1 key2: value2 key3: key31: value31 key32: value32 And I am trying to add a root to the existing yaml. mainkey: key1: value1 …
Vini
  • 1,978
  • 8
  • 40
  • 82
4
votes
3 answers

How to use `yq` to select key-value pairs and format them into "$key=$value" style outputs?

Let say I have YAML file that looks like this: FOO: somefoo BAR: somebar I would like to convert this (using yq) into the following so that I can source the contents into environment variables: export BAR='somebar' export FOO='somefoo' I can do it…
Karl
  • 5,573
  • 8
  • 50
  • 73
4
votes
2 answers

yq replace value in manifest yaml

I have a k8s manifest file for loadbalancer below and cannot for the life of me get the $ipaddress be replaced with value, I have got to to overwrite whole file or part of or even just leave blank. How can I replace only the $ipaddress like in…
DeclanG
  • 240
  • 2
  • 6
  • 21
4
votes
2 answers

yq - issue adding yaml into yaml

Hi I would like to update a yaml like string into a yaml i do have the following yaml file argocd.yaml --- apiVersion: argoproj.io/v1alpha1 kind: Application metadata: namespace: mynamespace name:my-app spec: project: xxx destination: …
Alex Ortner
  • 1,097
  • 8
  • 24
4
votes
2 answers

How to Add / Replace array elements with "yq" conditionally

I am looking for some help with using "yq" to replace / add existing array elements by name. Also conditionally? Appreciate your help in this regard. I have tried the below so far.. but this just merges and I am getting duplicates when I rerun this…
3
votes
2 answers

Reading key value pairs from yaml and storing in associative array bash

In below yaml, I want to iterate through the states and capture both key, value to create associative arrays for each state and then print them. Note: I'm using yq from mikefarah repo. data.yaml data: continent: countries: - state1: …
jagatjyoti
  • 699
  • 3
  • 10
  • 29
3
votes
1 answer

How to verify if the github syntax variables actually exist in github actions workflow yaml?

I have list of jenkins jobs which I'm converting to github actions using github actions importer. Some conversions are adding syntax like ${{ env.some_variable }} But some of those converted workflow files doesn't have some_variable in the env…
Underoos
  • 4,708
  • 8
  • 42
  • 85
3
votes
2 answers

YQ edit files with multiple document in place

I have a YAML file with 2 documents # template.yaml a : 1 --- b : 2 I'm trying to edit the YAML file inplace. I've tried using # yq4 yq -i ' select(documentIndex == 0) | .a = 3 | select(documentIndex == 1) | .b = 4 '…
Anugerah Erlaut
  • 990
  • 13
  • 23
3
votes
1 answer

Dynamically fetch values using env variable from yaml file using yq

I'm trying to get the values of tenants in below yaml file using yq. The intent is to dynamically fetch the value depending on env variable. Let's assume there's an env variable var="az-dev", then tenants of az-dev should be retrieved. I have given…
jagatjyoti
  • 699
  • 3
  • 10
  • 29
3
votes
2 answers

yq (GO/Mike Farah) uniquify all arrays recursively

This is probably related to another question I posted: yq (GO/Mike Farah) sort all arrays recursively? Mike Farah's yq provides documentation for making arrays unique but I'm having trouble figuring how to apply that to lists that are nested…
Mark Miller
  • 3,011
  • 1
  • 14
  • 34
3
votes
2 answers

yq (GO/Mike Farah) sort all arrays recursively?

This is probably related to another question I posted: yq (GO/Mike Farah) uniquify all arrays recursively Mike Farah's yq provides documentation for sorting arrays but I'm having trouble figuring how to apply that to a list that is nested…
Mark Miller
  • 3,011
  • 1
  • 14
  • 34
1
2
3
22 23