gre*_*son 10 puppet vagrant hiera
我想知道如何建立:datadir:
在hiera.yaml
与日伪和流浪最佳利用。目前我在 Ubuntu 13.10 上使用 vagrant 1.5.0 和 virtualbox 4.2,Ubuntu 12.04 来宾运行 puppet 3.1.1
我正在尝试设置一个类似于这篇博文Puppet Best Practices: Environment specific configs 的环境。具体来说,我的 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
Run Code Online (Sandbox Code Playgroud)
我可以确认hiera_config_path
是正确的,因为如果我删除hiera.yaml
.
puppet/hiera.yaml
包含:
---
:backends: yaml
:yaml:
:datadir: "manifests/configuration"
:hierarchy:
- "%{::clientcert}"
- "%{::environment}"
- "virtual_%{::is_virtual}"
- common
:logger: console
Run Code Online (Sandbox Code Playgroud)
此外,还puppet/manifests/configuration/common.yaml
包含:
---
myvar: "test"
Run Code Online (Sandbox Code Playgroud)
从命令行测试:
$ hiera -c hiera.yaml myvar
test
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好。但是,如果我尝试从人偶清单文件中对此进行测试,则无法找到该变量,并且会出现错误。示例测试:
$myvariable = hiera(myvar)
notice("My variable is: ${myvar}")
Run Code Online (Sandbox Code Playgroud)
错误是:
Error: Could not find data item myvar in any Hiera data file and no default supplied at...
Run Code Online (Sandbox Code Playgroud)
如果我通过 ssh 进入我的机器vagrant ssh
,我可以看到 Vagrant 正在 /tmp/vagrant-puppet-2 挂载我的清单目录。如果我编辑hiera.yaml
文件并替换:datadir:
为完整路径/tmp/vagrant-puppet-2/manifests/configuration
,则我的 Puppet 清单可以访问我的 Hiera 数据。不过,我可以用相对路径来做到这一点吗?
我在记录我的问题时找到了解决方案。将 :datadir: 更改为:
:datadir: "%{settings::manifestdir}/configuration"
Run Code Online (Sandbox Code Playgroud)
Puppet 将在 $settings::manifestdir 中提供清单目录的路径。将 Hiera 数据存储在清单目录中很有用,因为 Vagrant 会在来宾系统中运行 Puppet 之前显式挂载此目录,而您为此目的选择的其他目录可能不可用。
归档时间: |
|
查看次数: |
10840 次 |
最近记录: |