/rpi-ansible

Automatically sets up my raspberry pis in a headless state

Primary LanguageShell

ansible-rpi

This repository setups raspberry pi's headless with wifi k

About

This is an ansible repository used to setup raspberry pi's in a headless state. You should need a basic knowledge of ansible and linux/mac/*nix to use this.

Prerequisites

  • ansible 2.x
  • an ssh key Guide here
  • latest Raspbian image Download
  • a Raspberry Pi with some kind of wifi

Pre Ansible Steps

All of these need to be done before we can run the ansible playbook

  1. copy the latest Raspbian image to your SD card (See the "latest Raspbian image" link above for more info)
  2. mount the second partition of the newly created Raspbian image
mount /dev/disk2s2 /mnt/sd/

(Note in my case the device was /dev/disk2s2 you can find your device name by using fdisk -l)

  1. mount the first partition to /mnt/sd/boot Use the same steps as above
  2. edit requirements/dhcpcd.conf go to the bottom of the file, update the IP address, router, and DNS servers
  3. edit requirements/wpa_supplicant.conf
  • change the country code to your countries two digit code
  • change the SSID to your wireless SSID name
  • change the PSK to your wireless password
  • use: wpa_passphrase YOUR_SSID YOUR_PASSWORD on a computer with wpa_passphrase installed to mask your PSK
  • will look similar to this when done psk=ceff3c46ec98932f4cea44f19b776f620027f78559cff46afde5e66ce835d9b2
  1. copy requirements/dhcpcd.conf to (and overwrite) /mnt/sd/etc/dhcpd.conf
  2. copy requirements/wpa_supplicant.conf to /mnt/sd/boot
  3. create an empty file called "ssh" in /mnt/sd/boot
  • touch /mnt/sd/boot/ssh
  1. unmount /mnt/sd/boot
  • umount /mnt/sd/boot
  1. unmount /mnt/sd
  • umount /mnt/sd
  1. put the sd card into your raspberry pi and plug it in
  2. ensure your raspberrry pi is connected to your network
  • ping the ip address you put int dhcpcd.conf
  • if it's not responding wait a minute
  • if it's still not responding check dhcpcd.conf and wpa_supplicant.conf for errors

Ansible Steps

  1. edit inventories/all/hosts
  • setup your hosts as formatted there
  1. edit roles/common/vars/main.yml
  • edit to include the username and ssh key you want
  1. edit roles/common/default/main.yml
  • include any packages you want installed on your raspberry pis
  1. run the ansible playbook
  • ansible-playbook -b site.yml -t setup