错误:未定义的方法' ref' for nil:节点vagrant-trusty64上的NilClass

时间:2014-12-17 08:00:15

标签: vagrant puppet

我的Puppet清单在我当地的Vagrant机器上出现问题。每当我尝试配置我的Vagrant机器时,我会收到以下输出,我似乎无法找到原因:

Error: undefined method `ref' for nil:NilClass on node vagrant-trusty64.lan
Error: undefined method `ref' for nil:NilClass on node vagrant-trusty64.lan
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

puppet apply --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/vagrant.pp || [ $? -eq 2 ]

Stdout from the command:



Stderr from the command:

stdin: is not a tty
Error: undefined method `ref' for nil:NilClass on node vagrant-trusty64.lan
Error: undefined method `ref' for nil:NilClass on node vagrant-trusty64.lan

关于从哪里开始调试的想法?

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    # Use Phusion's Ubuntu 12.04 box with support for Docker
    config.vm.box = "phusion-open-ubuntu-14.04-amd64"
    config.vm.box_url = "https://oss-binaries.phusionpassenger.com/vagrant/boxes/latest/ubuntu-14.04-amd64-vbox.box"
    # Set hostname
    config.vm.hostname = "vagrant-trusty64"

    # Configure the VirtualBox Provider
    config.vm.provider :virtualbox do |vb|
        # Give the VM 1GB of RAM
        # vb.customize ["modifyvm", :id, "--memory", "1024"]
    end

    # Provisioning with Puppet Standalone 
    config.vm.provision :puppet do |puppet|
        puppet.hiera_config_path = "conf/puppet/hiera.yaml"
        puppet.manifests_path = "manifests"
        puppet.manifest_file  = "vagrant.pp"
        puppet.module_path = "modules"
    end
end

1 个答案:

答案 0 :(得分:3)

首先,当试图调试这些问题时,正如Felix Frank在他对该问题的评论中指出的那样,将Puppet的--trace参数添加到Vagrant使用的Puppet参数中:

Vagrant.configure("2") do |config|
    config.vm.provision :puppet do |puppet|
        # ...
        puppet.options = ["--debug", "--trace"]
    end
end

更好的解决方案:

Vagrant.configure("2") do |config|
    config.vm.provision :puppet do |puppet|
        # ...
        if ENV.key?('PUPPET_OPTS')
            puppet.options = ENV['PUPPET_OPTS'].split(' ')
        end
    end
end

使用上面的命令,只需在运行时定义PUPPET_OPTS环境变量:

PUPPET_OPTS="--trace --debug" vagrant provision

这揭示了木偶的一般观点,表明事情失败了。我评论了一些东西并将问题分离到以下类:

class profiles::some::long::path {
    contain a, b, c
}

...其中abcprofiles::some::long::path内的类。奇怪的是,这个确切的代码在某种程度上昨晚运行良好。 I'm still trying to find out if there's an abridged syntax for including classes in the current class' package.