Skip to content

Instantly share code, notes, and snippets.

@robrant
Created September 22, 2016 20:17
Show Gist options
  • Save robrant/0e1d22a4304b5b3592ae7b82d7d46fd1 to your computer and use it in GitHub Desktop.
Save robrant/0e1d22a4304b5b3592ae7b82d7d46fd1 to your computer and use it in GitHub Desktop.
Not testing ansible networking
# Mostly copied/scripted from
# https://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-address
# We're assuming you're on ethernet when this is run.
# Also worth trying:
# route -n | awk '$4 == "UG" {print $2}'
# Get basic network information
- name: Get the gateway
shell: $(/sbin/route -n | awk 'FNR == 3 {print $2}')
register: eth0_gateway
- name: Get the destination
shell: $(/sbin/route -n | awk 'FNR == 4 {print $1}')
register: eth0_destination
- name: Get the mask
shell: $(/sbin/route -n | awk 'FNR == 4 {print $3}')
register: eth0_mask
# Set variables with those parameters
- name: Set the network variables
set_fact:
eth0_gateway : eth0_gateway
eth0_destination : eth0_destination
eth0_mask : eth0_mask
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment