Initial Commit
This commit is contained in:
commit
ac2d974e4b
10 changed files with 234 additions and 0 deletions
3
collections/requirements.yml
Normal file
3
collections/requirements.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
collections:
|
||||
- community.general
|
26
hosts.yml
Normal file
26
hosts.yml
Normal 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'
|
9
roles/sanoid/handlers/main.yml
Normal file
9
roles/sanoid/handlers/main.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
# file: roles/sanoid/handlers/main.yml
|
||||
|
||||
- name: Reboot Host
|
||||
reboot:
|
||||
|
||||
- name: Daemon Reload
|
||||
systemd:
|
||||
daemon_reload: yes
|
95
roles/sanoid/tasks/main.yml
Normal file
95
roles/sanoid/tasks/main.yml
Normal 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
|
13
roles/sanoid/templates/sanoid-prune.service.j2
Normal file
13
roles/sanoid/templates/sanoid-prune.service.j2
Normal 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
|
55
roles/sanoid/templates/sanoid.conf.j2
Normal file
55
roles/sanoid/templates/sanoid.conf.j2
Normal 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 %}
|
12
roles/sanoid/templates/sanoid.service.j2
Normal file
12
roles/sanoid/templates/sanoid.service.j2
Normal 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
|
10
roles/sanoid/templates/sanoid.timer.j2
Normal file
10
roles/sanoid/templates/sanoid.timer.j2
Normal 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
7
sanoid.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
# file: sanoid.yml
|
||||
|
||||
- hosts: sanoid
|
||||
become: true
|
||||
roles:
|
||||
- sanoid
|
4
site.yml
Normal file
4
site.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
## This playbook deploys the whole application stack in this site.
|
||||
|
||||
- import_playbook: sanoid.yml
|
Loading…
Add table
Add a link
Reference in a new issue