DEV Community

Cover image for Three quick tips when setting up a new node with Chef Infra!

Three quick tips when setting up a new node with Chef Infra!

Jennifer Davis
Jennifer is a site reliability engineer, author and public speaker. She founded CoffeeOps, co-wrote Effective DevOps, and organizes devopsdays.
・2 min read

I was helping someone this evening with setting up a new node with Chef Infra. I wanted to document this so that if someone else experienced a similar problem, it might be a bit easier to understand what's going on.

Tip 1 Ask for help when you get stuck.

The problem statement was "trying to pass a JSON file to chef-zero for extra attributes." The command in use was chef-client.

Folks might not know the exact terminology in use by a product so it can be hard to figure it out without guidance. Folks with expertise may be able to give you more insight with the right terminology.

To make sure I understood what the person was looking for, I asked clarifying questions. The answers to those questions helped me understand that this was setting up a new instance or bootstrapping. While the chef-client page has helpful information, it isn't as specific and direct as the bootstrapping page.

Tip 2 Don't pass -o and -j both to chef-client.

-o overrides the run_list, and -j is how you specify a file that includes the recipes and attributes that you want to run. So instead of using both -j and -o, we took the configuration specified after -o and added it to the JSON file.

Tip 3 The JSON file has a particular format that shouldn't look like a standard attribute file.

Within the node attributes file, attributes look like node['resolver']['nameservers']. So this:

    "node['resolver']['nameservers']": [""],
    "node['search']": "http://sparkle.corp",
    "run_list": ["recipe[resolver]"]
Enter fullscreen mode Exit fullscreen mode

is valid JSON and looks close to the appropriate configuration within the node attributes definitions. It will even successfully be accepted but won't have the expected behavior. No errors will point you to the problem with the JSON file on converge.

Instead, the JSON file should look like this:

    "resolver": {
        "nameservers": [""],
        "search": "http://sparkle.corp"
    "run_list": ["recipe[resolver]"]
Enter fullscreen mode Exit fullscreen mode

That's all for now!

Discussion (0)