如何将Linux命令输出存储到puppet中的变量中 [英] How to store linux command output into a variable in puppet
问题描述
是否可以将Linux命令结果存储在变量中?
Is it possible to store a linux command result in variable?
我正在尝试将加密值存储在变量中.为了加密,我正在使用base64命令.要将其存储在变量中,我正在使用generate方法.但是我无法存储值.
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.
$secretvalue = generate("/bin/bash","-c","/usr/bin/echo ${password} | /usr/bin/base64")
推荐答案
如果要在Puppet Master服务器上执行任何命令,可以将inline_template
函数与ERB模板一起使用,并使用Ruby代码执行shell命令:
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:
$password = "12345"
$secretvalue = inline_template("<%= `/bin/echo ${password} | /usr/bin/base64` %>")
notify { "STDOUT: ${secretvalue}": }
P.S.
如果您只想将字符串编码为Base64格式,则可以导入 puppetlabs-stdlib 模块并使用base64
函数:
P.S.
If you just want to encode string to Base64 format you can import puppetlabs-stdlib module and use base64
function from it:
$secretvalue = base64('encode', $password)
这篇关于如何将Linux命令输出存储到puppet中的变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!