I have a yaml:
global:
resolve_timeout: 5m
receivers:
- name: alerts-null
- name: default
local_configs:
- api_url: https://abx.com
channel: '#abx'
send_resolved: true
username: abc-123
- name: devops-alerts
local_configs:
- api_url: https://abx.com
channel: '#abx'
send_resolved: true
username: abc-123
The yaml can have multiple "name:" elements in the array and I want to loop all "name" elements and change the value for key "username:" to "xyz-321". Resultant YAML should be as follows:
global:
resolve_timeout: 5m
receivers:
- name: alerts-null
- name: default
local_configs:
- api_url: https://abx.com
channel: '#abx'
send_resolved: true
username: xyz-321
- name: devops-alerts
local_configs:
- api_url: https://abx.com
channel: '#abx'
send_resolved: true
username: xyz-321
I tried to use following yq command, but it did not changed the desired key's value:
yq eval '(.receivers[] | select(.name.local_configs.username)) = "xyz-321"' source.yaml > manipulated.yaml
Any pointers are appreciated.