How to execute a shell command and input that output inside yaml data

Viewed 1138

I have a yaml file and a shell script having curl requests with below logic. I need to get the output of shell script and place it in the yaml data value.

For eg: shell script logic:

servers=`curl test.com/servers` 
for a in servers; do
  val=`curl $a/number`
  if [$val == 0]
    output=`curl $a/ip`
done
echo $output

If value of $output is programming, then I need test.yaml:

name: test
config: $get_output_value_from_shell  #config: programming

It could be really helpful if someone helps me to solve this. I need to achieve this in helm.

1 Answers

Your shell script should be able to just write the file.

output=$(curl "$a/ip")
cat >install-values.yaml <<EOF
name: test
config: $output
EOF

You also might consider a higher-level language to achieve this; for example, Python has requests and pyyaml libraries that can be combined to assemble a YAML file from HTTP requests, and it will be easier to get quoting and escaping correct than in a shell script.

Helm itself can neither invoke external commands nor make arbitrary HTTP requests, so you need to do this in some tool before you run helm.

Related