Issue
I've been trying to update helm values.yaml with a randomized password.
My approach is to add a placeholder
like
global:
my_password: "password-placeholder"
another_service
service_password: "password-placeholder"
I tried to generate password with openssl rand -base64 12
. I'm looking for a string replacement bash command which can loop and create these password.
Tried yq
but it has a bug where it removes some comments in the file.
Tried sed
but not sure how to replace the password-placeholder
with a unique password everytime.
Looking for suggestions.
Solution
You could use awk
for that:
awk -v placeholder='password-placeholder' '
$0 ~ placeholder {
cmd = "openssl rand -base64 12"
cmd | getline pass
close(cmd)
sub(placeholder,pass)
} 1
' file.yml
explanations:
$0 ~ placeholder {...}
selects the lines that match the regex contained inplaceholder
and executes...
for them."openssl rand -base64 12" | getline pass
loads the result of the openssl command into thepass
variablesub(placeholder,pass)
replaces (in the current line) the first match of the regexplaceholder
with the content ofpass
1
prints each line
Answered By - Fravadona Answer Checked By - Pedro (WPSolving Volunteer)