How to store linux command output into a variable in puppet

我们两清 提交于 2019-12-18 16:45:09

问题


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

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")

回答1:


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. 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)


来源:https://stackoverflow.com/questions/33800565/how-to-store-linux-command-output-into-a-variable-in-puppet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!