NameError --------- 当 Chef 在节点上执行时,未定义的局部变量或方法 `service_name'

问题描述 投票:0回答:2

我有一个厨师食谱,它从神器下载 jar 并在 /etc/systemd/system 文件夹下为该 java jar 创建服务。它曾经适用于 Chef 版本 13.9.4,但使用版本 14.12.9 我收到错误:

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

这里可以做什么?

Berks 文件内容:

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

metadata
cookbook 'chef-vault'
cookbook 'filebeat', '~> 1.4.0'
chef-infra chef-recipe
2个回答
0
投票

所有,我确实通过在主配方本身中创建必要的服务来解决这个问题。 java_service 可以与 13 版本的 Chef 配合使用,但不能与 14 版本配合使用。

现在我在菜谱中创建了服务来解决问题。谢谢大家的建议


0
投票

java_service
不是内置厨师资源。因此,您将需要依赖于提供
java_service
资源的说明书,并将在您的
Berksfile
中指定依赖项。

Berksfile
中没有食谱提供
java_service
资源。

© www.soinside.com 2019 - 2024. All rights reserved.