【问题标题】:Chef::Exceptions::CookbookNotFound: Cookbook sudo not found and Chef-Solo “undefined method `[]' for nil:NilClass”Chef::Exceptions::CookbookNotFound: Cookbook sudo not found and Chef-Solo “undefined method `[]' for nil:NilClass”
【发布时间】:2019-12-19 20:40:25
【问题描述】:

我正在尝试制作一本有一些依赖关系的食谱,但它不起作用

/食谱 ls

default.rb

食谱:

include_recipe 'sudo::default'
include_recipe 'user'

def will_create_user?(username, user)
    return false if node['etc']['passwd'].key?(username)
    return true if user['action'] == 'create' || !user.key?('action')
    false
end

node['authorization']['sudo']['groups'].each do |group|
        group group
end


node['vms']['users'].each do |username, user| 
    send_notification = will_create_user? username, user 

    user_account username do
        comment user['comment'] if user['comment']
        ssh_keys user['ssh_keys'] 
        groups user['groups'] if user['groups'] 

        if send_notification
            notifies :run, "execute[reset_password_#{username}]", :delayed 
        end
    end

    execute "reset_password_#{username}" do
        command "passwd -d #{username} && chage -d 0 #{username}" 
        action :nothing 
    end

end

元数据.rb

...
version '0.1.0'
chef_version '>= 14.0'

depends "sudo"
depends "user"

Berksfile.lock

DEPENDENCIES
  vms-users
    path: .
    metadata: true

GRAPH
  sudo (5.4.5)
  user (0.7.0)
  vms-users (0.1.0)
    sudo (>= 0.0.0)
    user (>= 0.0.0)

属性/default.rb

{
   "vms": { 
     "users": {
        'magrini' => {
                'comment' => 'Bruna Magrini',
                'groups' => ['sysadmin'],
            'ssh_keys' => ['chave ssh'],        
               },
        }
   } 
}

我正在使用chef-client --local-mode default.rb 执行

错误: Chef::Exceptions::CookbookNotFound: Cookbook sudo 未找到

Recipe `sudo::default` is not in the run_list, and cookbook 'sudo'
is not a dependency of any cookbook in the run_list.  To load this recipe,
first add a dependency on cookbook 'sudo' in the cookbook you're
including it from in that cookbook's metadata.


Running handlers:
[2019-12-19T20:42:12+00:00] ERROR: Running exception handlers
Running handlers complete
[2019-12-19T20:42:12+00:00] ERROR: Exception handlers complete
Chef Infra Client failed. 0 resources updated in 01 seconds
[2019-12-19T20:42:12+00:00] FATAL: Stacktrace dumped to /home/chef-repo/.chef/local-mode-cache/cache/chef-stacktrace.out
[2019-12-19T20:42:12+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2019-12-19T20:42:12+00:00] FATAL: Chef::Exceptions::CookbookNotFound: Cookbook sudo not found. If you're loading sudo from another cookbook, make sure you configure the dependency in your metadata

【问题讨论】:

    标签: ruby chef-infra


    【解决方案1】:

    我感觉你在混淆某些东西,因为当你真正使用chef-zero (--local-mode) 时,你的问题标题提到了chef-solo

    你绝对应该喜欢 chef-zero 而不是 chef-solo(但我不会解释原因)。

    在这两种情况下(使用 chef-zero 或 chef-solo),您都必须下载所有食谱并验证 chef-client 知道 cookbooks located 在哪里。

    如果您使用 chef-zero,这里有一些参考:

    本地模式不需要配置文件,而是会查找名为/cookbooks 的目录并将chef_repo_path 设置为刚好高于该目录。 (如果需要,本地模式将遵循配置文件中的设置。)如果未找到 client.rb 文件且未指定配置文件,则本地模式将搜索 config.rb 文件。

    client.rb settings:

    chef_repo_path:在本地模式下运行 Chef Infra Client 时,包含食谱和其他文件(例如环境或数据包)的 chef-repo 的路径。

    cookbook_path:Chef Infra Client 食谱的子目录。此值可以是字符串或文件系统位置数组,按指定顺序处理。最后一个食谱被认为覆盖了本地修改。

    因为我看到您使用的是 berkshelf,您可以使用vendor sub-command 下载所有食谱依赖项并将它们放在同一目录中。然后,为 chef-client 进行自定义配置,将 cookbook_path 的值设置为与 berks vendor 一起使用的同一目录,最后执行 chef-client。

    【讨论】:

    • 我认为当我执行“berks install”时,它会下载我设置为依赖的食谱。如果没有,为什么我必须执行“berks install”?
    • berks install 确实会下载食谱,但berks vendor 会做一些其他的事情。这里要注意的主要事情是,您需要指示厨师烹饪书所在的位置。
    • 我明白了。我会尝试。但如果我做了“berks install”,食谱在哪里?而且我认为client.rb是在引导后在节点上创建的,如果没有,我应该创建谁? (对不起,我是新手)
    • @BrunaMagrini:你搞混了,chef节点上的client.rb和operator节点上的client.rb(以前叫knife.rb)是有区别的。默认情况下,berkshelf 会将食谱下载到~/.berkshelf/cookbooks/。但是除了原始问题之外,您还问了太多问题。请创建另一个问题,如果您觉得我的回答有帮助,请接受:)
    猜你喜欢
    • 2015-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    • 2013-10-16
    • 1970-01-01
    • 2023-03-25
    相关资源
    最近更新 更多