Overview
- Something like Substitution with sed + bash function
But using
yq
- yq of kislyuk not other yq projects https://github.com/kislyuk/yq (
pip install yq
)
Details
I have this bash function :
function replace_image_repo() {
echo "nexus.local/${1}"
}
On the other side, i have a YAML file:
# pod.yaml
kind: Pod
# ...
spec:
containers:
- name: web
image: nginx
- name: logger
image: abdennour/logger
I am able to replace all value occurences of .image
key by a static value:
yq -y '(.. | .image?) |= "mynewimage"' pod.yaml
And the result is as expected:
# pod.yaml
kind: Pod
# ...
spec:
containers:
- name: web
image: mynewimage # <-- Replacement done successfully
- name: logger
image: mynewimage # <-- Replacement done successfully
However, I want to leverage the bash function above replace_image_repo
and call it to calculate the new value for each occurrence based on the current value :
for example,
nginx
must be replaced by the output of$(replace_image_repo nginx)
which should benexus.local/nginx
.Is it possible to match the current value ?
If so , is it possible a call the Bash function "yq -y '.... $(HERE)'" ?