Vagrant在提供 Puppet 事实方面具有很大的实用性:
facter (hash) - 在 Puppet 运行中设置为可用因子变量的数据散列。
例如,这是我的 Vagrantfile 中带有 Puppet 设置的片段:
config.vm.provision "puppet", :options => ["--fileserverconfig=/vagrant/fileserver.conf"] do |puppet|
puppet.manifests_path = "./"
puppet.module_path = "~/projects/puppet/modules"
puppet.manifest_file = "./vplan-host.pp"
puppet.facter = {
"vagrant_puppet_run" => "true"
}
end
然后我们利用这个事实,例如:
$unbound_conf = $::vagrant_puppet_run ? {
'true' => 'puppet:///modules/unbound_dns/etc/unbound/unbound.conf.vagrant',
default => 'puppet:///modules/unbound_dns/etc/unbound/unbound.conf',
}
file { '/etc/unbound/unbound.conf':
owner => root,
group => root,
notify => Service['unbound'],
source => $unbound_conf,
}
请注意,该事实仅在puppet provision
一段时间内可用。