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.