我有一个傀儡问题,具体到stream浪者使用清单/模块/ hiera-config与其木偶供应商的方式,因为“puppet apply site.pp”在生成的stream浪汉部署的VM(当在本地应用客户操作系统本身)。 在Vagrantfile的目录中,我有一个“puppet_files”子目录,其中有清单,模块和hiera文件,将被复制到VM上的/ etc / puppet(我使用带有“file”伪指令的puppet模块来复制这些文件)。
我的主机环境是OSX,我正在使用vagrant在VirtualBox上部署Centos 6。
背景信息:
当我input“vagrant up”时,我看到这个开头是:
==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... ==> default: Setting hostname... ==> default: Mounting shared folders... default: /vagrant => /Users/juser/vm_stuff/vagrant-fresh default: /tmp/vagrant-puppet-1/manifests => /Users/juser/vm_stuff/vagrant-fresh/puppet_files/manifests default: /tmp/vagrant-puppet-1/modules-0 => /Users/juser/vm_stuff/vagrant-fresh/puppet_files/modules ==> default: Running provisioner: shell...
因此,它看起来像在我的OSX文件系统上创build临时文件,并从Vagrantfile中指定的位置复制源目录/文件。 在虚拟机本身puppet目录被适当地挂载为/ vagrant / puppet_files。 这是puppet config的Vagrantfile的相关部分:
config.vm.provision "puppet" do |puppet| puppet.manifests_path = "puppet_files/manifests" puppet.module_path = "puppet_files/modules" puppet.hiera_config_path = "puppet_files/hiera_config/hiera.yaml" puppet.manifest_file = "site.pp" puppet.options = "--verbose --debug" end
site.pp只有两行重要性(调用两个模块):
include ::hierasetup include ::jboss
hiera.yaml文件如下所示:
:backends: - json :logger: console :hierarchy: - "node/%{::fqdn}" - common :json: :datadir: '/etc/puppet/hieradata/'
而我的hierasetup模块(在site.pp中调用)也复制了一个json hiera文件到/etc/puppet/hieradata/common.json。 而且仅供参考,jboss模块是试图使用hiera和“hiera_hash”和“create_resources”(在Linux VM中本地/手动应用时工作正常)的模块。
问题:
stream浪汉没有问题导入清单和模块,甚至应用清单,但它不断阅读我的hiera.yaml文件(正确?),因为如果它会看到我指定json而不是yaml作为后端:
Debug: importing '/tmp/vagrant-puppet-1/modules-0/hierasetup/manifests/init.pp' in environment production Debug: Automatically imported hierasetup from hierasetup into production Debug: importing '/tmp/vagrant-puppet-1/modules-0/jboss/manifests/init.pp' in environment production Debug: Automatically imported jboss from jboss into production Debug: hiera(): Hiera YAML backend starting Debug: hiera(): Looking up jbossas in YAML backend Debug: hiera(): Looking for data source common Debug: hiera(): Cannot find datafile /var/lib/hiera/common.yaml, skipping Error: create_resources(): second argument must be a hash at /tmp/vagrant-puppet-1/modules-0/jboss/manifests/init.pp:14 on node josh-new.morgan.haib.org Wrapped exception: create_resources(): second argument must be a hash Error: create_resources(): second argument must be a hash at /tmp/vagrant-puppet-1/modules-0/jboss/manifests/init.pp:14 on node josh-new.morgan.haib.org The following SSH command responded with a non-zero exit status. Vagrant assumes that this means the command failed! puppet apply --verbose --debug --modulepath '/tmp/vagrant-puppet-1/modules-0:/etc/puppet/modules' --hiera_config=/tmp/vagrant-puppet-1/hiera.yaml --manifestdir /tmp/vagrant-puppet-1/manifests --detailed-exitcodes /tmp/vagrant-puppet-1/manifests/site.pp || [ $? -eq 2 ]
为什么它寻找common.yaml而不是/etc/puppet/hieradata/common.json? 为什么它认为这是一个YAML后端,而不是JSON? 它不读取我的hiera.yaml文件(我在Vagrantfile中给出了正确的相对path),并在某种默认情况下运行?
底线:如果我在虚拟机上的Linux环境中应用本地,“puppet apply site.pp”完美地工作,但它不适用于傀儡configuration器的“stream浪者的方式”。 我必须错过一些关于hieraconfiguration如何工作的stream浪者。
好吧,看来我遇到了两个不同的问题。 最大的问题是,尽pipe我创build了一个名为“hieraconfig”的模块,它将复制我的预先创build的hiera.yaml和common.json文件到/ etc / puppet,调用hiera的jboss模块首先被执行(尽pipe我包括它在清单中的hieraconfig之后 – 见下文)。 我试图解决这个问题首先在site.pp清单中评估hierasetup,但是它仍然首先运行jboss模块:
stage { 'pre': before => Stage['main'] } # add the hierasetup module to the new 'pre' run stage class { 'hierasetup': stage => 'pre' } include ::hierasetup include ::jboss
我目前没有解决这个问题。 但至less我知道,部分失败是当hiera被从jboss模块调用时,/ etc / puppet / hiera.yaml和/etc/puppet/hieradata/common.json甚至不存在于VM上,因为hierasetup还没有运行。 我暂时使用Vagrant的脚本提供程序而不是木偶来为我复制文件。
第二个问题是因为我认为这些文件一直存在,所以我对“puppet.hiera_config_path”应该做什么感到困惑。 通过各种尝试和错误的尝试,我发现:
puppet.manifests_path , puppet.modules_path和puppet.hiera_config_path只指向主机上的path(在我的情况下在OSX上)。 如果你使用相对path,相对于虚拟机上的/ vagrant mount,而不是相对于宿主机器上包含你的Vagrantfile的目录,那么就不要被这个想法所迷惑了(尽pipe这显然是挂载到/stream浪汉)。
这些_pathvariables中的每一个,IF和ONLY,如果它们实际设置在Vagrantfile中(否则默认的木偶目录将被search),将导致Vagrant将模块,清单和hieraconfiguration复制到/ tmp / vagrant-puppet下的子目录[ -X] (-X可能是一个附加的数字后缀/ tmp / vagrant-puppet-1),并告诉puppet在/ tmp下面查看它们。
如果你的傀儡文件已经在你想使用的虚拟机上 ,但设置了_pathvariables,那么Vagrant的puppet命令不会find它们,因为当你设置它们时,它将puppetredirect到/ tmp / vagrant-puppet [-X] 。 尽pipe“vagrant up”输出会通知你他们被映射的位置,但是你不能在VM上改变这个目的地。
默认:/ tmp / vagrant-puppet-1 / manifests => / Users // vm_stuff / vagrant-fresh / puppet_files / manifests
默认:/ tmp / vagrant-puppet-1 / modules-0 => / Users // vm_stuff / vagrant-fresh / puppet_files / modules
=>箭头之后的path是您使用Vagrantfile中的_pathvariables指定的主机上的源目录。 =>箭头之前的path是将在其上复制源目录内容的虚拟机的位置。
如果你更喜欢Vagrant让puppet在你已经放置在虚拟机上的文件的默认目录中(你不需要被Vagrant复制到/ tmp),那么不要在Vagrant中指定任何_pathvariables。 或者,如果默认位置或/ tmp位置都不令人满意,则可以通过显式指定在哪里查找每个具有puppet.optionsvariables的默认stream浪行为,如下所示:
puppet.options =“–hiera_config = / path / to / hiera.yaml –modulepath”/ path / to / modules / –manifestdir / path / to / manifests /“
如果有任何失败,并且已经将puppet.options设置为–verbose && –debug(可能会显示没有这些设置),则会显示实际的通过ssh发送到guest虚拟机的puppet命令的错误,喜欢这个:
The following SSH command responded with a non-zero exit status. Vagrant assumes that this means the command failed! puppet apply --verbose --debug --modulepath '/tmp/vagrant-puppet-1/modules-0:/etc/puppet/modules' --manifestdir /tmp/vagrant-puppet-1/manifests --hiera_config=/tmp/vagrant-puppet-1/hiera.yaml --detailed-exitcodes /tmp/vagrant-puppet-1/manifests/site.pp || [ $? -eq 2 ]
只要–hiera_config指向正确的位置/文件在这个命令它应该读你的configuration没有问题。 我暂时有一个问题(在我发现/etc/puppet/hieradata/common.json不存在于虚拟机上)到它将读取hiera.yaml的地方,但由于common.json不存在而失败。
所有说过的,虽然hiera看起来在非常具体的位置取决于你是否设置“ puppet.hiera_config_path ”,除非你手动覆盖puppet.options。