本文介绍了使用Packer覆盖Chef-Client中的角色属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我担任厨师:

{
  "name": "my-role",
  "description": "Defines a role",
  "override_attributes": {
    "cookbook_one" {
      "key": "value"
    }
  }
  "run_list": [
    recipe["cookbook_one"],
    recipe["cookbook_two"]
  ]
}

我在预配器块中与Packer通话:

Which I call with Packer in the provisioner block:

{
  "variables": {
    "my-variable": ""
  },
  "provisioners": [
    {
      "type": "chef-client",
      "server_url": "https://mychefserver.com/",
      "run_list": "role[my-role]",
      ...
    }

我需要能够从Packer中将某些属性添加到recipe_two 。我读过我可以使用Chef-client的 json块预配器,将一些属性添加到运行列表。我尝试过

I need to be able to add some attributes to recipe_two from within Packer. I read I can use the json block of the chef-client provisioner to add some attributes to the runlist. I tried

  "type": "chef-client",
  "server_url": "https://mychefserver.com/",
  "run_list": "role[my-role]",
  "json": {
    "override_attributes": {
      "cookbook_two": {
        "some_key": "value"
      }
    }
  }

,当我运行打包程序时,我可以在/tmp/packer-chef-client/first-boot.json

and when I run packer I can see in /tmp/packer-chef-client/first-boot.json

   {
     "override_attributes": {
       "cookbook_two": {
         "some_key": "{{ user `my-variable` }}"
       }
     },
     "run_list": [
       "role[my-role]"
     ]
   }

但是对食谱_two的override_attributes不公开。我找不到如何使它以这种方式工作的任何示例,也找不到 json的正确格式:{}要通过的块。

But the override_attributes for recipe_two are not exposed to the cookbook. I cannot find any examples of how to get it to work in this way nor the correct format of the "json": {} block to pass through.

任何指向

推荐答案

您的打包程序文件中不应包含 override_attributes 部分。相反,它应该是这样的:

Your packer file should not include the override_attributes part. Instead it should be like this:

"type": "chef-client",
  "server_url": "https://mychefserver.com/",
  "run_list": "role[my-role]",
  "json": {
    "cookbook_two": {
      "some_key": "value"
    }
  }

这篇关于使用Packer覆盖Chef-Client中的角色属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 04:29