This is exactly why learned Ansible. I am proficient in Linux and yet I can’t remember everything I do to set up my RPis and VMs. Using Ansible all the setup becomes scripted. The scripts get checked into my source control, like I do with my OH configs. I don’t have to remember what I did because it’s all captured in the YAML. I can go back and look at the history and see how my config has changed over time. And if I have a worse case scenario and lose everything, setting everything back up the way it was is just a matter of setting up the logins on the machines and running one command.
Here is my Ansible role for moving /var/log to a tempfs file system (i.e. logging to RAM).
---
# tasks file for min-writes
# http://www.zdnet.com/article/raspberry-pi-extending-the-life-of-the-sd-card/
- name: Mount /tmp to tmpfs
mount:
path: /tmp
src: tmpfs
fstype: tmpfs
opts: defaults,noatime,nosuid,size=100m
dump: 0
state: mounted
become: yes
- name: Mount /var/tmp to tmpfs
mount:
path: /var/tmp
src: tmpfs
fstype: tmpfs
opts: defaults,noatime,nosuid,size=30m
dump: 0
state: mounted
become: yes
- name: Mount /var/log to tmpfs
mount:
path: /var/log
src: tmpfs
fstype: tmpfs
opts: defaults,noatime,nosuid,mode=0755,size=100m
dump: 0
state: mounted
become: yes
#- name: Mount /var/run to tmpfs
# mount:
# path: /var/run
# src: tmpfs
# fstype: tmpfs
# opts: defaults,noatime,nosuid,mode=0755,size=2m
# dump: 0
# state: mounted
# become: yes
- name: Reboot
include_role:
name: reboot
There are ways to collapse the above into one task but I haven’t bothered to go back and update my old playbooks yet with new things I’ve learned about Ansible.
I don’t remember why I commented out linking /var/run to a tmpfs.
The script that Russell links to does the same thing using Bash scripting, with some additions to preserve the logs periodically. I just let my logs and tmp folders disappear on a reboot unless I’m actively debugging a problem. Then I’ll enable a cron job like the script linked to above does. If I wanted to write the logs to disk periodically, I’d add a task to create a cron job to do that to the above.
For anyone overwhelmed with needing to maintain more than just a couple a Linux machines, I highly recommend spending the time to learn Ansible. It’s not hard to learn and the little bit of time you spend up front will pay huge dividends in the long run. If you do it right (I don’t yet) and build it to be idempotent (i.e. no changes are made if no changes are needed) you can use the same scripts that build the system to update/upgrade as well. I’ve a separate set of upgrade playbooks. But that means I can upgrade apt, docker images, git cloned software that needs to be built, pulling and deploying updates of my own code, etc to all of my machines with one command. The amount of time this has saved me far outweighs the amount of time I invested learning it.