Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError: undefined method `[]' for nil:NilClass during privisioning #77

Open
epoxsize opened this issue Jun 15, 2016 · 7 comments

Comments

@epoxsize
Copy link

Hello

recently i've tried to use chef-provisioning-vsphere module to clone VM's but it failed with following issue:

[2016-06-15T21:02:13+03:00] INFO: Processing chef_node[test-machine] action create (basic_chef_client::block line 57)

- update node test-machine at chefzero://localhost:8890
-   update run_list from ["rhel-web-dockerized::defaul]"] to ["rhel-web-dockerized::default"]
================================================================================
Error executing action `converge` on resource 'machine[web-01]'
================================================================================

NoMethodError
-------------
undefined method `[]' for nil:NilClass

Resource Declaration:
---------------------
# In /root/chef-repo/cookbooks/vsphere-prov/recipes/linux.rb

 34: machine "web-01" do
 35:   run_list ['rhel-web-dockerized::defaul']
 36: end

Compiled Resource:
------------------
# Declared in /root/chef-repo/cookbooks/vsphere-prov/recipes/linux.rb:34:in `from_file'

machine("web-01") do
  action [:converge]
  retries 0
  retry_delay 2
  default_guard_interpreter :default
  chef_server {:chef_server_url=>"chefzero://localhost:8890", :options=>{:client_name=>"user1", :signing_key_filename=>"/root/chef-repo/.chef/user.pem", :api_version=>"0"}}
  driver "vsphere://vrt-vc/sdk?use_ssl=true&insecure=true"
  machine_options {:bootstrap_options=>{:use_linked_clone=>false, :num_cpus=>1, :memory_mb=>2048, :network_name=>["cLAN1"], :datacenter=>"DC_Blade", :resource_pool=>"chef-respool", :template_name=>"rhel-72-minimal", :customization_spec=>{:ipsettings=>{:dnsServerList=>["8.8.8.8", "8.8.4.4"]}, :domain=>"testdc.local", :ssh=>{:user=>"root", :password=>"password", :paranoid=>false}}}}
  declared_type :machine
  cookbook_name "@recipe_files"
  recipe_name "/root/chef-repo/cookbooks/vsphere-prov/recipes/linux.rb"
  run_list ["rhel-web-dockerized::default"]
end

[2016-06-15T21:02:14+03:00] INFO: Running queued delayed notifications before re-raising exception

Running handlers:
[2016-06-15T21:02:14+03:00] ERROR: Running exception handlers
Running handlers complete
[2016-06-15T21:02:14+03:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 16 seconds
[2016-06-15T21:02:14+03:00] FATAL: Stacktrace dumped to /root/chef-repo/.chef/local-mode-cache/cache/chef-stacktrace.out
[2016-06-15T21:02:14+03:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2016-06-15T21:02:14+03:00] ERROR: machine[test-machine](@recipe_files::/root/chef-repo/cookbooks/vsphere-prov/recipes/linux.rb line 34) had an error: NoMethodError: undefined method `[]' for nil:NilClass
[2016-06-15T21:02:15+03:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

i've started to provision VM with following parameters:

chef_gem 'chef-provisioning-vsphere' do
action :install
compile_time true
end

require 'chef/provisioning/vsphere_driver'

with_vsphere_driver host: 'vrt-vc',
insecure: true,
user: 'domain\user',
password: 'password'

with_machine_options :bootstrap_options => {
use_linked_clone: false,
num_cpus: 1,
memory_mb: 2048,
network_name: ["cLAN1"],
datacenter: 'DC_Blade',
resource_pool: 'chef-respool',
template_name: 'rhel-72-minimal',
customization_spec: {
ipsettings: {
dnsServerList: ['8.8.8.8','8.8.4.4']
},
:domain => 'testdc.local'
}
:ssh => {
:user => 'root',
:password => 'password',
:paranoid => false,
}
}

machine "web-01" do
run_list ['rhel-web-dockerized::default']
end

Had someone seen that before ?

@colourmeamused
Copy link

Might have run into something similar today. Can you copy the stacktrace, the filename is in the logs:

"[2016-06-15T21:02:14+03:00] FATAL: Stacktrace dumped to /root/chef-repo/.chef/local-mode-cache/cache/chef-stacktrace.out"

Or, run chef-client with '-l debug'. That will tell us where the error is coming from.

@mwrock
Copy link
Contributor

mwrock commented Jul 29, 2016

@colourmeamused do you have your stacktrace handy?

@dan-rose
Copy link

I too am having this problem - please find a link to a gist with the stack-trace. I am able to 'allocate' the VM's but they don't start in fact get no further in the process.

Any help would be gratefully received

############################################

cmd> chef-client -z -o "provisionvm::vmware_dev,windows_basicwebserver::cluster" -c .chef/knife.rb

chef_gem 'chef-provisioning-vsphere' do
action :install
compile_time true
end

require 'chef/provisioning/vsphere_driver'

with_vsphere_driver host: 'vcentre',
insecure: true,
user: 'user',
password: 'pass!'

with_machine_options bootstrap_options: {
use_linked_clone: true,
datacenter: 'DC',
host: 'host', # this is the cluster name
template_name: '2012r2_Template',
template_folder: 'Templates/Infrastructure',
vm_folder: 'New Builds',
network_name: ['network-upgrade/Production LAN'],
num_cpus: 2,
memory_mb: 4096,
datastore: 'MSA03_vd3_v03'
}

machine 'Test-SRV1' do
action 'allocate'
end

machine 'Test-SRV1' do
action 'converge'
recipe 'windows_basicwebserver::iis'
end

@mwrock
Copy link
Contributor

mwrock commented Oct 18, 2016

Based on your stacktrace @dan-rose, you are missing :ssh options in your machine options. Have a look at the readme for example options. I realize you are provisioning windows and thus it seems odd to use :ssh. Under the covers the provisioner will use winrm on windows.

@dan-rose
Copy link

dan-rose commented Oct 18, 2016

Thanks, that’s got it! The readme (that I’ve seen here - https://github.com/CenturyLinkCloud/chef-provisioning-vsphere/blob/master/README.md) doesn’t seem to specify what options are “required” for the process continue. I can appreciate that a user account is needed to further provision the machine after it boots, but sometimes we need it spelt out!

As a quick aside.. how could you tell I was missing that specific option for the stacktrace??? If it’s too long-winded to explain don’t worry :)

Dan

@mwrock
Copy link
Contributor

mwrock commented Oct 18, 2016

I hear ya. The readme (and API) could really use some work. The line in the stacktrace is:

vsphere_helper.start_vm(vm, machine_options[:bootstrap_options][:ssh][:port])

so a undefined method[]' for nil:NilClass ` must have been because one of the option hashes was nil.

Also thats a horrible error and if it was easier for me to get releases out for this repo I'd add proper validation.

@dan-rose
Copy link

Thank you again - .. I am still new to Chef and Ruby.. I have gone back to look at the trace, and then looked in this location - vsphere_driver/driver.rb:434: - and can now see the line you mentioned. I doubt i would have known the answer even now i know where how to start looking :)

Thanks for taking the time to assist me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants