Skip to content

Unexpected content added to yaml file #1907

Answered by mikefarah
dmitchsplunk asked this question in Q&A
Discussion options

You must be logged in to vote

Just add a select first to only select documents that you want updated.

It'll be something like:

 yq eval -i '(select(.spec.template.spec.containers) | .spec.template.spec.containers[].env) += {
      "name": "NODE_IP",
      "valueFrom": {
        "fieldRef": {
          "fieldPath": "status.hostIP"
        }
      }
    }
    ' opentelemetry-demo.yaml

You can put boolean expression in select to check for length and other things too - similar to this example here: https://mikefarah.gitbook.io/yq/recipes#find-and-update-items-in-an-array

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dmitchsplunk
Comment options

Answer selected by dmitchsplunk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants