Skip to content

Commit

Permalink
Add APT mirrors, Time Machine adjustments, hdparm, snapraid
Browse files Browse the repository at this point in the history
  • Loading branch information
notthebee committed Aug 31, 2021
1 parent a333f24 commit eca1c95
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 14 deletions.
11 changes: 8 additions & 3 deletions ansible/group_vars/all/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ docker_dir: /opt/docker/data

dotfiles_repo: https://github.com/notthebee/dotfiles

version: focal

# Automatically select the fastest mirror
apt_mirror: mirror://mirrors.ubuntu.com/mirrors.txt

#
# Email credentials (for SMART and Snapraid error reporting)
Expand Down Expand Up @@ -132,7 +136,6 @@ samba_shares:
write_list: "{{ username }}, {{ additional_users[0].name }}"



#
# Time Machine
#
Expand All @@ -142,7 +145,6 @@ timemachine_drive: /dev/disk/by-label/TimeMachine

enable_timemachine: true


#
# Snapraid and MergerFS
#
Expand All @@ -152,6 +154,7 @@ disks:
- { name: /mnt/data1, src: /dev/disk/by-label/Data1, content: true }
- { name: /mnt/data2, src: /dev/disk/by-label/Data2, content: true }


parity_disks:
- { name: /mnt/parity1, src: /dev/disk/by-label/Parity1, content: true }

Expand All @@ -171,8 +174,10 @@ snapraid_runner_email_sendon: "error"

snapraid_runner_use_ssl: true

content_file: "{{ disks[0].name }}/snapraid.content"

snapraid_content_files:
- disks[0].name/snapraid.content
- "{{ content_file }}"
- /var/snapraid.content

snapraid_config_excludes:
Expand Down
1 change: 1 addition & 0 deletions ansible/requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ roles:
- name: bertvv.samba
- name: geerlingguy.security
- name: geerlingguy.ntp
- name: geerlingguy.hdparm
- name: chriswayg.msmtp-mailer
20 changes: 20 additions & 0 deletions ansible/roles/essential/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
modification_time: preserve
access_time: preserve

- name: Install the apt mirror list
template:
src: sources.list.j2
dest: /etc/apt/sources.list
owner: root
group: root
mode: 0644

- name: Update and upgrade apt packages
become: true
apt:
Expand All @@ -21,6 +29,7 @@

- name: Reboot if required
reboot:
msg: Rebooting due to a kernel update
when: reboot_required_file.stat.exists == true

- name: Install extra packages
Expand Down Expand Up @@ -57,3 +66,14 @@
- name: Set the hostname
hostname:
name: "{{ inventory_hostname }}"

- name: Install hdparm
apt:
name: hdparm
state: latest

- name: Install the hdparm config file
template:
src: hdparm.conf.j2
dest: /etc/hdparm.conf
mode: 0644
2 changes: 2 additions & 0 deletions ansible/roles/filesystems/hdparm/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
spindown: "120"
11 changes: 11 additions & 0 deletions ansible/roles/filesystems/hdparm/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- name: Install hdparm
apt:
name: hdparm
state: latest

- name: Install the hdparm config file
template:
src: hdparm.conf.j2
dest: /etc/hdparm.conf
mode: 0644
10 changes: 10 additions & 0 deletions ansible/roles/filesystems/hdparm/templates/hdparm.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% for device in disks %}
{{ device.src }} {
spindown_time = {{ spindown }}
}
{% endfor %}
{% for device in parity_disks %}
{{ device.src }} {
spindown_time = {{ spindown }}
}
{% endfor %}
45 changes: 34 additions & 11 deletions ansible/roles/filesystems/timemachine/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,45 @@
- 'hfsplus'
- 'hfsprogs'

- name: create the mount point for Time Machine
file:
dest: "{{ timemachine_root }}"
state: directory
owner: nobody
group: nogroup
mode: "0777"
recurse: yes

- name: Mount the Time Machine drive
mount:
name: "{{ timemachine_root }}"
src: "{{ timemachine_drive }}"
fstype: hfsplus
opts: defaults,nofail,force
state: present
opts: defaults,nofail,force,rw
state: mounted

- name: Remount the drive if it's read-only
block:
- name: Check if the drive is read-only
shell:
cmd: grep "[[:space:]]ro[[:space:],]" /proc/mounts | grep timemachine
register: timemachine_ro
failed_when: timemachine_ro.rc == 0
changed_when: timemachine_ro.rc == 0

rescue:
- name: Stop the Netatalk service
service:
name: netatalk
state: stopped

- name: Unmount and fsck the drive if it became read-only
shell:
cmd: umount "{{ timemachine_drive }}" && fsck.hfsplus "{{ timemachine_drive }}"

- name: Mount the Time Machine drive again
mount:
name: "{{ timemachine_root }}"
src: "{{ timemachine_drive }}"
fstype: hfsplus
opts: defaults,nofail,force,rw
state: mounted

- name: Start the Netatalk service
service:
name: netatalk
state: started

- name: Copy the Netatalk config
template:
Expand Down
12 changes: 12 additions & 0 deletions ansible/run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@
- hosts: all
become: yes



pre_tasks:
- name: Copy persistent data to the server
import_tasks: tasks/copy_persistent_data.yml
tags: containers

- name: print out
debug:
var: hdparm_devices



roles:
- role: essential
tags:
Expand All @@ -34,6 +42,10 @@
tags:
- snapraid

- role: filesystems/hdparm
tags:
- hdparm

- role: avahi
tags:
- avahi
Expand Down
15 changes: 15 additions & 0 deletions ansible/templates/sources.list.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
deb {{ apt_mirror }} {{ version }} main restricted

deb {{ apt_mirror }} {{ version }}-updates main restricted

deb {{ apt_mirror }} {{ version }} universe
deb {{ apt_mirror }} {{ version }}-updates universe

deb {{ apt_mirror }} {{ version }} multiverse
deb {{ apt_mirror }} {{ version }}-updates multiverse

deb {{ apt_mirror }} {{ version }}-backports main restricted universe multiverse

deb {{ apt_mirror }} {{ version }}-security main restricted
deb {{ apt_mirror }} {{ version }}-security universe
deb {{ apt_mirror }} {{ version }}-security multiverse

0 comments on commit eca1c95

Please sign in to comment.