大网数据广告活动
服务器运维问答

Vagrant Puppet apply manifest with wrong environment

· 52CE 我爱测

I use Puppet 3.7 in standard client-server mode, with environments, and using Hiera for data. I use Vagrant to test the Puppet manifests directly from my Puppet repository. I recently started to use Hiera and changed my Vagrantfi…

问题原文

原帖链接 · daks · CC BY-SA 3.0

I use Puppet 3.7 in standard client-server mode, with environments, and using Hiera for data. I use Vagrant to test the Puppet manifests directly from my Puppet repository.

I recently started to use Hiera and changed my Vagrantfile (and Vagrant directory) to works with it. It now seems to work with Hiera but another problem appears: Vagrant thinks my VM is in environment production when it's in experimental one. (this worked fine before)

The Puppet repository looks like

~/code/puppet
└── environments
    ├── experimental
    │   ├── manifests
    │   │   └── site.pp
    │   ├── modules
    │   └── Puppetfile
    ├── production
    │   ├── manifests
    │   │   └── site.pp
    │   ├── modules
    │   └── Puppetfile
    └── testing
        ├── manifests
        │   └── site.pp
        ├── modules
        └── Puppetfile

My Vagrant setup is stored in another directory. I have created a symbolic link (ln -s) to ~/code/puppet named puppet in this directory. The Vagrantfile looks

config.vm.define "standalone", primary: true do |config|
    config.vm.box = "debian_wheezy+vbox_jessie+puppet_3.7"
    config.vm.hostname = "standalone.puppet.vagrant"
    config.vm.network "private_network", ip:"192.168.10.21"

    config.vm.synced_folder "puppet/hieradata", "/etc/puppet/hieradata"
    config.vm.provision :puppet, :options => ["--yamldir /hieradata"] do |puppet|
        puppet.manifests_path = "puppet/environments/experimental/manifests"
        puppet.manifest_file = "site.pp"
        puppet.module_path = [ "puppet/environments/experimental/modules", "puppet/environments/production/modules", "puppet/modules" ]
        puppet.hiera_config_path = "puppet/hiera.yaml"
    end
  end

I imagine that my recent changes following the use of Hiera are not correct to Vagrant, and maybe the hacks (linking puppet code directory) are the cause, but I can't see how this should be organized.

Is there some people who knows this problem and how to solve it?

Thanks

Update

I changed

puppet.manifests_path = "puppet/environments/#{env}/manifests" 

and removed puppet.working_directory to have my VM up/provision.

With

puppet.module_path = [ "puppet/modules", "puppet/environments/production/modules" ] 

it seems to let my VM access to production and current env modules, which I need.

已采纳解答

原帖链接 · Marc Lambrichs · CC BY-SA 3.0

You can specify all options for your puppet run. You can use something like this:

srv.vm.provision :puppet do |puppet|
      puppet.working_directory = "/vagrant/puppet"
      puppet.module_path       = "puppet/modules"
      puppet.manifests_path    = "puppet/manifests"
      puppet.manifest_file     = "site.pp"
      puppet.hiera_config_path = "puppet/hiera.yaml"
      puppet.options           = "--debug --verbose --environment #{env}"
end

Which means that your modules are in "puppet/modules/#{env} and your manifests in "puppet/manifests/#{env}. Now, "env" is a variable that you can set in your Vagrantfile:

env = "production"

or: you could put all variables, like "env", in a yaml file and load that.

For reference, you can find all puppet provision options here: https://www.vagrantup.com/docs/provisioning/puppet_apply.html

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-03-04)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。