如何设置:datadir:使用木偶和stream浪汉的Hiera

我想知道如何设置:datadir: hiera.yaml与Puppet和Vagrant的最佳使用。 目前,我在Ubuntu 13.10上使用了vagrant 1.5.0和virtualbox 4.2,并且运行了puppet 3.1.1的Ubuntu 12.04 guest

我试图build立一个类似于这个博客的环境, 木偶最佳实践:环境特定的configuration 。 具体来说,我的Vagrantfile包含:

  config.vm.define "servername" do |servername| servername.vm.box = "precise-puppet-3" servername.vm.network "private_network", ip: "192.168.213.2", virtualbox__intnet: "networkname" # Provision with puppet. servername.vm.provision :puppet do |puppet| puppet.hiera_config_path = "puppet/hiera.yaml" puppet.manifests_path = "puppet/manifests" puppet.module_path = "puppet/modules" puppet.manifest_file = "servername.pp" puppet.facter = { "vagrant" => "1", "server" => "servername", } end end 

我可以确认hiera_config_path是正确的,因为如果我删除hiera.yaml ,我得到一个错误。

puppet/hiera.yaml包含:

 --- :backends: yaml :yaml: :datadir: "manifests/configuration" :hierarchy: - "%{::clientcert}" - "%{::environment}" - "virtual_%{::is_virtual}" - common :logger: console 

此外, puppet/manifests/configuration/common.yaml包含:

 --- myvar: "test" 

从命令行testing:

 $ hiera -c hiera.yaml myvar test 

到现在为止还挺好。 但是,如果我尝试从puppet清单文件中testing此variables,则无法findvariables,并且出现错误。 示例testing:

 $myvariable = hiera(myvar) notice("My variable is: ${myvar}") 

错误是:

 Error: Could not find data item myvar in any Hiera data file and no default supplied at... 

如果我通过vagrant ssh ssh进入我的机器,我可以看到stream浪者正在将我的清单目录安装在/ tmp / vagrant-puppet-2上。 如果我编辑hiera.yaml文件,并用完整path/tmp/vagrant-puppet-2/manifests/configurationreplace:datadir:则我的Puppet清单可以访问我的Hiera数据。 我可以用相对path来做这个吗?

我在logging我的问题的同时find了解决scheme。 更改:datadir:读取:

  :datadir: "%{settings::manifestdir}/configuration" 

Puppet将提供$ settings :: manifestdir中manifest目录的path。 将Hiera数据存储在manifest目录中非常有用,因为Vagrant会在来宾系统中运行Puppet之前显式挂载此目录,而您为此select的其他目录可能不可用。

我正在处理的hiera.yaml指定:datadir: /etc/puppet/hiera ,我没有将--yamldir选项设置为指定的其他答案。 但是,过了一会儿,我意识到我可以将我的数据映射到guest虚拟机上的那个位置:

 config.vm.synced_folder "../puppet/hiera", "/etc/puppet/hiera" 

这很好地工作:-)

这就是我在自己的木偶实验中所做的事情。

 VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box = "puppetlabs/debian-7.8-64-puppet" # source box on atlas config.vm.hostname = "wheezybox" # hostname of box # Include Hiera Data Directory (no automatic option for this) config.vm.synced_folder "../../hieradata", "/tmp/vagrant-puppet/hieradata" # Puppet Configuration config.vm.provision :puppet do |puppet| puppet.manifests_path = "../../manifests/" puppet.manifest_file = "site.pp" puppet.module_path = ["../../modules/"] # shared modules puppet.hiera_config_path = "../../hiera.yaml" # hiera config file puppet.working_directory = "/tmp/vagrant-puppet" # default hiera path puppet.options = "--verbose --debug" end end 

我的极简主义hiera.yaml看起来像这样:

 --- :backends: - yaml :yaml: :datadir: "hieradata" :hierarchy: - "node/%{::hostname}" 

而为了说明的目的,主机(MacBook)上的目录结构如下所示:

  . ├── hiera.yaml ├── hieradata │  └── node │  ├── centos6box.yaml │  ├── precisebox.yaml │  └── wheezybox.yaml ├── manifests │  └── site.pp ├── modules -> ../puppet-common/modules/ └── vagrants ├── README.md ├── centos6 │  └── Vagrantfile ├── precise │  └── Vagrantfile └── wheezy └── Vagrantfile 

你最初的问题是:datadir需要是一个绝对path。 Hiera不允许你指定:datadir相对path。 如果您觉得这应该被允许,请提交一个请求来改变它 。

manifestdir已弃用 。 您可能更喜欢使用yamldir 。 当你通过傀儡申请时,你可以覆盖该设置。

对于stream浪汉来说:

  servername.vm.provision :puppet, :options => ["--yamldir some/absolute/path"] do |puppet| puppet.hiera_config_path = "puppet/hiera.yaml" puppet.manifests_path = "puppet/manifests" puppet.module_path = "puppet/modules" puppet.manifest_file = "servername.pp" puppet.facter = { "vagrant" => "1", "server" => "servername", } end 

更新 :因为你需要提供一个绝对path(因为stream浪),所以你应该build立你自己的共享文件夹,这样你就可以清楚地知道它在哪里,而不是为了傀儡执行而在stream浪的path上做出假设。 将此添加到您的Vagrantfile

 config.vm.synced_folder "puppet/manifests/configuration", "/hieradata" 

然后将上面的第一行更改为:

 servername.vm.provision :puppet, :options => ["--yamldir /hieradata"] do |puppet|