Add automirror support to Ansible
This commit is contained in:
@ -91,6 +91,36 @@ pvc_autobackup:
|
||||
# Example: Unmount the {backup_root_path}
|
||||
# - "/usr/bin/umount {backup_root_path}"
|
||||
|
||||
# PVC VM automirrors
|
||||
# This is uncommented but disabled so this is not installed by default; enable it in your per-cluster configs
|
||||
# Automirror allows the sending of VM snapshots automatically to an external cluster.
|
||||
# These values are default; ensure you modify them in your own group_vars to match your system!
|
||||
pvc_automirror:
|
||||
enabled: no
|
||||
destinations:
|
||||
cluster2:
|
||||
address: pvc.cluster2.mydomain.tld
|
||||
port: 7370
|
||||
prefix: "/api/v1"
|
||||
key: 00000000-0000-0000-0000-000000000000
|
||||
ssl: yes
|
||||
verify_ssl: yes
|
||||
pool: vms
|
||||
default_destination: cluster2
|
||||
tags:
|
||||
- automirror
|
||||
schedule:
|
||||
time: "*-*-* 00/4:00:00"
|
||||
retention: 7
|
||||
reporting:
|
||||
enabled: no
|
||||
emails:
|
||||
- myuser@domain.tld
|
||||
- otheruser@domain.tld
|
||||
report_on:
|
||||
success: no
|
||||
error: yes
|
||||
|
||||
# Coordinators & Nodes list
|
||||
pvc_nodes:
|
||||
- hostname: "pvc1" # The full ansible inventory hostname of the node
|
||||
|
24
roles/pvc/tasks/automirror/disable.yml
Normal file
24
roles/pvc/tasks/automirror/disable.yml
Normal file
@ -0,0 +1,24 @@
|
||||
---
|
||||
|
||||
- name: disable timer units
|
||||
systemd:
|
||||
name: "{{ item }}"
|
||||
state: stopped
|
||||
enabled: false
|
||||
loop:
|
||||
- pvc-automirror.timer
|
||||
ignore_errors: yes
|
||||
|
||||
- name: remove automirror configurations
|
||||
file:
|
||||
dest: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- /etc/systemd/system/pvc-automirror.timer
|
||||
- /etc/systemd/system/pvc-automirror.service
|
||||
register: systemd
|
||||
ignore_errors: yes
|
||||
|
||||
- name: reload systemd to apply changes
|
||||
command: systemctl daemon-reload
|
||||
when: systemd.changed
|
23
roles/pvc/tasks/automirror/enable.yml
Normal file
23
roles/pvc/tasks/automirror/enable.yml
Normal file
@ -0,0 +1,23 @@
|
||||
---
|
||||
|
||||
- name: install automirror systemd units
|
||||
template:
|
||||
src: "automirror/pvc-automirror.{{ item }}.j2"
|
||||
dest: "/etc/systemd/system/pvc-automirror.{{ item }}"
|
||||
loop:
|
||||
- timer
|
||||
- service
|
||||
register: systemd
|
||||
|
||||
- name: reload systemd to apply changes
|
||||
command: systemctl daemon-reload
|
||||
when: systemd.changed
|
||||
|
||||
- name: enable timer units
|
||||
systemd:
|
||||
name: "{{ item }}"
|
||||
state: started
|
||||
enabled: true
|
||||
loop:
|
||||
- pvc-automirror.timer
|
||||
|
7
roles/pvc/tasks/automirror/main.yml
Normal file
7
roles/pvc/tasks/automirror/main.yml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
|
||||
- include: enable.yml
|
||||
when: pvc_automirror.enabled
|
||||
|
||||
- include: disable.yml
|
||||
when: not pvc_automirror.enabled
|
@ -65,6 +65,11 @@
|
||||
tags: pvc-autobackup
|
||||
when: pvc_autobackup is defined
|
||||
|
||||
# Install PVC automirror
|
||||
- include: automirror/main.yml
|
||||
tags: pvc-automirror
|
||||
when: pvc_automirror is defined
|
||||
|
||||
# Install CPU tuning
|
||||
- include: cputuning/main.yml
|
||||
tags: pvc-cputuning
|
||||
|
@ -1,24 +0,0 @@
|
||||
---
|
||||
# PVC Autobackup configuration
|
||||
# {{ ansible_managed }}
|
||||
|
||||
autobackup:
|
||||
backup_root_path: {{ pvc_autobackup.backup_root_path }}
|
||||
backup_root_suffix: {{ pvc_autobackup.backup_root_suffix }}
|
||||
backup_tags:
|
||||
{% for tag in pvc_autobackup.backup_tags %}
|
||||
- {{ tag }}
|
||||
{% endfor %}
|
||||
backup_schedule:
|
||||
full_interval: {{ pvc_autobackup.schedule.full_interval }}
|
||||
full_retention: {{ pvc_autobackup.schedule.full_retention }}
|
||||
auto_mount:
|
||||
enabled: {{ pvc_autobackup.auto_mount.enabled }}
|
||||
mount_cmds:
|
||||
{% for cmd in pvc_autobackup.auto_mount.mount_cmds %}
|
||||
- "{{ cmd }}"
|
||||
{% endfor %}
|
||||
unmount_cmds:
|
||||
{% for cmd in pvc_autobackup.auto_mount.unmount_cmds %}
|
||||
- "{{ cmd }}"
|
||||
{% endfor %}
|
9
roles/pvc/templates/automirror/pvc-automirror.service.j2
Normal file
9
roles/pvc/templates/automirror/pvc-automirror.service.j2
Normal file
@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=[Cron] PVC VM automirror
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
IgnoreSIGPIPE=false
|
||||
KillMode=process
|
||||
ExecCondition=/usr/bin/pvc --quiet node is-primary
|
||||
ExecStart=/usr/bin/pvc --quiet vm automirror --cron {% if pvc_automirror.reporting.enabled and (pvc_automirror.reporting.report_on.error or pvc_automirror.reporting.report_on.success) %}--email-report {{ pvc_automirror.reporting.emails|join(',') }}{% endif %} {% if pvc_automirror.reporting.enabled and (pvc_automirror.reporting.report_on.error and not pvc_automirror.reporting.report_on.success) %}--email-errors-only{% endif %}
|
9
roles/pvc/templates/automirror/pvc-automirror.timer.j2
Normal file
9
roles/pvc/templates/automirror/pvc-automirror.timer.j2
Normal file
@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=[Timer] PVC VM automirror
|
||||
|
||||
[Timer]
|
||||
Unit=pvc-automirror.service
|
||||
OnCalendar={{ pvc_automirror.schedule.time }}
|
||||
|
||||
[Install]
|
||||
WantedBy=pvc.target
|
@ -174,7 +174,7 @@ autobackup:
|
||||
full_interval: {{ pvc_autobackup.schedule.full_interval }}
|
||||
full_retention: {{ pvc_autobackup.schedule.full_retention }}
|
||||
auto_mount:
|
||||
enabled: {{ pvc_autobackup.auto_mount.enabled }}
|
||||
enabled: {{ 'yes' if pvc_autobackup.auto_mount.enabled else 'no' }}
|
||||
mount_cmds:
|
||||
{% for cmd in pvc_autobackup.auto_mount.mount_cmds %}
|
||||
- "{{ cmd }}"
|
||||
@ -184,6 +184,26 @@ autobackup:
|
||||
- "{{ cmd }}"
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
automirror:
|
||||
{% if pvc_automirror is defined and pvc_automirror.enabled is defined and pvc_automirror.enabled %}
|
||||
destinations:
|
||||
{% for destination in pvc_automirror.destinations %}
|
||||
{{ destination }}:
|
||||
address: {{ pvc_automirror.destinations[destination].address }}
|
||||
port: {{ pvc_automirror.destinations[destination].port }}
|
||||
prefix: {{ pvc_automirror.destinations[destination].prefix }}
|
||||
key: {{ pvc_automirror.destinations[destination].key }}
|
||||
ssl: {{ 'yes' if pvc_automirror.destinations[destination].ssl else 'no' }}
|
||||
verify_ssl: {{ 'yes' if pvc_automirror.destinations[destination].verify_ssl else 'no' }}
|
||||
pool: {{ pvc_automirror.destinations[destination].pool }}
|
||||
{% endfor %}
|
||||
default_destination: {{ pvc_automirror.default_destination }}
|
||||
mirror_tags:
|
||||
{% for tag in pvc_automirror.tags %}
|
||||
- {{ tag }}
|
||||
{% endfor %}
|
||||
keep_snapshots: {{ pvc_automirror.schedule.retention }}
|
||||
{% endif %}
|
||||
|
||||
# VIM modeline, requires "set modeline" in your VIMRC
|
||||
# vim: expandtab shiftwidth=2 tabstop=2 filetype=yaml
|
||||
|
Reference in New Issue
Block a user