Skip to content

Instantly share code, notes, and snippets.

@michailw
Last active June 18, 2017 19:53
Show Gist options
  • Save michailw/21ea76347b4688ba081a36bb057cdee3 to your computer and use it in GitHub Desktop.
Save michailw/21ea76347b4688ba081a36bb057cdee3 to your computer and use it in GitHub Desktop.
- name: "Create temporary directory"
become: yes
file:
path: "/tmp/raspbian"
state: directory
- name: "Download Raspbian image"
become: yes
get_url:
url: "https://downloads.raspberrypi.org/raspbian_lite_latest"
dest: "/tmp/raspbian/raspbian.zip"
- name: "Unarchive Raspbian"
become: yes
unarchive:
src: /tmp/raspbian/raspbian.zip
dest: /tmp/raspbian/
- name: "Find Raspbian image"
find:
paths: "/tmp/raspbian"
patterns: "*.img"
register: raspbian_image_files
- name: "Check if image file was found"
set_fact:
raspbian_image_file: {{ raspbian_image_files.files.0.path }}
when:
- raspbian_image_files
- raspbian_image_files.files
- raspbian_image_files.files.0
- raspbian_image_files.files.0.path
- name: "Copy Raspberry Image to SD Card"
become: yes
command: "dd bs=4M if={{ raspbian_image_file }} of={{ raspbian_target_device }}"
- name: "Read image from SD card"
become: yes
command: "dd bs=4M if={{ raspbian_target_device }} of=/tmp/raspbian/check-read.img"
- name: "Truncate image from SD card"
become: yes
command: "truncate --reference {{ raspbian_image_file }} /tmp/raspbian/check-read.img"
- name: "Verify if images are equal"
become: yes
command: "diff -s /tmp/raspbian/check-read.img {{ raspbian_image_file }}"
- name: "Ensure write cache is flushed"
become: yes
command: "sync"
- name: "Create mounting point #1"
become: yes
file:
path: "{{ raspbian_mounting_point }}/boot"
state: directory
- name: "Create mounting point #2"
become: yes
file:
path: "{{ raspbian_mounting_point }}/main"
state: directory
- name: "Mount card locally"
become: yes
command: "mount -t vfat {{ raspbian_target_device }} {{ raspbian_mounting_point }}/boot"
- name: "Enable SSH on boot"
become: yes
file:
path: "{{ raspbian_mounting_point }}/boot/ssh"
state: touch
### /etc/network/interfaces ###
- name: "wlan0 config"
become: yes
blockinfile:
path: "{{ raspbian_mounting_point }}/etc/network/interfaces"
block: |
auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
- name: "Configure WiFi settings"
become: yes
blockinfile:
path: "{{ raspbian_mounting_point }}/etc/wpa_supplicant/wpa_supplicant.conf"
block: |
network={
ssid="Raspberry"
psk="raspberrypi"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
auth_alg=OPEN
}
- name: "Disable HDMI output"
become: yes
lineinfile:
path: "{{ raspbian_mounting_point }}/etc/rc.local"
insertbefore: '\s*exit\s*0'
state: present
line: "/usr/bin/tvservice -o"
- name: "Ensure write cache is flushed"
become: yes
command: "sync"
- name: "Unmount SD card"
become: yes
command: "unmount TODO"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment