gposton / vagrant-hiera

MIT License
21 stars 12 forks source link

Unknown function hiera #1

Closed czerasz closed 12 years ago

czerasz commented 12 years ago

Hi I'm trying to use the vagrant-hiera plugin on my project. Unfortunately I'm getting an "Unknown function hiera" error.

Am I missing something?

More details below:

Devs-MacBook-Pro:project dev$ git checkout feature/hiera
Switched to branch 'feature/hiera'
Devs-MacBook-Pro:project dev$ vagrant up database
[database] VM already created. Booting if it's not already running...
[database] Clearing any previously set forwarded ports...
[database] Forwarding ports...
[database] -- 22 => 2222 (adapter 1)
[database] Creating shared folders metadata...
[database] Creating hiera shared folders metadata...
[database] Clearing any previously set network interfaces...
[database] Preparing network interfaces based on configuration...
[database] Booting VM...
[database] Waiting for VM to boot. This can take a few minutes.
[database] VM booted and ready for use!
[database] Installing puppet-hiera
[database] Adding hiera data folder
[database] Adding hiera config file
[database] Configuring and enabling network interfaces...
[database] Mounting shared folders...
[database] -- v-root: /vagrant
[database] -- manifests: /tmp/vagrant-puppet/manifests
[database] -- v-pp-m0: /tmp/vagrant-puppet/modules-0
[database] Running provisioner: Vagrant::Provisioners::Puppet...
[database] Running Puppet with /tmp/vagrant-puppet/manifests/database.pp...
stdin: is not a tty
info: Loading facts in /tmp/vagrant-puppet/modules-0/stdlib/lib/facter/facter_dot_d.rb

info: Loading facts in /tmp/vagrant-puppet/modules-0/stdlib/lib/facter/puppet_vardir.rb

info: Loading facts in /tmp/vagrant-puppet/modules-0/stdlib/lib/facter/root_home.rb

No LSB modules are available.
debug: importing '/tmp/vagrant-puppet/modules-0/boxes/manifests/database.pp' in environment production

debug: Automatically imported boxes::database from boxes/database into production

debug: importing '/tmp/vagrant-puppet/modules-0/boxes/manifests/base.pp' in environment production

debug: Automatically imported boxes::base from boxes/base into production

debug: Scope(Class[Boxes::Base::Init]): Retrieving template boxes/etc/motd.erb

debug: template[/tmp/vagrant-puppet/modules-0/boxes/templates/etc/motd.erb]: Bound template variables for /tmp/vagrant-puppet/modules-0/boxes/templates/etc/motd.erb in 0.00 seconds

debug: template[/tmp/vagrant-puppet/modules-0/boxes/templates/etc/motd.erb]: Interpolated template /tmp/vagrant-puppet/modules-0/boxes/templates/etc/motd.erb in 0.00 seconds

debug: Failed to load library 'selinux' for feature 'selinux'

Unknown function hiera at /tmp/vagrant-puppet/modules-0/boxes/manifests/database.pp:7 on node lucid32.localdomain

The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

cd /tmp/vagrant-puppet/manifests && puppet apply --verbose --debug --modulepath '/tmp/vagrant-puppet/modules-0' /tmp/vagrant-puppet/manifests/database.pp
gposton commented 12 years ago

You'll need to add/checkout puppet-hiera to your module path.

"It's not 100% ready for prime time, shortly a simple gem install hiera-puppet on your master will do it. For the moment the Gem install will place the Puppet Parser Function where Puppet cannot find it, you should copy it out and distribute it to your master using Pluginsync or something similar" Reference: https://github.com/puppetlabs/hiera-puppet#installation

"It worked after I copied the correct puppet module github.com/puppetlabs/hiera-puppet http://github.com/puppetlabs/hiera-puppet to the modules folder." https://groups.google.com/d/msg/puppet-users/IlPq14Rsnm0/UhbbRUsqqLgJ

On 7/8/12 5:46 PM, "Michał Czeraszkiewicz" <reply+i-5489425-c4d5a8cabff37a2a3e559fabf6d489094be71fd8-909581@reply.gith ub.com> wrote:

Hi I'm trying to use the vagrant-hiera plugin on my project (https://github.com/czerasz/vagrant-application-database/tree/feature/hier a). Unfortunately I'm getting an "Unknown function hiera" error.

Am I missing something?

More details below: `Devs-MacBook-Pro:project dev$ git checkout feature/hiera Switched to branch 'feature/hiera' Devs-MacBook-Pro:project dev$ vagrant up database [database] VM already created. Booting if it's not already running... [database] Clearing any previously set forwarded ports... [database] Forwarding ports... [database] -- 22 => 2222 (adapter 1) [database] Creating shared folders metadata... [database] Creating hiera shared folders metadata... [database] Clearing any previously set network interfaces... [database] Preparing network interfaces based on configuration... [database] Booting VM... [database] Waiting for VM to boot. This can take a few minutes. [database] VM booted and ready for use! [database] Installing puppet-hiera [database] Adding hiera data folder [database] Adding hiera config file [database] Configuring and enabling network interfaces... [database] Mounting shared folders... [database] -- v-root: /vagrant [database] -- manifests: /tmp/vagrant-puppet/manifests [database] -- v-pp-m0: /tmp/vagrant-puppet/modules-0 [database] Running provisioner: Vagrant::Provisioners::Puppet... [database] Running Puppet with /tmp/vagrant-puppet/manifests/database.pp... stdin: is not a tty info: Loading facts in /tmp/vagrant-puppet/modules-0/stdlib/lib/facter/facter_dot_d.rb

info: Loading facts in /tmp/vagrant-puppet/modules-0/stdlib/lib/facter/puppet_vardir.rb

info: Loading facts in /tmp/vagrant-puppet/modules-0/stdlib/lib/facter/root_home.rb

No LSB modules are available. debug: importing '/tmp/vagrant-puppet/modules-0/boxes/manifests/database.pp' in environment production

debug: Automatically imported boxes::database from boxes/database into production

debug: importing '/tmp/vagrant-puppet/modules-0/boxes/manifests/base.pp' in environment production

debug: Automatically imported boxes::base from boxes/base into production

debug: Scope(Class[Boxes::Base::Init]): Retrieving template boxes/etc/motd.erb

debug: template[/tmp/vagrant-puppet/modules-0/boxes/templates/etc/motd.erb]: Bound template variables for /tmp/vagrant-puppet/modules-0/boxes/templates/etc/motd.erb in 0.00 seconds

debug: template[/tmp/vagrant-puppet/modules-0/boxes/templates/etc/motd.erb]: Interpolated template /tmp/vagrant-puppet/modules-0/boxes/templates/etc/motd.erb in 0.00 seconds

debug: Failed to load library 'selinux' for feature 'selinux'

Unknown function hiera at /tmp/vagrant-puppet/modules-0/boxes/manifests/database.pp:7 on node lucid32.localdomain

The following SSH command responded with a non-zero exit status. Vagrant assumes that this means the command failed!

cd /tmp/vagrant-puppet/manifests && puppet apply --verbose --debug --modulepath '/tmp/vagrant-puppet/modules-0' /tmp/vagrant-puppet/manifests/database.pp`


Reply to this email directly or view it on GitHub: https://github.com/gposton/vagrant-hiera/issues/1

czerasz commented 12 years ago

Hi,

Thanks for the quick response! I added the hiera-puppet gem and the hiera-puppet module to my project.

After this I copied the hiera parser functions:

sudo cp /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/hiera-puppet-0.3.0/lib/puppet/parser/functions/* /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/functions/

Any Idea how this could be automated?

But then I got the message, that rubygems can't find "hiera_puppet". For more details, please see the log below:

Devs-MacBook-Pro:ztp_project dev$ vagrant up database
[database] Importing base box 'lucid32'...
[database] The guest additions on this VM do not match the install version of
VirtualBox! This may cause things such as forwarded ports, shared
folders, and more to not work properly. If any of those things fail on
this machine, please update the guest additions and repackage the
box.

Guest Additions Version: 4.1.16
VirtualBox Version: 4.1.12
[database] Matching MAC address for NAT networking...
[database] Clearing any previously set forwarded ports...
[database] Forwarding ports...
[database] -- 22 => 2222 (adapter 1)
[database] Creating shared folders metadata...
[database] Creating hiera shared folders metadata...
[database] Clearing any previously set network interfaces...
[database] Preparing network interfaces based on configuration...
[database] Booting VM...
[database] Waiting for VM to boot. This can take a few minutes.
[database] VM booted and ready for use!
[database] Installing puppet-hiera
[database] Adding hiera data folder
[database] Adding hiera config file
[database] Configuring and enabling network interfaces...
[database] Mounting shared folders...
[database] -- v-root: /vagrant
[database] -- manifests: /tmp/vagrant-puppet/manifests
[database] -- v-pp-m0: /tmp/vagrant-puppet/modules-0
[database] Running provisioner: Vagrant::Provisioners::Puppet...
[database] Running Puppet with /tmp/vagrant-puppet/manifests/database.pp...
stdin: is not a tty
info: Loading facts in /tmp/vagrant-puppet/modules-0/stdlib/lib/facter/facter_dot_d.rb

info: Loading facts in /tmp/vagrant-puppet/modules-0/stdlib/lib/facter/puppet_vardir.rb

info: Loading facts in /tmp/vagrant-puppet/modules-0/stdlib/lib/facter/root_home.rb

No LSB modules are available.
warning: Could not retrieve fact fqdn
debug: importing '/tmp/vagrant-puppet/modules-0/boxes/manifests/database.pp' in environment production

debug: Automatically imported boxes::database from boxes/database into production

debug: importing '/tmp/vagrant-puppet/modules-0/boxes/manifests/base.pp' in environment production

debug: Automatically imported boxes::base from boxes/base into production

debug: Scope(Class[Boxes::Base::Init]): Retrieving template boxes/etc/motd.erb

debug: template[/tmp/vagrant-puppet/modules-0/boxes/templates/etc/motd.erb]: Bound template variables for /tmp/vagrant-puppet/modules-0/boxes/templates/etc/motd.erb in 0.00 seconds

debug: template[/tmp/vagrant-puppet/modules-0/boxes/templates/etc/motd.erb]: Interpolated template /tmp/vagrant-puppet/modules-0/boxes/templates/etc/motd.erb in 0.00 seconds

debug: Failed to load library 'selinux' for feature 'selinux'

/opt/vagrant_ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
: 
no such file to load -- hiera_puppet
 (
LoadError
)
    from /opt/vagrant_ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
    from /tmp/vagrant-puppet/modules-0/hiera/lib/puppet/parser/functions/hiera.rb:3:in `function_hiera'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast/function.rb:33:in `send'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast/function.rb:33:in `evaluate'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast.rb:76:in `safeevaluate'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast/resourceparam.rb:18:in `evaluate'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast.rb:76:in `safeevaluate'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast/resource.rb:29:in `evaluate'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/type_loader.rb:78:in `collect'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast/branch.rb:16:in `each'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast/branch.rb:15:in `each'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast/resource.rb:28:in `collect'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast/resource.rb:28:in `evaluate'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/type_loader.rb:78:in `collect'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast/branch.rb:16:in `each'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast/branch.rb:15:in `each'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast/resource.rb:25:in `collect'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast/resource.rb:25:in `evaluate'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast.rb:76:in `safeevaluate'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast/astarray.rb:25:in `evaluate'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast/astarray.rb:20:in `each'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast/astarray.rb:20:in `evaluate'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast.rb:76:in `safeevaluate'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/resource/type.rb:76:in `evaluate_code'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/resource.rb:85:in `evaluate'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/compiler.rb:159:in `evaluate_classes'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/compiler.rb:146:in `each'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/compiler.rb:146:in `evaluate_classes'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/functions/include.rb:6:in `function_include'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast/function.rb:33:in `send'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast/function.rb:33:in `evaluate'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast.rb:76:in `safeevaluate'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast/astarray.rb:25:in `evaluate'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast/astarray.rb:20:in `each'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast/astarray.rb:20:in `evaluate'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/ast.rb:76:in `safeevaluate'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/resource/type.rb:76:in `evaluate_code'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/resource.rb:85:in `evaluate'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/compiler.rb:295:in `evaluate_main'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/compiler.rb:99:in `compile'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/compiler.rb:24:in `compile'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/indirector/catalog/compiler.rb:77:in `compile'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/util.rb:164:in `benchmark'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/indirector/catalog/compiler.rb:75:in `compile'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/indirector/catalog/compiler.rb:35:in `find'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/indirector/indirection.rb:196:in `find'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/application/apply.rb:218:in `main'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/application/apply.rb:149:in `run_command'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/application.rb:309:in `run'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/application.rb:416:in `hook'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/application.rb:309:in `run'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/application.rb:407:in `exit_on_fail'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/application.rb:309:in `run'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/util/command_line.rb:69:in `execute'
    from /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/bin/puppet:4
    from /opt/vagrant_ruby/bin/puppet:19:in `load'
    from /opt/vagrant_ruby/bin/puppet:19
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

cd /tmp/vagrant-puppet/manifests && puppet apply --verbose --debug --modulepath '/tmp/vagrant-puppet/modules-0' /tmp/vagrant-puppet/manifests/database.pp

The funny thing was that the gem was listed in the rubygems:

$ vagrant@lucid32:~$ gem list | grep hiera
hiera (0.3.0)
hiera-puppet (0.3.0)

But in the gem directory the hiera_puppet.rb file was missing. So I copied it from github:

$ cd /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/hiera-puppet-0.3.0/lib
$ wget https://raw.github.com/puppetlabs/hiera-puppet/master/lib/hiera_puppet.rb

Any idea what causes this issue and how to automate this?

The last thing I noticed was that in the datadir specified in my hiera.yaml file was pointing to the path on my guest. I thought that the datadir is defined by the config.hiera.data_path parameter and is located on the host. For my project I was expecting this location to be the source for all hiera configuration files. How do You deal with this in Your projects? Do You first copy the files with puppet and then use hiera?

gposton commented 12 years ago

Did you add hiera-puppet to your manifest path.

For example, if your puppet manifests have the following directory structure

- modules
  - snmp
  - dns
  - etc

you'll want to

cd modules/
git clone https://github.com/KrisBuytaert/puppet-hiera.git

The datadir in hiera.yaml should point to the mount point on the guest (which should be /tmp/vagrant-hiera/data ). The config.hiera.data_path parameter simply tells the vagrant box what directory (from your host) to mount to that location on the guest.

As far as your question about how we deal with this in our projects, I may not understand exactly what your asking but I'll attempt an answer. A git checkout of puppet-hiera exists in our manifests directory along with all other manifests. The gem is only installed on the puppet master. The gem does not have to exist on the machines you are provisioning. Also, you should not have to copy anything. On your puppet master, simply do a gem install puppet-hiera, then as long as you have the puppet-hiera checkout in your manifests/modules directory, everything should work.

czerasz commented 12 years ago

Hi,

I already did add the puppet-hiera module to my project as a git submodule.

The tip with setting the datadir in hiera.yaml to /tmp/vagrant-hiera/data was very, very good. Thanks a lot for this! We should update this information to the readme of Your project. (I see now that it's already there)

But I'm still experiencing issues. If You clone my git project with git clone git@github.com:czerasz/vagrant-application-database.git, then switch to the branch where I play with hiera git checkout feature/hiera, do bundle install und try to build the vm vagrant up database You will notice the following issue:

...

Unknown function hiera at /tmp/vagrant-puppet/modules-0/boxes/manifests/database.pp:7 on node lucid32.localdomain

The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

Please notice that I have the hiera-puppet gem installed on my host with bundler:

$ bundle list | grep hiera
  * hiera (0.3.0)
  * hiera-puppet (0.3.0)
  * vagrant-hiera (0.2.1)

And that is the moment when I need to ssh to my guest and copy the functions:

$ vagrant ssh database
Welcome to the database box
Last login: Wed Jul 11 23:09:53 2012 from 10.0.2.2
...
$ sudo cp /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/hiera-puppet-0.3.0/lib/puppet/parser/functions/* /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/puppet-2.7.14/lib/puppet/parser/functions/

After this step the provisioning ($ vagrant provision database) is successful.

Do You know the solution for this issue? Or maybe know what causes it?

Thanks for Your help.

gposton commented 12 years ago

I just upgraded the gem to v0.3. I believe your issue should be resolved now. It looks like some of the newer changes to puppet-hiera and hiera that were made in preparation for puppet v3 broke my setup with puppet 2.7.14/6. I upgraded everything to the newest puppet/hiera release candidates and it works now. Note that this will upgrade puppet on your vagrant box.

I created an example directory that has a working setup as well.

czerasz commented 12 years ago

I have upgraded the "vagrant-hiera" gem in my Gemfile.

Now hiera works like I wished.

Thanks a lot for Your support! You are great!

gposton commented 12 years ago

Glad to hear it. Enjoy!

On 7/17/12 7:11 PM, "Michał Czeraszkiewicz" <reply+i-5489425-c4d5a8cabff37a2a3e559fabf6d489094be71fd8-909581@reply.gith ub.com> wrote:

I have upgraded the "vagrant-hiera" gem in my Gemfile.

Now hiera works like I wished.

Thanks a lot for Your support! You are great!


Reply to this email directly or view it on GitHub: https://github.com/gposton/vagrant-hiera/issues/1#issuecomment-7052318