skip to Main Content

I have a chef recipe which downloads the jar from artifactory and creates a service for that java jar under /etc/systemd/system folder. It used to work with chef version 13.9.4 but with version 14.12.9 I am getting the error: NameError - undefined local variable or method service_name’ for #<#Class:0x00000000049d3218:0x0000000005a04678>`

* java_service[myApp service for file processing] action enable

================================================================================
Error executing action `enable` on resource 'java_service[myApp service for file processing]'
================================================================================

NameError
---------
undefined local variable or method `service_name' for #<#<Class:0x00000000049d3218>:0x0000000005a04678>

Cookbook Trace:
---------------
/tmp/kitchen/cache/cookbooks/myApp_chef/resources/java_service.rb:69:in `create_init'
/tmp/kitchen/cache/cookbooks/myApp_chef/resources/java_service.rb:58:in `block in class_from_file'

Resource Declaration:
---------------------
# In /tmp/kitchen/cache/cookbooks/myApp_chef/recipes/default.rb

134:   java_service service['title'] do
135:     service_name service['service_name'].to_s
136:     env node['myApp_chef']['myApp_env'].to_s
137:     user_name node['myApp_chef']['myApp_user'].to_s
138:     group_name node['myApp_chef']['myApp_group'].to_s
139:     jar_name service['jar_name']
140:     action %i[enable start]
141:   end
142: end

Compiled Resource:
------------------
# Declared in /tmp/kitchen/cache/cookbooks/myApp_chef/recipes/default.rb:134:in `block in from_file'

java_service("myApp service for file processing") do
    action [:enable, :start]
    default_guard_interpreter :default
    declared_type :java_service
    cookbook_name "myApp_chef"
    recipe_name "default"
    service_name "myApp-fp"
    env "test"
    user_name "myAppuser"
    group_name "myAppgroup"
    jar_name "myApp_file_processing-1.21.0.jar"
end

System Info:
------------
chef_version=14.12.9
platform=centos
platform_version=7.2.1511
ruby=ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]
program_name=/opt/chef/bin/chef-client
executable=/opt/chef/bin/chef-client

What can be done here?

Berksfile contents:

source 'https://supermarket.chef.io'
source 'https://supermarket.<mycompany>.com'

metadata
cookbook 'chef-vault'
cookbook 'filebeat', '~> 1.4.0'

2

Answers


  1. Chosen as BEST ANSWER

    All, I did resolve this by creating the necessary service(s) in the main recipe itself. The java_service was working with the 13 version of chef but not with 14.

    For now I created the service in the recipe to solve the problem. Thanks for all the suggestions


  2. java_service is not a built-in chef resource. thus, you will need to be dependent on a cookbook that provides the java_service resource, and will specify the dependency in your Berksfile.

    each cookbook in the Berksfile that you shared, does not provide the java_service resource.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search