Chef on Rasperry Pi

I hope you are familiar with bash or C++‘s stream operator >>. If not, this post’s banner is not saying Chef is greater than Raspberry Pi, but rather, adding Chef to Raspberry Pi. In this post, I’ll do just that. I’m currently in a couple of job interviews in which some technical tasks are running on my 2 servers. To avoid disturbing the critical services running on those two machines, I decided to dust off me old Raspberry Pi and play with Chef there. I need these distractions in these dark times… 😒

Setting Up Raspberry Pi

First things first. Let us set up this little thing.

  1. I picked the official ubuntu-16.04 image for Raspberry Pi 2. For other Raspberry Pi version, check Ubuntu 16.04 LTS ‘classic’. Why I chose Ubuntu server image instead of Raspbian? Since all my other servers are Ubuntu servers. I want consistency!
  2. Prepare your Raspberry Pi’s SD card. I had a 32 GB one lying around, so I formatted it to NTFS using Ubuntu’s Disk Utility. Others prefer using GParted. Whatever works for you. For more information on this process, see Raspberry Pi’s Official Linux Instruction.
  3. Once SD card is formatted, we
    xzcat ubuntu.img.xz | sudo dd bs=4M of=/dev/mmcblk0
  4. Plug it into your Raspberry Pi. Attach ethernet and power and wait.
  5. Discover your Raspberry Pi’s local IP address. This can be done by logging in to your router’s gateway and refer to your router’s documentation on the getting the list of connected machine.
  6. Finally ssh to your Raspberry Pi with username: ubuntu, password: ubuntu. It will ask you to change your password.
    ssh ubuntu@<ip location>  # Change <ip location> with your raspberry pi's ip.

Setting Up Ubuntu Server 16.04

This section will set up the installed Ubuntu Server.

  1. Like all new instance of Ubuntu Server, we update/upgrade,
    sudo apt update && sudo apt upgrade
  2. Reboot to apply the upgrade,
    sudo reboot
  3. Optional. Install your favorite text editor. As a follower of the church of GNU, praise be upon Richard Stallman, I naturally install emacs.
  4. Optional. I personally hate the “ubuntu” hostname, so I change it to my personal server naming convention linux-*. Since this is my third server, I want the hostname to be linux-03.
    1. Use your favorite editor to change /etc/hostname to your hostname. In my case, linux-03.
    2. Use your favorite editor to replace ubuntu in /etc/hosts to your desired hostname. Again, in my case, linux-03.
    3. Reboot.
  5. To avoid guessing the IP of your raspberry pi, it’s really useful to set up a static IP. Since this had been done more than a dozen times, here’s an official Ubuntu Network Configuration Documentation.

Installing Ruby

Now that our Ubuntu Server is looking like a proper server, let us install a Chef prerequisite, ruby.

  1. Download latest stable Ruby release. We can’t just use the usual apt install this time since those builds crashes. Trust me I tried…
    # Replace with the latest stable ruby version.
  2. Untar and get in there!
    tar zxvf ruby-2.4.2.tar.gz
    cd ruby-2.4.2
  3. Configure with some unnecessary flags disabled.
    ./configure --enable-shared --disable-install-doc --disable-install-rdoc --disable-install-capi
  4. Compile and install. This’ll take a while…
    make -j4 ; make install
  5. Log out / Log in to load new paths.
  6. Verify your ruby installation,
    ruby -v

Install Chef-Client

Finally, we can install the chef-client:

  1. Use gem utility tool, ruby’s package management tool, to install Chef-Client:
    gem install chef
  2. Verify your Chef-Client installation:
    chef-client --version  # Should display version.

I hope you find this guide useful. I won’t make heavy use of this like a Hadoop node. I’ll probably run some home security recipes, such as ZoneMinder.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.