Skip to content
Permalink
Browse files

Fixes #60: Get networking setup working with Raspbian Jessie Lite.

  • Loading branch information...
geerlingguy committed Mar 10, 2016
1 parent 8ad7091 commit 11dfedc49ab70869151b27bb1124dc5b973d5f51
@@ -1,2 +1,5 @@
.DS_Store
.vagrant

setup/networking/inventory
setup/networking/vars.yml
@@ -2,13 +2,17 @@

When you plug a fresh new Raspberry Pi into your network, the default configuration tells the Pi to use DHCP to dynamically request an IP address from your network's router. Typically this is a pretty random address, and it can make configuration annoying.

To keep things simpler, I elected to jot down the MAC addresses of each of the Pis' onboard LAN ports (this stays the same over time), and map those to a set of contiguous static IP addresses so I can deploy, for example, the balancer to 10.0.1.60, the webservers to 10.0.1.61-63, and so on.
To keep things simpler, I elected to jot down the MAC addresses of each of the Pis' onboard LAN ports (this stays the same over time), and map those to a set of contiguous static IP addresses so I can deploy, for example, the balancer to 10.0.1.60, the webservers to 10.0.1.61-62, and so on.

The playbook and configuration in this directory will automatically perform all the required networking configuration to make this so.

To run the playbook, after you have all your Pi IP addresses listed in the `inventory` and all the MAC addresses mapped to IP addresses and hostnames in `vars.yml`:
To run the playbook:

$ ansible-playbook -i inventory main.yml
1. Copy `example.inventory` to `inventory`, and list all your Raspberry Pi's _current_ IP addresses under `[pis]`
2. Copy `example.vars.yml` to `vars.yml`, and make sure each Pi's MAC address is mapped to the desired final IP addresses and hostnames.
3. Run `ansible-playbook -i inventory main.yml`.

> _Note_: If you don't have your SSH key installed on all the Pis yet, you will also need to pass `-k` to the above command and enter your SSH password (the default for Raspbian is `raspberry`).
Reboot the Raspberry Pis after this playbook runs (once you're ready to start accessing them via their new IP addresses):

@@ -4,7 +4,6 @@
10.0.1.62
10.0.1.63
10.0.1.64
10.0.1.65

[pis:vars]
ansible_ssh_user=pi
@@ -6,24 +6,21 @@ mac_address_mapping:
name: bal1.pidramble.com
ip: "10.0.1.59"
# Balancer over built-in LAN.
"b8:27:eb:a1:14:de":
"b8:27:eb:52:6a:13":
name: bal1.pidramble.com
ip: "10.0.1.60"
"b8:27:eb:52:6a:13":
"b8:27:eb:90:52:27":
name: www1.pidramble.com
ip: "10.0.1.61"
"b8:27:eb:90:52:27":
"b8:27:eb:f0:49:d2":
name: www2.pidramble.com
ip: "10.0.1.62"
"b8:27:eb:f0:49:d2":
name: www3.pidramble.com
ip: "10.0.1.63"
"b8:27:eb:ea:9c:e0":
name: www4.pidramble.com
ip: "10.0.1.64"
"b8:27:eb:54:0c:d1":
name: db1.pidramble.com
ip: "10.0.1.65"
ip: "10.0.1.63"
"b8:27:eb:54:0c:d1":
name: db2.pidramble.com
ip: "10.0.1.64"

# Nameservers to use in resolv.conf.
dns_nameservers:
@@ -1,6 +1,6 @@
---
- hosts: pis
sudo: yes
become: yes

vars_files:
- vars.yml
@@ -25,8 +25,19 @@
- { template: hosts.j2, dest: /etc/hosts }
- { template: interfaces.j2, dest: /etc/network/interfaces }
- { template: resolv.conf.j2, dest: /etc/resolv.conf }
notify: update hostname
- { template: dhcpcd.conf.j2, dest: /etc/dhcpcd.conf }
notify:
- update hostname
- delete dhcp leases

handlers:
- name: update hostname
command: "hostname {{ dramble_hostname }}"

- name: delete dhcp leases
file:
path: /var/lib/dhcp/dhclient.leases
state: absent
with_items:
- /var/lib/dhcp/dhclient.leases
- /var/lib/dhcpcd5/dhcpcd-eth0.lease
@@ -0,0 +1,46 @@
# Configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

interface eth0
static ip_address={{ dramble_ip_address }}/24
static routers=10.0.1.1
static domain_name_servers={{ dns_nameservers | join(' ') }}

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
#duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU.
# Some interface drivers reset when changing the MTU so disabled by default.
#option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private

# A hook script is provided to lookup the hostname if not set by the DHCP
# server, but it should not be run by default.
nohook lookup-hostname
@@ -7,9 +7,8 @@ ff02::2 ip6-allrouters

127.0.1.1 {{ dramble_hostname }}

{{ groups.pis[0] }} pidramble.com www.pidramble.com bal1.pidramble.com git.pidramble.com
{{ groups.pis[1] }} www1.pidramble.com
{{ groups.pis[2] }} www2.pidramble.com
{{ groups.pis[3] }} www3.pidramble.com
{{ groups.pis[4] }} www4.pidramble.com
{{ groups.pis[5] }} db1.pidramble.com
10.0.1.60 pidramble.com www.pidramble.com bal1.pidramble.com git.pidramble.com
10.0.1.61 www1.pidramble.com
10.0.1.62 www2.pidramble.com
10.0.1.63 db1.pidramble.com
10.0.1.64 db2.pidramble.com
@@ -1,8 +1,10 @@
auto lo

iface lo inet loopback

iface eth0 inet static
address {{ dramble_ip_address }}/24
netmask 255.255.255.0
gateway 10.0.1.1
dns-nameservers {{ dns_nameservers | join(' ') }}

0 comments on commit 11dfedc

Please sign in to comment.
You can’t perform that action at this time.