Tuesday, April 19, 2016

Installing Chef on A Raspberry Pi 2/3

Introduction

So you’ve got 1,103 Raspberry Pis that you need to manage. Two things:

Why?

Wanna hang out Saturday? No? You’re busy managing all your mini computers manually? I can help you with that!

Scope

In this article we’ll cover installing and configuring the Chef version 12 client on a Raspberry Pi. This has been tested on Raspberry Pi versions 2 and 3; in theory it should work on a 1 as well, albeit slowly.

Assumptions

Raspberry Pi with Rasbian, Hypriot, or similar build with connections to interwebs

Chef server/org you would like to point clients to

Chef workstation capable of bootstrapping clients; if needed see this excellent article by Digital Ocean.

Execution

The main point of this article is really the installation of Ruby, which is the foundation on which Chef is based. Because the Ruby package in the Rasbian locations is out of date (2.1 as of this writing) we need to compile our own from source. Chef 12 requires Ruby 2.0 or greater, but Rack, which is installed with Chef, requires 2.2.2. UPDATE 7/9/2017: Ruby 2.4 or newer is now needed to continue successfully. Thanks Mike (from comments below)!

Step 1: Install Ruby

Clearly this should be scripted for optimal efficiency, but for learning purposes we’ll do it step by step to see exactly what is going on first hand. Log onto your Raspi via SSH and execute the following:

Step 2: Install Chef

Note: This will take between 5 and 25 minutes depending on which Pi, SD card, and network connection.

Relinquish root privileges as they are no longer needed. This should only exit the root session and not the SSH session itself. If you’re logged in directly as root ignore this, but don’t do that next time!

exit

Test the install to ensure it worked

chef-client --version

Step 3: Configure Chef

For this step move to your Chef workstation and logon using your account that is configured to manage your organization.

Where: {user} is a user on the target platform with root privs and {password} is the password for that account.

Note: It is normal to see errors on the first portion on the bootstrap since the Chef ARM client will not be found in the Chef repo, but the second phase should work utilizing the client we just installed.

That’s it! For further verification you can check against the Chef server using your workstation (knife client show {node name}) or even better yet, use Chef Manage if you have it available.

7 comments:

Excellent guide; thanks. I've been messing with a Chef Server on AWS and a small number of Raspberry Pi's (Zero's) to experiment and learn in the course of building an IoT project. This guide worked perfectly on the zero's, albeit it took a few hours. It's a real shame / ironic you have to spend 2.5h to get the pi to a chef-controlled state, but I'm glad I did. Nevertheless really appreciate this writeup, it's just what i needed.

Have this list of copy-pasta commands kind of defeats the purpose of chef, does it not. You can modify the https://github.com/RPi-Distro/pi-gen repo to make it build the exact base image you want (unbooted, not yet expanded, because everything is done via a QEMU chroot). I have a concise demonstration of this at https://github.com/RichardBronosky/pi-gen-extender