简体   繁体   English

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

[英]How to store linux command output into a variable in puppet

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. 加密我正在使用base64命令。 To store it in variable, I am using generate method. 要将它存储在变量中,我使用的是generate方法。 But I am not able to store a value. 但我无法存储价值。

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

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}": }

PS If you just want to encode string to Base64 format you can import puppetlabs-stdlib module and use base64 function from it: PS如果您只想将字符串编码为Base64格式,您可以导入puppetlabs-stdlib模块并使用它的base64函数:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM