Vagrant, Puppet and nodejs module: throwing error

2019-06-20 06:37发布

问题:

I have the following manifest:

include nodejs

package { 'serve':
  ensure => latest,
  provider => 'npm',
}

I am using the puppetlab node.js module:

http://forge.puppetlabs.com/puppetlabs/nodejs

Vagrantfile:

Vagrant::Config.run do |config|
  config.vm.box = "precise64"
  config.vm.box_url = "http://files.vagrantup.com/precise64.box"

  config.vm.provision :puppet do |puppet|
    puppet.manifests_path = '~/work/environments/default/'
    puppet.manifest_file = 'site.pp'
    puppet.module_path = '~/work/environments/default/modules'
  end

end

When I run vagrant up I am getting the following error:

[default] Running provisioner: Vagrant::Provisioners::Puppet...
[default] Running Puppet with /tmp/vagrant-puppet/manifests/site.pp...
stdin: is not a tty
err: /Stage[main]//Package[serve]/ensure: change from absent to latest failed: Could not update: Got nil value for ensure at /tmp/vagrant-puppet/manifests/site.pp:6
notice: /Stage[main]/Nodejs/Package[nodejs]/ensure: ensure changed 'purged' to 'present'
notice: /Stage[main]/Nodejs/Package[npm]/ensure: ensure changed 'purged' to 'present'
notice: Finished catalog run in 14.89 seconds

At first I thought maybe it's trying to install the 'serve' module before npm installed so I tried require => Package[npm] but that gave the same result.

So could anybody shine some light on why it's not installing the 'serve' module?

回答1:

It seems to be ordering - the provider needs the npm command, which you don't have yet.

Try altering your manifest to something like:

class { 'nodejs': } -> package { 'serve': ensure => present, provider => 'npm', }

alternatively, possibly:

include nodejs

package { 'serve':
  ensure => present,
  provider => 'npm',
  require => Package['npm'],
}


回答2:

I ran across this as well - it looks to me like the puppetlabs-nodejs module doesn't actually accept ensure => latest, which is contrary to the documentation. My issue was fixed when I changed to ensure => present, and the code does look to support specific versions as well with ensure => 1.12.4 for example.