Skip to content

Instantly share code, notes, and snippets.

@AjkayAlan
Last active June 20, 2024 00:48
Show Gist options
  • Save AjkayAlan/ca856a5b5b36bdbd3e38f6c1a7e60bd7 to your computer and use it in GitHub Desktop.
Save AjkayAlan/ca856a5b5b36bdbd3e38f6c1a7e60bd7 to your computer and use it in GitHub Desktop.
Create a Docker host with Ansible on a Raspberry Pi 4b

RPI4 Docker Host With Ansible

A fun experement to run everything on my home network using Docker, with it all managed via Ansible. A few notes...

  1. This will rely on you setting up some things on the RPI manually
  2. It will rely on running Ansible via localhost (instead of another device running ansible against the RPI)

Flashing The OS

  1. Download the Raspberry Pi Imager and format your SD card
  2. Choose Ubuntu Server 24 and select the advanced options
  3. Set the hostname to ubuntu-pi-server.local
  4. Enable SSH, using username and password auth. Set the username to ubuntu and the password to something safe that only you will know
  5. Save, then Write
  6. Boot the SD card, giving ~5 minutes after you power it up before trying to connect

First Time SSH'ing

  1. From your computer, ssh to ubuntu@ubuntu-pi-server.local.

Setting Up Static IP

  1. Run ip a to identify the network interface. We will assume that eth0 is your ethernet for this example
  2. Run ls /etc/netplan to identify the yaml config file you need to edit. Likely 01-netcfg.yaml or 50-cloud-init.yaml
  3. Edit the netplan (changing the file as appropriate) via sudo vi /etc/netplan/50-cloud-init.yaml:
    network:
      version: 2
      ethernets:
        eth0:
          addresses:
            - 192.168.1.10/24
          routes:
            - to: default
              via: 192.168.1.1
          nameservers:
            addresses: [192.168.1.1]
  4. Apply the netplan changes via sudo netplan apply
  5. Verify with ip a, look at inet of the interface.

Install Ansible & Git

sudo apt update
sudo apt install -y software-properties-common git
sudo add-apt-repository --yes --update ppa:ansible/ansible
sudo apt install -y ansible

Clone & Run Playbook

cd ~
mkdir git
cd git
git clone git@github.com:AjkayAlan/ansible-rpi-docker-homelab-alan.git
cd ansible-rpi-docker-homelab-alan

Then read the readme at https://github.com/AjkayAlan/ansible-rpi-docker-homelab-alan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment