如何将linux命令输出存储到puppet中的变量中

时间:2021-01-07 00:37:35

Is it possible to store a linux command result in variable?

是否可以将linux命令结果存储在变量中?

I am trying to store an encrypted value in a variable. To encrypt I am using base64 command. To store it in variable, I am using generate method. But I am not able to store a value.

我试图将加密值存储在变量中。加密我正在使用base64命令。要将它存储在变量中,我使用的是generate方法。但我无法存储价值。

$secretvalue    = generate("/bin/bash","-c","/usr/bin/echo ${password} | /usr/bin/base64")

1 个解决方案

#1


10  

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

如果要在Puppet Master服务器上执行任何命令,可以使用带有ERB模板的inline_template函数和用于执行shell命令的Ruby代码:

$password = "12345"

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

notify { "STDOUT: ${secretvalue}": }

P.S. If you just want to encode string to Base64 format you can import puppetlabs-stdlib module and use base64 function from it:

附:如果您只想将字符串编码为Base64格式,您可以导入puppetlabs-stdlib模块并使用它的base64函数:

$secretvalue = base64('encode', $password)

#1


10  

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

如果要在Puppet Master服务器上执行任何命令,可以使用带有ERB模板的inline_template函数和用于执行shell命令的Ruby代码:

$password = "12345"

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

notify { "STDOUT: ${secretvalue}": }

P.S. If you just want to encode string to Base64 format you can import puppetlabs-stdlib module and use base64 function from it:

附:如果您只想将字符串编码为Base64格式,您可以导入puppetlabs-stdlib模块并使用它的base64函数:

$secretvalue = base64('encode', $password)