Initial Commit

This commit is contained in:
chale 2025-05-20 16:31:56 -06:00
commit ac2d974e4b
10 changed files with 234 additions and 0 deletions

View file

@ -0,0 +1,3 @@
---
collections:
- community.general

26
hosts.yml Normal file
View file

@ -0,0 +1,26 @@
---
# file: hosts.yml
sanoid:
hosts:
Server1:
ansible_host: 10.1.25.67
sanoid_config:
pools:
- name: rpool
template: production
recursive: zfs
- name: rpool/zfs-share
template: production
recursive: zfs
templates:
- name: production
hourly: 24
daily: 30
montly: 3
yearly: 0
autosnap: yes
autoprune: yes
vars:
ansible_user: root
ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'

View file

@ -0,0 +1,9 @@
---
# file: roles/sanoid/handlers/main.yml
- name: Reboot Host
reboot:
- name: Daemon Reload
systemd:
daemon_reload: yes

View file

@ -0,0 +1,95 @@
---
# file: roles/zfs/tasks/main.yml
- name: Enable Code Ready Builder
community.general.dnf_config_manager:
name: crb
state: enabled
- name: Install EPEL
package:
name: epel-release
state: present
- name: Install Dependencies
package:
name: "{{ item }}"
state: present
loop:
- "git"
- "perl-Config-IniFiles"
- "perl-Data-Dumper"
- "perl-Capture-Tiny"
- "perl-Getopt-Long"
- "lzop"
- "mbuffer"
- "mhash"
- "pv"
- name: Clone Sanoid Repository
git:
repo: "https://github.com/jimsalterjrs/sanoid.git"
dest: "/opt/repos/sanoid"
- name: Place Executables
copy:
remote_src: true
src: "/opt/repos/sanoid/{{ item }}"
dest: "/usr/local/sbin"
mode: "preserve"
loop:
- "sanoid"
- "syncoid"
- "findoid"
- "sleepymutex"
- name: Create Sanoid Config Directory
file:
path: /etc/sanoid
state: directory
- name: Place Default Config
copy:
remote_src: true
src: "/opt/repos/sanoid/sanoid.defaults.conf"
dest: "/etc/sanoid/sanoid.defaults.conf"
- name: Create Config
template:
src: "sanoid.conf.j2"
dest: "/etc/sanoid/sanoid.conf"
- name: Create Sanoid Service
template:
src: "sanoid.service.j2"
dest: "/etc/systemd/system/sanoid.service"
become: true
notify: Daemon Reload
- name: Create Sanoid Pruning Service
template:
src: "sanoid-prune.service.j2"
dest: "/etc/systemd/system/sanoid-prune.service"
become: true
notify: Daemon Reload
- name: Create Sanoid Timer
template:
src: "sanoid.timer.j2"
dest: "/etc/systemd/system/sanoid.timer"
become: true
notify: Daemon Reload
- name: Flush handlers
meta: flush_handlers
- name: Enable Prune Service
service:
name: sanoid-prune.service
enabled: true
- name: Start and Enable Timer
service:
name: sanoid.timer
state: started
enabled: true

View file

@ -0,0 +1,13 @@
[Unit]
Description=Cleanup ZFS Pool
Requires=zfs.target
After=zfs.target sanoid.service
ConditionFileNotEmpty=/etc/sanoid/sanoid.conf
[Service]
Environment=TZ=UTC
Type=oneshot
ExecStart=/usr/local/sbin/sanoid --prune-snapshots --verbose
[Install]
WantedBy=sanoid.service

View file

@ -0,0 +1,55 @@
{% for pool in sanoid_config.pools %}
[{{ pool.name }}]
{% if pool.template != '' %}
use_template={{pool.template}}
{% endif %}
{% if pool.recursive|default('') != '' %}
recursive={{pool.recursive}}
{% endif %}
{% if pool.hourly|default('') != '' %}
hourly = {{ pool.hourly }}
{% endif %}
{% if pool.daily|default('') != '' %}
daily = {{ pool.daily }}
{% endif %}
{% if pool.monthly|default('') != '' %}
monthly = {{ pool.montly }}
{% endif %}
{% if pool.yearly|default('') != '' %}
yearly = {{ pool.yearly }}
{% endif %}
{% if pool.autosnap|default('') != '' %}
autosnap = {{ pool.autosnap }}
{% endif %}
{% if pool.autoprune|default('') != '' %}
autoprune = {{ pool.autoprune }}
{% endif %}
{% endfor %}
########### TEMPLATES ###########
{% for template in sanoid_config.templates %}
[template_{{ template.name }}]
{% if template.hourly|default('') != '' %}
hourly = {{ template.hourly }}
{% endif %}
{% if template.daily|default('') != '' %}
daily = {{ template.daily }}
{% endif %}
{% if template.monthly|default('') != '' %}
monthly = {{ template.montly }}
{% endif %}
{% if template.yearly|default('') != '' %}
yearly = {{ template.yearly }}
{% endif %}
{% if template.autosnap|default('') != '' %}
autosnap = {{ template.autosnap }}
{% endif %}
{% if template.autoprune|default('') != '' %}
autoprune = {{ template.autoprune }}
{% endif %}
{% if template.recursive|default('') != '' %}
recursive = {{ template.recursive }}
{% endif %}
{% endfor %}

View file

@ -0,0 +1,12 @@
[Unit]
Description=Snapshot ZFS Pool
Requires=zfs.target
After=zfs.target
Wants=sanoid-prune.service
Before=sanoid-prune.service
ConditionFileNotEmpty=/etc/sanoid/sanoid.conf
[Service]
Environment=TZ=UTC
Type=oneshot
ExecStart=/usr/local/sbin/sanoid --take-snapshots --verbose

View file

@ -0,0 +1,10 @@
[Unit]
Description=Run Sanoid Every 15 Minutes
Requires=sanoid.service
[Timer]
OnCalendar=*:0/15
Persistent=true
[Install]
WantedBy=timers.target

7
sanoid.yml Normal file
View file

@ -0,0 +1,7 @@
---
# file: sanoid.yml
- hosts: sanoid
become: true
roles:
- sanoid

4
site.yml Normal file
View file

@ -0,0 +1,4 @@
---
## This playbook deploys the whole application stack in this site.
- import_playbook: sanoid.yml