Search code examples
dockerchef-solopacker

Packer provisioning docker with chef-solo gets node name not found error


I am using chef version 11.16.4 and packer v 0.7.1 with docker v1.3.0

I am having trouble getting chef-solo to run the chef-solo provisioner after it installs chef-solo.

I am getting the following error:

ERROR: Unable to determine node name: configure node_name or configure the system's hostname and fqdn

I poked around on the internet trying to figure what was happening, and this error seems rare since node_name is usually given a default value by the system, or is assigned in solo.rb, which seemed to me can not be overwritten directly in the packer config template.

Am I doing something wrong with my packer config or is this an incompatiblity issue between chef-solo and docker provisioning?

I am using the following packer config:

{
    "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`}}"
    }]
}

Solution

  • I ended up solving this by creating a config template, that defines the node_name, and installing the chef files using the file provisioner.

    Here is the updated config

    {
        "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"
         }],
    
    }
    

    and the corresponding config template file

    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"