NoMethodError, what does this mean?

#1

Hello,

Im trying to update the php.ini file on my system. There's only two small changes
I want to make so I thought I would copy the file over to my templates directory and just add a couple variables in there to replace the values I want, and just overwrite the php.ini file. The only thing is I'm getting this error every time I try to apply the recipe.

Recipe: (chef-apply cookbook)::(chef-apply recipe)
  * template[/etc/php/7.2/apache2/php.ini] action create

    ================================================================================
    Error executing action `create` on resource 'template[/etc/php/7.2/apache2/php.ini]'
    ================================================================================

    NoMethodError
    -------------
    undefined method `preferred_filename_on_disk_location' for nil:NilClass

    Resource Declaration:
    ---------------------
    # In update_php_file.rb

     10: template '/etc/php/7.2/apache2/php.ini' do
     11: 	action :create
     12: 	mode '0644'
     13: 	source 'php.erb'
     14: 	variables(
     15: 		:post_size =>  '12M',
     16: 		:upload_size =>  '10M'
     17: 		)
     18: end

    Compiled Resource:
    ------------------
    # Declared in update_php_file.rb:10:in `run_chef_recipe'

    template("/etc/php/7.2/apache2/php.ini") do
      action [:create]
      default_guard_interpreter :default
      source "php.erb"
      declared_type :template
      cookbook_name "(chef-apply cookbook)"
      recipe_name "(chef-apply recipe)"
      mode "0644"
      variables {:post_size=>"12M", :upload_size=>"10M"}
      path "/etc/php/7.2/apache2/php.ini"
      owner nil
      group nil
      verifications []
    end

    System Info:
    ------------
    chef_version=14.10.9
    platform=ubuntu
    platform_version=18.04
    ruby=ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]
    program_name=/usr/bin/chef-apply
    executable=/opt/chefdk/bin/chef-apply

[2019-05-09T14:35:34-03:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2019-05-09T14:35:34-03:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2019-05-09T14:35:34-03:00] FATAL: NoMethodError: template[/etc/php/7.2/apache2/php.ini] ((chef-apply cookbook)::(chef-apply recipe) line 10) had an error: NoMethodError: undefined method `preferred_filename_on_disk_location' for nil:NilClass

I'm not sure what this means, and I literally can't find anything explaining it. Any feedback would be appreciated. (I'll post the recipe contents below)

template '/etc/php/7.2/apache2/php.ini' do
action :create
mode '0644'
source 'php.erb'
variables(
:post_size => '12M',
:upload_size => '10M'
)
end

#2

The core problem here is the usage of chef-apply which is a limited subset that is primarily useful for toy examples and does not have feature parity with chef-client.

#3

I'm just trying to run this on the local server to test it before I upload it to the chef server and run it on the nodes, but I still can't get it to work. Is there a specific way to pull an attribute from the default.rb with the recipe and apply it to a template? thanks in advance.

#4

I've found this book online:
https://books.google.ca/books?id=fT1PAQAAQBAJ&pg=PA56&lpg=PA56&dq="undefined+method+'preferred_filename_on_disk_location'+for+nil:NilClass"&source=bl&ots=QXm5PfL8Gy&sig=ACfU3U1z-pUUMJyJIIbuq9Lm5Nri0-9Tnw&hl=en&sa=X&ved=2ahUKEwjB96uTjZniAhUineAKHRaKCSkQ6AEwB3oECAkQAQ#v=onepage&q="undefined%20method%20'preferred_filename_on_disk_location'%20for%20nil%3ANilClass"&f=false

It basically says to avoid using chef-apply when working with multiple ruby files and use chef-solo in order to apply the cookbooks/recipes. It says there is no way for the file to access the data in the template when using chef-apply.

#5

It states this at the very top of page 61.