I have run into an issue where a chef cookbook that would build in test-kitchen on ubuntu 18 with chef 14(yes I know its EOL, were upgrading) successfully, absolutely fails on ubuntu 18 and chef 17.9.52.
Basically, the chef 14 suite builds OK. The chef 17 suite fails at the compile step, it basically never gets any of the attributes that are specified in the code. The error on the run looks like so:
[2022-05-06T05:30:53+00:00] INFO: Loading cookbooks [xxxx-xxxx@0.3.2, users@5.7.0, sudo@5.4.7, php@6.1.1, apache2@5.2.1, chef-vault@4.0.3, build-essential@8.2.1, yum-epel@4.4.1, seven_zip@3.2.0, mingw@2.1.4, windows@7.0.2]
Synchronizing cookbooks:
- users (5.7.0)
- php (6.1.1)
- sudo (5.4.7)
- xxxx-xxxx (0.3.2)
- build-essential (8.2.1)
- yum-epel (4.4.1)
- seven_zip (3.2.0)
- mingw (2.1.4)
- windows (7.0.2)
- chef-vault (4.0.3)
- apache2 (5.2.1)
Installing cookbook gem dependencies:
Compiling cookbooks...
[2022-05-06T05:30:53+00:00] DEBUG: Cookbooks to compile: [:apache2, :"chef-vault", :windows, :seven_zip, :mingw, :"build-essential", :"yum-epel", :php, :sudo, :users, :"xxxx-xxxx"]
Loading Chef InSpec profile files:
Loading Chef InSpec input files:
Loading Chef InSpec waiver files:
[2022-05-06T05:30:53+00:00] WARN: Resource chef_vault_secret built into Chef Infra Client is being overridden by the resource from a cookbook. Please upgrade your cookbook or remove the cookbook from your run_list.
[2022-05-06T05:30:53+00:00] WARN: Resource chef_vault_secret built into Chef Infra Client is being overridden by the resource from a cookbook. Please upgrade your cookbook or remove the cookbook from your run_list.
================================================================================
Recipe Compile Error in /tmp/kitchen/cache/cookbooks/xxxx-xxxx/recipes/default.rb
================================================================================
NoMethodError
-------------
undefined method `[]' for nil:NilClass
Cookbook Trace: (most recent call first)
----------------------------------------
/tmp/kitchen/cache/cookbooks/xxxx-xxxx/recipes/_users.rb:11:in `from_file'
/tmp/kitchen/cache/cookbooks/xxxx-xxxx/recipes/default.rb:11:in `from_file'
Relevant File Content:
----------------------
/tmp/kitchen/cache/cookbooks/xxxx-xxxx/recipes/_users.rb:
4: #
5: # Copyright:: (C) 2020 xxxx-xxxx
6: #
7: # All rights reserved - Do Not Redistribute
8: #
9:
10: # Provision all scrum-freelancer-success-tmp users
11>> users_manage node['xxxx-xxxx']['scrum-freelancer-success-temp']['user'] do
12: data_bag node['xxxx-xxxx']['scrum-freelancer-success-temp']['data_bag']
13: end
14:
15: # Setup SUDOers privilges
16: sudo node['xxxx-xxxx']['scrum-freelancer-success-temp']['group'] do
17: group node['xxxx-xxxx']['scrum-freelancer-success-temp']['group']
18: nopasswd true
19: end
20:
System Info:
------------
chef_version=17.9.52
platform=ubuntu
platform_version=18.04
ruby=ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-linux]
program_name=/opt/chef/bin/chef-client
executable=/opt/chef/bin/chef-client
Running handlers:
[2022-05-06T05:30:53+00:00] ERROR: Running exception handlers
Running handlers complete
[2022-05-06T05:30:53+00:00] ERROR: Exception handlers complete
Infra Phase failed. 0 resources updated in 01 seconds
[2022-05-06T05:30:53+00:00] DEBUG: Chef::Compliance::Runner#enabled?: Chef InSpec profiles? false
[2022-05-06T05:30:53+00:00] DEBUG: Chef::Compliance::Runner#enabled?: audit cookbook?
[2022-05-06T05:30:53+00:00] DEBUG: Chef::Compliance::Runner#enabled?: compliance phase attr? false
[2022-05-06T05:30:53+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
[2022-05-06T05:30:53+00:00] FATAL: ---------------------------------------------------------------------------------------
[2022-05-06T05:30:53+00:00] FATAL: PLEASE PROVIDE THE CONTENTS OF THE stacktrace.out FILE (above) IF YOU FILE A BUG REPORT
[2022-05-06T05:30:53+00:00] FATAL: ---------------------------------------------------------------------------------------
[2022-05-06T05:30:53+00:00] DEBUG: NoMethodError: undefined method `[]' for nil:NilClass
/tmp/kitchen/cache/cookbooks/xxxx-xxxx/recipes/_users.rb:11:in `from_file'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/mixin/from_file.rb:34:in `instance_eval'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/mixin/from_file.rb:34:in `from_file'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/cookbook_version.rb:233:in `load_ruby_recipe'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/cookbook_version.rb:203:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/run_context.rb:417:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/run_context.rb:373:in `block in include_recipe'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/run_context.rb:372:in `each'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/run_context.rb:372:in `include_recipe'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/dsl/include_recipe.rb:26:in `include_recipe'
/tmp/kitchen/cache/cookbooks/xxxx-xxxx/recipes/default.rb:11:in `from_file'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/mixin/from_file.rb:34:in `instance_eval'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/mixin/from_file.rb:34:in `from_file'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/cookbook_version.rb:233:in `load_ruby_recipe'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/cookbook_version.rb:203:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/run_context.rb:417:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/run_context/cookbook_compiler.rb:228:in `block in compile_recipes'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/run_context/cookbook_compiler.rb:225:in `each'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/run_context/cookbook_compiler.rb:225:in `compile_recipes'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/run_context/cookbook_compiler.rb:109:in `compile'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/run_context.rb:247:in `load'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/policy_builder/expand_node_object.rb:103:in `setup_run_context'
/opt/chef/embedded/lib/ruby/3.0.0/forwardable.rb:238:in `setup_run_context'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/client.rb:495:in `setup_run_context'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/client.rb:281:in `run'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/application.rb:305:in `run_with_graceful_exit_option'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/application.rb:281:in `block in run_chef_client'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/local_mode.rb:42:in `with_server_connectivity'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/application.rb:264:in `run_chef_client'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/application/base.rb:352:in `run_application'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-17.9.52/lib/chef/application.rb:67:in `run'
/opt/chef/embedded/lib/ruby/gems/3.0.0/gems/chef-bin-17.9.52/bin/chef-client:25:in `<top (required)>'
/opt/chef/bin/chef-client:160:in `load'
/opt/chef/bin/chef-client:160:in `<main>'
[2022-05-06T05:30:53+00:00] FATAL: NoMethodError: undefined method `[]' for nil:NilClass
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>> Converge failed on instance <xxxx-xxxx-ubuntu-1804-chef-17>. Please see .kitchen/logs/xxxx-xxxx-ubuntu-1804-chef-17.log for more details
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration
the nodes it claims are nil are completely defined in the attributes/default.rb file and in fact the exact same code works in the ubuntu18-chef14 suite. Looking at the stacktrace from the chef-client I have no idea what the hell is going on or the problem. Basically, it seems like the chef crashed during the compile phase and failed to figure out the attributes, even though they are all defined. Help?