我使用的是厨师版11.16.4和打包器v 0.7.1与docker v1.3.0
在安装厨师独奏后,我无法让厨师独奏运行厨师独奏配置器。
我收到以下错误:
错误:无法确定节点名称:配置node_name或配置系统的主机名和fqdn
我在互联网上试图弄清楚发生了什么,这个错误似乎很少见,因为node_name通常由系统给出一个默认值,或者在solo.rb中分配,这对我来说似乎不能直接覆盖在打包器配置模板中。
我的打包器配置有问题,或者这是chef-solo和docker配置之间的不兼容问题?
我正在使用以下打包器配置:
{
"variables": {
"version": "",
"base-image-version": ""
},
"builders":[{
"type": "docker",
"image": "centos:latest",
"pull": true,
"export_path": "zookeeper-base-{{user `version`}}.tar"
}],
"provisioners":[
{
"type": "chef-solo",
"cookbook_paths": ["../chef-simple/cookbooks"],
"install_command":"curl -L https://www.opscode.com/chef/install.sh | bash",
"execute_command":"chef-solo --no-color -c {{.ConfigPath}} -j {{.JsonPath}}",
"run_list":["recipe[zookeeper::install]"],
"json":{"node_name":"zookeeper-box","env_name":"dev","ip":"10.10.10.10"},
"prevent_sudo":true
}],
"post-processors": [{
"type": "docker-import",
"repository": "ed-sullivan/zookeeper-base",
"tag": "{{user `version`}}"
}]
}
答案 0 :(得分:3)
我通过在json文件中为execute_command
添加Docker主机名来解决这个问题。
"run_command": ["-d", "--hostname=foobar", "-i", "-t", "{{.Image}}", "/bin/bash"]
我还必须安装主机名包(我认为厨师使用它来查找主机名)和curl包。
"inline": ["yum -y update; yum -y install curl; yum -y install hostname"]
希望这有帮助!
答案 1 :(得分:1)
我最终通过创建配置模板来解决这个问题,该模板定义了node_name,并使用文件配置器安装了chef文件。
这是更新的配置
{
"variables": {
"version": "0.1",
"base-image-version": "",
"chef_dir" : "/tmp/packer-chef-client",
"chef_env" : "dev"
},
"builders":[{
"type": "docker",
"image": "centos:latest",
"pull": true,
"export_path": "zookeeper-base-{{user `version`}}.tar"
}],
"provisioners":[
{ "type": "shell", "inline": [ "mkdir -p {{user `chef_dir`}}", "yum install -y tar" ] },
{ "type": "file", "source": "../chef/cookbooks", "destination": "{{user `chef_dir`}}" },
{
"type": "chef-solo",
"install_command":"curl -L https://www.opscode.com/chef/install.sh | bash",
"execute_command":"chef-solo --no-color -c {{.ConfigPath}} -j {{.JsonPath}}",
"run_list":["recipe[zookeeper::install]"],
"prevent_sudo":true,
"config_template":"./solo.rb.template"
}],
}
和相应的配置模板文件
log_level :info
log_location STDOUT
local_mode true
ssl_verify_mode verify_peer
role_path "{{user `chef_dir`}}/roles"
data_bag_path "{{user `chef_dir`}}/data_bags"
environment_path "{{user `chef_dir`}}/environments"
cookbook_path [ "{{user `chef_dir`}}/cookbooks" ]
node_name "packer-docker-build"