yq/pkg/yqlib/doc/operators/envsubst.md

1.1 KiB

Envsubst

This operator is used to replace environment variables in strings using envsubst.

To replace environment variables across all values in a document, this can be used with the recursive descent operator as follows:

yq eval '(.. | select(tag == "!!str)) |= envsubst' file.yaml

Replace strings with envsubst

Running

myenv="cat" yq eval --null-input '"the ${myenv} meows" | envsubst'

will output

the cat meows

Replace strings with envsubst, missing variables

Running

myenv="cat" yq eval --null-input '"the ${myenvnonexisting} meows" | envsubst'

will output

the  meows

Replace strings with envsubst, missing variables with defaults

Running

myenv="cat" yq eval --null-input '"the ${myenvnonexisting-dog} meows" | envsubst'

will output

the dog meows

Replace string environment variable in document

Given a sample.yml file of:

v: ${myenv}

then

myenv="cat meow" yq eval '.v |= envsubst' sample.yml

will output

v: cat meow