0

我正在尝试将参数从工头推送到我的 puppet 类以生成配置文件。

每个文件应该是这样的:

file1
DB_USERNAME=toto
DUMP_TYPE=full
[...]

file2
DB_USERNAME=toto
DUMP_TYPE=full
[...]

我在 Foreman 中定义了一个参数,它是一个哈希数组

bacula_client dumpCfg  [{"techno"=>"oracle", "DB_USERNAME"=>"toto", "DUMP_TYPE"=>"full", ...},
{"techno"=>"mysql", "DB_USERNAME"=>"toto", "DUMP_TYPE"=>"full",    ...}]

我想知道是否可以执行类似的操作来生成例如 2 个不同的配置文件,因为我在调用 dumpdb 时得到“资源标题必须是字符串”

class bacula_client (

$isDirector    = false,
$backupCrons   = [],
$isHostConcentrator = false,
$dumpCfg = [],

define bacula_client::dumpdb () {

    $techno     = $name['techno']
    $dbusername       = $name['DB_USERNAME']
    $dumptype        = $name['DUMP_TYPE']

    # call a function that generates the files
  } 
 [.....]
}#myclass

bacula_client::dumpdb{$dumpCfg:} 

先感谢您,

4

1 回答 1

1

错误信息说明了一切。您正在使用哈希命名资源。应该是字符串。

试试这种方式:

define bacula_client::dumpdb ($dumpCfg) {

    $techno     = $dumpCfg['techno']
    $dbusername       = $dumpCfg['DB_USERNAME']
    $dumptype        = $dumpCfg['DUMP_TYPE']

    # call a function that generates the files
  } 


bacula_client::dumpdb{'file1': dumpCfg => $dumpCfg[0] }
bacula_client::dumpdb{'file2': dumpCfg => $dumpCfg[1] }

注意“file1”和“file2”。这些资源名称必须是字符串并且必须是唯一的。数据作为参数传入。

不确定您的数组/哈希使用是否有效。没有测试,我也不经常以这种方式传递数据。

帮自己一个忙,把你的定义放在它自己的文件中,而不是放在班级中间。以后会省去你的头疼(就像我试图理解过去 2 年积累的各种乐趣的 400 多个线路课程一样)。

编辑:语法

于 2014-01-22T00:27:15.607 回答