尝试将 hiera 与 vagrant 和 puppet 一起使用

Trying to use hiera with vagrant and puppet

所以我正在尝试使用 hiera 来更改我设置 git user.name 和 user.email 的方式。在我的流浪盒子上。

我的 default.pp

里有这个
git::config { 'user.name':
    value => hiera("github_username"),
}

git::config { 'user.email':
    value => hiera("github_email"),
}

在 Vagrant 文件中我有这个(在人偶选项中):

puppet.options = "--hiera_config /vagrant/hieradata/hiera.yaml"

这似乎加载正确。我在该文件中的内容是:

---
:backends:
  - yaml
:hierarchy:
  - defaults
  - "%{clientcert}"
  - "%{environment}"
  - global
  - company

:yaml:
  :datadir:/vagrant/hieradata

现在 company.yaml 我有:

github_username: 'antonio'
github_email: 'antonio@mail.com'

当我执行 vagrant provision 时,我收到以下错误消息:

==> debian_dev: Error: Error from DataBinding 'hiera' while looking up 'apache::apache_name': can't convert Symbol into Integer on node debian.dev
==> debian_dev: Wrapped exception:
==> debian_dev: can't convert Symbol into Integer
==> debian_dev: Wrapped exception:
==> debian_dev: can't convert Symbol into Integer
==> debian_dev: Error: Error from DataBinding 'hiera' while looking up 'apache::apache_name': can't convert Symbol into Integer on node debian.dev
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

我正在使用 apache 模块,但即使在默认 hiera.yaml(位于 /etc/hiera.yaml 的模块)中也没​​有 apache::apache_name.

的定义

如果我不将选项传递给 puppet in 只是抱怨找不到 hiera.yaml 并且它将使用默认选项。

关于如何解决这个问题有什么想法或建议吗?

谢谢!

PS: 我是 运行 windows 7,Vagrant 1.6.5 和 puppet 3.7.1

更新您的 hiera.yaml 文件,使数据目录中有一个 space:

:yaml:
  :datadir: /vagrant/hieradata

为了帮助调试,我建议在您的 Vagrantfile 中添加详细和调试选项:

config.vm.provision "puppet" do |puppet|
  puppet.options = "--verbose --debug"
end

以下是错误的 datadir 值应该看到的内容:

$ vagrant provision
==> other: Running provisioner: puppet...
==> other: Running Puppet with default.pp...
==> other: stdin: is not a tty
==> other: Notice: Scope(Node[default]): -----
==> other: Debug: hiera(): Hiera YAML backend starting
==> other: Debug: hiera(): Looking up github_username in YAML     backend
==> other: Debug: hiera(): Looking for data source defaults
==> other: Debug: hiera(): Found github_username in defaults    

这是更新数据目录后您应该看到的内容:

$ vagrant provision
==> other: Running provisioner: puppet...
==> other: Running Puppet with default.pp...
==> other: stdin: is not a tty
==> other: Notice: Scope(Node[default]): -----
==> other: Debug: hiera(): Hiera YAML backend starting
==> other: Debug: hiera(): Looking up github_username in YAML     backend
==> other: Debug: hiera(): Looking for data source defaults
==> other: Debug: hiera(): Found github_username in defaults

这也应该有助于解释当 hiera 进行查找时如何找到值。