需要在哈希表中定义类型

时间:2018-02-07 17:41:51

标签: puppet

我有一个名为profile_winsql_dbengine::resources::sqlconfighelper的已定义类型,它调用exec块并且工作正常。

我在init清单中使用以下create resource语句:

create_resources( profile_winsql_dbengine::resources::sqlconfighelper, $sqlconfighelperhash )

哈希声明如下:

$sqlconfighelperhash = {
    'config1' => {
      param1     => $param1,
      param2     => $param2,
    },
    'config2' => {
      param1     => $param1,
      param2     => $param2,
      require    => Profile_winsql_dbengine::Resources::Sqlconfighelper['config1'],
    }
}

除了require之外,一切都按预期工作。 require抛出了编译错误,告诉我它无法找到Profile_winsql_dbengine::Resources::Sqlconfighelper['config1']

语法编译,如果没有require,它会按预期应用配置文件。我应该做些什么来使require工作?

1 个答案:

答案 0 :(得分:0)

我无法使用最新的Puppet 5.3.4重现这一点。

我的代码:

# /tmp/test.pp
define test::my_type($message, $withpath) {
  notify { $name:
    message  => $message,
    withpath => $withpath,
  }
}

class test (
) {
  $data = {
    'message1' => {
      message  => 'I am message 1',
      withpath => false,
      require  => Test::My_type['message2'],
    },
    'message2' => {
      message  => 'I am message 2',
      withpath => false,
    }
  }
  create_resources(test::my_type, $data)
}

include test

然后:

$ puppet apply /tmp/test.pp
Notice: Compiled catalog for alexs-macbook-pro.local in environment production in 0.06 seconds
Notice: I am message 2
Notice: /Stage[main]/Test/Test::My_type[message2]/Notify[message2]/message: defined 'message' as 'I am message 2'
Notice: I am message 1
Notice: /Stage[main]/Test/Test::My_type[message1]/Notify[message1]/message: defined 'message' as 'I am message 1'
Notice: Applied catalog in 0.05 seconds

也许你的某个地方可能有拼写错误?