【问题标题】:Chef - roles and environments厨师 - 角色和环境
【发布时间】:2017-03-04 15:57:57
【问题描述】:

从厨师开始,难以进行角色/环境设置。无法弄清楚我错过了什么。

     Cookbooks: nginx_webserver
          recipes: default.rb, config_test, config_dev

     Roles: 
          webserver
     Environment:
          dev, qa 

这是我的角色文件:

     chef_type:           role
     default_attributes:
     description:         Nginx webserver
     env_run_lists:
         dev: recipe[nginx_webserver::config_dev]
         qa:  recipe[nginx_webserver::config_qa]
         json_class:          Chef::Role
         name:                webserver
         override_attributes:
         run_list:            recipe[nginx_webserver]

这是我的环境列表

        chef_type:           environment
        cookbook_versions:
           nginx_webserver: = 0.1.2
        default_attributes:
        description:         development environment
        json_class:          Chef::Environment
        name:                dev
        override_attributes:
              nginx:
        site_dir: dev.mysite.com # This value changes between envs

这是我的节点列表:

        {
          "name": "chef-node1",
          "chef_environment": "dev",
          "normal": {
            "tags": [

                 ]
          },
          "policy_name": null,
          "policy_group": null,
          "run_list": [
            "role[webserver]"
           ]

         }

我的厨师客户输出/错误:

        54.149.131.42 Recipe Compile Error
        54.149.131.42   

        ====================================================================
        54.149.131.42
        54.149.131.42 Chef::Exceptions::RecipeNotFound
        54.149.131.42 --------------------------------
        54.149.131.42 could not find recipe config_dev for cookbook    
        nginx_webserver
        54.149.131.42

我不确定如何在 Chef 服务器上安装我的 config_dev 和 config_qa 食谱。我已将两者都包含在我的 default.rb 配方中,但我仍然不断收到此错误。我的目标是在开发环境时调用 confg_dev recipe,在 qa 时调用 config_qa。请各位指点

编辑:1

cookbook show 命令的输出

名称:nginx_webserver-0.1.2 提供者: 食谱: 校验和:23978bdef70ea9a852e27d9489acdda1 名称:default.rb 路径:recipes/default.rb 特异性:默认 网址:https://s3-external-1.amazonaws.com:443/opscode-platform-production-data/organization-0ffe55465085b0ed5ec6cc4dc383888e/checksum-23978bdef70ea9a852e27d9489acdda1?AWSAccessKeyId=AKIAIQKPG2CTSTRVDO4Q&Expires=1477168767&Signature=8EUWtT1RJq1S6/N0nF00XV879fg%3D 资源: 根文件: 校验和:d5324dd6a872900fd6ee12c9628d9595 名称:README.md 路径:README.md 特异性:默认 网址:https://s3-external-1.amazonaws.com:443/opscode-platform-production-data/organization-0ffe55465085b0ed5ec6cc4dc383888e/checksum-d5324dd6a872900fd6ee12c9628d9595?AWSAccessKeyId=AKIAIQKPG2CTSTRVDO4Q&Expires=1477168767&Signature=KuzF07t3/Xnw3BA30PkcNbsnQf0%3D

校验和:d14d45c195dccbfe56b358b71d2a6a6b 名称:厨师长 路径:厨师长 特异性:默认 网址:https://s3-external-1.amazonaws.com:443/opscode-platform-production-data/organization-0ffe55465085b0ed5ec6cc4dc383888e/checksum-d14d45c195dccbfe56b358b71d2a6a6b?AWSAccessKeyId=AKIAIQKPG2CTSTRVDO4Q&Expires=1477168767&Signature=8nlPR7LBWOQbn6C7CfCaNTieaqM%3D

校验和:6528f8499102744b7616913a6cb225de 名称: Berksfile 路径: Berksfile 特异性:默认 网址:https://s3-external-1.amazonaws.com:443/opscode-platform-production-data/organization-0ffe55465085b0ed5ec6cc4dc383888e/checksum-6528f8499102744b7616913a6cb225de?AWSAccessKeyId=AKIAIQKPG2CTSTRVDO4Q&Expires=1477168767&Signature=0KRkWnrxasYQFhKaM0Kdqh79ltk%3D


编辑 - 2:

食谱/default.rb

     include_recipe 'selinux::permissive'
     include_recipe 'nginx_webserver::config_dev'
     include_recipe 'nginx_webserver::config_qa'

将 metadata.rb 更新为 = 0.1.3

 knife cookbook upload nginx_webserver
 Uploading nginx_webserver [0.1.3]
 Uploaded 1 cookbook.

得到同样的错误。另外,我真的需要在我的 default.rb 中包含我的 config_dev 和 config_qa 吗?厨师不应该根据 env_run_lists 自动挑选这些食谱吗?

【问题讨论】:

  • knife cookbook show nginx_webserver 0.1.2 为您显示什么?
  • 展示了很多东西。主要是关于我的两个食谱——selinux 和 nginx。有什么具体的你正在寻找的东西
  • 理想情况下是整个输出,所以我们在这里都可以理解这里发生了什么,至少如果 config_dev 配方在该版本中可见
  • 我添加了一些部分。但它没有显示关于我的 config_dev 配方的任何信息
  • 请在每个代码行的左边添加四个空格,使其成为代码格式

标签: chef-infra


【解决方案1】:

您的环境使用没有配方的版本(假设您已根据您的日志将它们上传到0.1.3):

    chef_type:           environment
    cookbook_versions:
       nginx_webserver: = 0.1.2

请使用knife environment edit,将0.1.3放在那里,然后再次尝试收敛节点。

【讨论】:

  • 我做了,但结果还是一样。我是否需要在默认配方中包含非默认配方。我注意到的另一件事是 Chef-server (UI - Attributes) 中显示的食谱版本仍然很旧。我确实上传了食谱,也上传了 berks。此外,用户界面会显示适当的环境和相关的配方。
  • @f-z-N 请附上截图