blob: 6f31e9ef7772b1beb700964fc58c0af4e65e9eca [file] [log] [blame]
---
- hosts: all
connection: local
remote_user: chrome-bot
become_user: root
become: yes
become_method: sudo
vars:
nfs_ip: 192.168.1.100
# override with --extra-vars "nfs_mount_point=/opt/stage"
nfs_mount_point: /opt/prod
# If drive is changed, also change total_sectors.
drive: /dev/sda
total_sectors: "{{ansible_devices.sda.sectors}}"
# Generate this with sfdisk -d [drive]
partition_templ: "./partition.j2"
expanded_partitions: "/tmp/partitions"
vars_prompt:
- name: "static_ip"
prompt: "We will be formatting /dev/sda. If that is not okay, stop the script. \n\nWhat are the last two bytes of the static IP address of this bot? 192.168.X.Y "
private: no
- name: "hostname"
prompt: "What is the hostname of this bot? skia-rpi-*"
private: no
tasks:
# This takes the pre-existing partition template (which is a jinja2
# template, as per ansible spec) and fills in the size of the last (/b)
# partition. This is used to quickly set up the partitions of the disk
# during the "Partitioning drive" step.
- name: generating partition file
template: src="{{partition_templ}}" dest="{{expanded_partitions}}"
# The magic number 6416384 is simply the beginning of the /b partition.
# We set the size to be that minus this magic number to make the /b
# partition take up the rest of the disk.
with_items:
- {end: "{{total_sectors|int-6416384}}"}
- name: unmounting drive and partitions
shell: umount {{drive}}*
ignore_errors: true
- name: Partitioning drive
shell: sfdisk {{drive}} < {{expanded_partitions}}
ignore_errors: true
# TODO(kjlubick): perhaps use the filesystem: module
- name: formatting boot partition
command: mkfs.fat {{drive}}1 -n BOOT
- name: formatting "b" partition
command: mkfs.ext4 {{drive}}3 -L B
- name: formatting var partition
command: mkfs.ext4 {{drive}}5 -L VAR
- name: formatting tmp partition
command: mkfs.ext4 {{drive}}6 -L TMP
- name: formatting home partition
command: mkfs.ext4 {{drive}}7 -L HOME
- name: Removing reserved space
command: tune2fs {{drive}}3 -m 0
- name: unmounting drive and partitions
shell: umount {{drive}}*
ignore_errors: true
- name: remounting /boot for writing
mount: src="{{drive}}1" name="/media/boot" fstype="auto" state="mounted"
- name: Copying /boot files
shell: cp -rp {{nfs_mount_point}}/boot/* /media/boot/
- name: deleting /boot/cmdline.txt
file: path=/media/boot/cmdline.txt state=absent
- name: "writing /boot/cmdline.txt with hostname skia-rpi-{{hostname}} and ip 192.168.{{static_ip}}"
lineinfile: dest=/media/boot/cmdline.txt create=yes line="smsc95xx.turbo_mode=N dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/nfs nfsroot={{nfs_ip}}:{{nfs_mount_point}}/root,nfsvers=3 ip=192.168.{{static_ip}}:{{nfs_ip}}:192.168.1.1:255.255.255.0:skia-rpi-{{hostname}}:eth0:off:8.8.8.8:8.8.4.4 elevator=deadline fsck.repair=yes rootwait"
- name: unmounting /boot
mount: src="{{drive}}1" name="/media/boot" fstype="auto" state="absent"
- name: remounting /home for writing
mount: src="{{drive}}7" name="/media/home" fstype="auto" state="mounted"
- name: Copying /home files
command: rsync -a {{nfs_mount_point}}/root/home/chrome-bot/ /media/home/
- name: unmounting /home
mount: src="{{drive}}7" name="/media/home" fstype="auto" state="absent"
handlers: