kitchen testing

================================================================================
Recipe Compile Error in /tmp/kitchen/cache/cookbooks/csl_configure_machine_image/recipes/default.rb
================================================================================

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

     Cookbook Trace:
     ---------------
       /tmp/kitchen/cache/cookbooks/csl_security_layer_requirements/recipes/user_accounts_and_environments.rb:29:in `from_file'
       /tmp/kitchen/cache/cookbooks/csl_security_layer_requirements/recipes/default.rb:37:in `from_file'
       /tmp/kitchen/cache/cookbooks/csl_configure_machine_image/recipes/default.rb:17:in `from_file'

     Relevant File Content:
     ----------------------
     /tmp/kitchen/cache/cookbooks/csl_security_layer_requirements/recipes/user_accounts_and_environments.rb:

      22:      PASS_WARN_AGE: node['users_and_environments']['PASS_WARN_AGE']
      23:    )
      24:  end
      25:
      26:  # Modify active user parameters to match: # chage --maxdays 90 <user>
      27:  # Modify active user parameters to match: # chage --mindays 7 <user>
      28:  # Modify active user parameters to match: # chage --warndays 7 <user>"
      29>> node['etc']['passwd'].each do |user, _data|
      30:    execute "PASS_WARN_AGE for #{user}" do
      31:      command "chage --warndays 7 #{user}"
      32:      live_stream true
      33:    end
      34:    execute "PASS_MIN_DAYS for #{user}" do
      35:      command "chage --mindays 7 #{user}"
      36:      live_stream true
      37:      not_if { user == 'root' }
      38:    end

     System Info:
     ------------
     chef_version=15.7.32
     platform=redhat
     platform_version=6.9
     ruby=ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
     program_name=/opt/chef/bin/chef-client
     executable=/opt/chef/bin/chef-client


     Running handlers:
   [2020-06-15T15:53:52+00:00] ERROR: Running exception handlers
     Running handlers complete
   [2020-06-15T15:53:52+00:00] ERROR: Exception handlers complete
     Chef Infra Client failed. 1 resources updated in 04 seconds
   [2020-06-15T15:53:52+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
   [2020-06-15T15:53:52+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
   [2020-06-15T15:53:52+00:00] FATAL: NoMethodError: undefined method `[]' for nil:NilClass

Hi @Chiango2 ! :wave:

With the information you've given from the bug report, it looks like node['etc'] is returning nil? Which means that trying to run node['etc']['passwd'] would break.

After hearing from one of my colleagues, it sounds like those attributes may not be set (hence the nil), here are some notes about setting data structures. https://docs.chef.io/ohai/#enabling-optional-plugins :slightly_smiling_face: