How to save linux command output to a variable in puppet

Is it possible to save the linux command line result in a variable?

I am trying to store an encrypted value in a variable. For encryption, I use the base64 command. To save it in a variable, I use the generate method. But I can’t keep the value.

$secretvalue = generate("/bin/bash","-c","/usr/bin/echo ${password} | /usr/bin/base64") 
+7
linux bash puppet puppet-enterprise
source share
1 answer

If you want to execute any command on the Puppet Master server, you can use the inline_template function with the ERB template inside and the Ruby code to execute the shell command:

 $password = "12345" $secretvalue = inline_template("<%= `/bin/echo ${password} | /usr/bin/base64` %>") notify { "STDOUT: ${secretvalue}": } 

PS If you just want to encode a string in Base64 format, you can import puppetlabs-stdlib and use the base64 function from it:

 $secretvalue = base64('encode', $password) 
+9
source share

All Articles