【问题标题】:Puppet defined resources and hiera jsonPuppet 定义的资源和 hiera json
【发布时间】:2014-02-07 22:06:18
【问题描述】:

尝试将 hiera 与 puppet 一起使用。我想知道我怎么能把这样的东西移到hiera:

定义:

define apache::namevirtualhost {
  $addr_port = $name

  # Template uses: $addr_port
  concat::fragment { "NameVirtualHost ${addr_port}":
    target  => $apache::ports_file,
    content => template('apache/namevirtualhost.erb'),
  }
}

然后在我的 super_node.pp 中:

apache::namevirtualhost { '*:80': }

如何将 '*:80' 移动到 hiera json 文件?像这样的东西(似乎不起作用):

{
    "apache::namevirtualhost" : "*:80"
}

如果我多次包含定义,同样的问题,我如何将配置移动到 hiera:

  vagrant::box { 'dev.local':
    sshport       => '2223',
    ip            => '10.69.69.101'
  } 

  vagrant::box { 'it.local':
    sshport       => '2224',
    ip            => '10.69.69.102'
  } 

【问题讨论】:

    标签: puppet hiera


    【解决方案1】:

    只需在您的清单中使用 hiera 函数,因此在您的 super_node.pp 中:

    $namevirtualhost = hiera("apache::namevirtualhost")
    apache::namevirtualhost { $namevirtualhost : }
    

    你的盒子也一样:

      vagrant::box { 'dev.local':
        sshport       => hiera("dev_local_sshport"),
        ip            => hiera("dev_local_ip"),
      }
    

    首先,您应该确保通过键入正确配置 hiera 数据库

    hiera "apache::namevirtualhost"
    

    从命令行

    【讨论】:

    • 你测试过你的答案了吗?:你建议的 'apache::namevirtualhost { hiera("apache::namevirtualhost"): }' 给了我“错误:无法解析环境生产:语法错误':';预期为 '}'"
    • 对不起,但实际上我无法检查语法,也许 puppet 不喜欢 resource{ foo(): } 语法。但是 hiera 调用是打印出来的,并且将与命令行 hiera variablename 一样工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多