Add item to list in yq if it doesn't already exist

Using mikefarah’s yq v4 I want to conditionally add an IP address to a list within a yml file if it does not exist in the list already. Given a file like: servers: web: – 1.1.1.1 jobs: – 2.2.2.2 If 1.1.1.1 was attempted to be added it should not change, if 3.3.3.3 was added to… Read More Add item to list in yq if it doesn't already exist

Delete an entry with the key matching regex using yq

I have a json like this: { "sha256key": [ "438143050f234146300c44ed7e22be698e1e3c8c6bbc89b5c7e6276e8250a3a7" ], "validkey": [ "77989d8d29d044112026eae94fe27e9df9ae29d9987d38bcdf470100175def76", "3c91a35a4e12eb89c8f25381f29438f270e9b0af1ef0cbcd416581cd7fe06a0e" ], } I want to remove all entries which have the key started with sha256 Expected result: { "validkey": [ "77989d8d29d044112026eae94fe27e9df9ae29d9987d38bcdf470100175def76", "3c91a35a4e12eb89c8f25381f29438f270e9b0af1ef0cbcd416581cd7fe06a0e" ], } I have tried yq ‘del(select(.key | test("^sha256.")) this does nothing I’m using go yq >Solution :… Read More Delete an entry with the key matching regex using yq

Update a specific value in a nested array by applying a condition on the parent (name or key) to proceed further in YAML using yq command

Let say my YAML is : releases: – chart: ../charts/foo name: foo namespace: ‘{{ .Values.stack }}’ values: – ../config/templates/foo-values.yaml.gotmpl set: – name: image.tag value: 22 – name: replicas value: 1 – chart: ../charts/bar name: bar namespace: ‘{{ .Values.stack }}’ values: – ../config/templates/bar-values.yaml.gotmpl set: – name: image.bar_proxy.tag value: 46 – name: image.bar.tag value: 29 – name:… Read More Update a specific value in a nested array by applying a condition on the parent (name or key) to proceed further in YAML using yq command

How to update an element in array using yq by not using the index, but rather some contextual info, like a name

this is the input apiVersion: v1 kind: Pod metadata: creationTimestamp: null name: kube-vip namespace: kube-system spec: containers: – args: – start env: – name: vip_arp value: "true" – name: vip_leaderelection value: "true" – name: vip_address value: – name: vip_interface value: eth0 – name: vip_leaseduration value: "15" – name: vip_renewdeadline value: "10" – name: vip_retryperiod value:… Read More How to update an element in array using yq by not using the index, but rather some contextual info, like a name

Is it possible to slice a list and write it back to a YAML file with YQ

If I have a file like this: name: test host: test.com region: us-east-1 plannedMaintenancePeriods: – startTime: 1679987700 endTime: 1679992500 – startTime: 1679987700 endTime: 1679992500 – startTime: 1679987700 endTime: 1679992500 – startTime: 1679987700 endTime: 1679992500 – startTime: 1679987700 endTime: 1679992500 – startTime: 1679987700 endTime: 1679992500 – startTime: 1679987700 endTime: 1679992500 – startTime: 1679987700 endTime: 1679992500 -… Read More Is it possible to slice a list and write it back to a YAML file with YQ

Shell variable subsitution in makefile

I would like to have command in Makefile that allows me to change service’s target in docker-compose.yaml respectively to target given command parameter. I have something like this: example: @[[ "$${target:-dev}" == @(dev|test|release) ]] || exit 1 yq -y -i ‘.services."$(service)".build.target = "$(target)"’ docker-compose.yaml This almost do the job, but I have this parameter to… Read More Shell variable subsitution in makefile