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:- Most commands we’ll be executing require root, so let’s elevate our session:
Where sudo = "super user do" and su ="super user"; using root privs to assume root identity.sudo su
- Pull the newest package lists from configured repositories to ensure we get the newest packages:
apt-get update
- Install pre-requisites for Ruby: gcc, make, and libssl-dev with their dependencies.
apt-get install gcc make libssl-dev
Note: On some distros, such as Raspbian, gcc and make are installed by default. It won't hurt to include the in the command line none the less, and including it here will cover most distros.
- Download the Ruby source to the /usr/src directory:
Note: 2.2.5 is the newest 2.2 version at the time of this writing, but you should make sure there isn't a newer version avialable. Check the Ruby page here.cd /usr/src wget https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.5.tar.gz
- Extract the source & navigate to the directory (Make sure you update filenames/directory names for differing versions):
tar -xvzf ruby-2.2.5.tar.gz cd ruby-2.2.5
- Prepare to compile with configure, omitting unnecessary components:
./configure --enable-shared --disable-install-doc --disable-install-rdoc --disable-install-capi
Note: This will take between 2 and 10 minutes depending on which Pi and the speed of your SD card.
- Compile it using make!
make -j4 ; make install
Note: "make -j4" will multi-thread the execution, using each of the Raspi's processors. This will take between 15 and 30 minutes depending on your Pi and SD card.
Step 2: Install Chef
Now we’ll use the gem install command to get Chef- Execute gem install chef as root (sudo if not).
Note: This will take between 5 and 25 minutes depending on which Pi, SD card, and network connection.gem install chef
- 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.- Use the knife command to boostrap the newly installed client
Where: {user} is a user on the target platform with root privs and {password} is the password for that account.knife bootstrap rasdock02.truckchase.lan -N rasdock02.truckchase.lan -x {user} -P {password}
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.
Thanks, your guide worked perfectly on my Raspberry Pi 3. Also monitored the temperature of the CPU and it never went above 112 F. Build steps each took about 8 minutes.
Thanks, I'm glad it worked for you!
Your version of Ruby is deprecated and throws an error. Changing to a 2.4+ version fixed it with no other changes to your documentation.
Thanks @Mike! Updated the article with your information.
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
Great blog post.You can refer to the post and know how to install and configure Chef version on a Raspberry pi case. Thanks for the post.
Post a Comment