There may be a time when you don’t want to (or cannot) make use of knife bootstrap to set up a new Chef node or a whole fleet of hundreds of nodes. If that’s the case, and you already have a “hook” into the hosts you want to turn into Chef nodes (such as an existing CM tool), you have an option.
- Install the proper Chef client package for the OS
mkdir /etc/chef- Drop your “validator“, typically
validation.pemin/etc/chef - Drop a basic
client.rbin/etc/chef - Drop a JSON file somewhere that includes the node attributes you want to set for the new node
- Run
chef-client -E some-environment -j /your/json/file - When you’re happy,
rm -f /etc/chef/validation.pem
What’s interesting here (bug?) is that, when running chef-client, specifying -E some-environment will assign some-environment to the node and persist that setting on the Chef server. Trying to use -o 'role[myrole]' to prime and persist a run list for the node will not work (hence the JSON hack).
You should end up with a new client and node defined on your Chef server and the node should have the environment and run list set the way you specified.
Example files
# /etc/chef/client.rb log_level :auto log_location STDOUT chef_server_url "https://your-chef-server.example.com" validation_client_name "chef-validator"
# /tmp/boot.json
{
"run_list": ["role[myrole]", "recipe[foo::bar]"]
}