350 Role vbotka.freebsd.rsnapshot
Use case
Use the role vbotka.freebsd.rsnapshot to install and configure rsnapshot.
Tree
shell> tree .
.
├── ansible.cfg
├── group_vars
│ └── all
│ ├── ansible-client.yml
│ ├── common.yml
│ └── rsnapshot.yml
├── hosts
│ ├── 04_iocage.yml
│ └── 99_constructed.yml
├── iocage.ini
├── pb-install.yml
└── pb-test.yml
Synopsis
The playbook vbotka.freebsd.pb_iocage_ansible_clients.yml creates and starts jails.
The playbook
pb-install.ymlinstalls rsnapshot in running jails.The playbook
pb-test.ymlconfigures rsnapshot in running jails.
Requirements
Templates created in 202 Create iocage templates. Clone DHCP jails.
Notes
The jail name doesn’t work in the parameter name of the module community.general.pkgng if the jail was created by
iocage. Use JID insteadjail: "{{ iocage_jid }}"
The plays run at the jails. The inventory
iocage.iniis needed when a task is delegated to an iocage hostdelegate_to: "{{ iocage_tags.vmm }}"
Disable use_globs
freebsd_pkgng_use_globs: false
to use the packages in the form pkg-origin
rsnapshot_packages: - sysutils/rsnapshot
ansible.cfg
Do not display skipped hosts. See the option display_skipped_hosts
[defaults]
gathering = explicit
callback_result_format = yaml
display_skipped_hosts = false
host_key_checking = false
[connection]
pipelining = true
Inventory iocage.ini
iocage_02 ansible_host=10.1.0.73
iocage_04 ansible_host=10.1.0.29
[iocage]
iocage_04
[iocage:vars]
ansible_user=admin
ansible_become=true
ansible_python_interpreter=auto_silent
group_vars
properties:
notes: "vmm={{ inventory_hostname }}"
swarms:
sw_01:
count: 3
template: ansible_client
properties:
bpf: 1
dhcp: 1
vnet: 1
ansible_python_interpreter: auto_silent
freebsd_pkgng_cached: false
freebsd_pkgng_use_globs: false
rsnapshot_install: false
rsnapshot_packages:
- sysutils/rsnapshot
rsnapshot_config_template: rsnapshot.conf.j2
rsnapshot_snapshot_root: /export/backup/snapshots
rsnapshot_no_create_root: '0'
rsnapshot_backup_points:
- {dir: /etc/, host: localhost/}
- {dir: /usr/local/etc/, host: localhost/}
rsnapshot_backup_points_test:
- {dir: /scratch/rsnapshot-test/, host: localhost/}
rsnapshot_exclude:
- regex: '.git/'
- regex: '.#*'
rsnapshot_test: true
rsnapshot_config_template_test: rsnapshot-test.conf.j2
rsnapshot_snapshot_root_test: /export/backup/snapshots-test
Create and start jails
(env) > ansible-playbook vbotka.freebsd.pb_iocage_ansible_clients.yml -i iocage \
-t swarm -e swarm=true
PLAY [Create and start jails. Optionally stop and destroy jails.] **************
TASK [Get iocage facts] ********************************************************
ok: [iocage_04]
TASK [Create swarms] ***********************************************************
changed: [iocage_04] => (item=sw_01)
TASK [Get iocage facts] ********************************************************
ok: [iocage_04]
TASK [Start swarms] ************************************************************
changed: [iocage_04] => (item=sw_01)
PLAY RECAP *********************************************************************
iocage_04 : ok=4 changed=2 unreachable=0 failed=0 skipped=6 rescued=0 ignored=0
Jails at iocage_04
[iocage_04]# iocage list -l
+-----+----------+------+-------+------+-----------------+--------------------+-----+----------------+----------+
| JID | NAME | BOOT | STATE | TYPE | RELEASE | IP4 | IP6 | TEMPLATE | BASEJAIL |
+=====+==========+======+=======+======+=================+====================+=====+================+==========+
| 90 | b2b1ef56 | off | up | jail | 15.0-RELEASE-p3 | epair0b|10.1.0.135 | - | ansible_client | no |
+-----+----------+------+-------+------+-----------------+--------------------+-----+----------------+----------+
| 91 | bdf104a6 | off | up | jail | 15.0-RELEASE-p3 | epair0b|10.1.0.145 | - | ansible_client | no |
+-----+----------+------+-------+------+-----------------+--------------------+-----+----------------+----------+
| 92 | fd032233 | off | up | jail | 15.0-RELEASE-p3 | epair0b|10.1.0.173 | - | ansible_client | no |
+-----+----------+------+-------+------+-----------------+--------------------+-----+----------------+----------+
Inventory hosts
plugin: vbotka.freebsd.iocage
host: 10.1.0.29
user: admin
env:
CRYPTOGRAPHY_OPENSSL_NO_LEGACY: 1
get_properties: True
hooks_results:
- /var/db/dhclient-hook.address.epair0b
compose:
ansible_host: (iocage_hooks.0 == '-') | ternary(iocage_ip4, iocage_hooks.0)
iocage_tags: dict(iocage_properties.notes | regex_findall('(\w+)=([\w\-]+)'))
plugin: ansible.builtin.constructed
groups:
up: iocage_state == 'up'
keyed_groups:
- prefix: swarm
key: iocage_tags.swarm
- prefix: vmm
key: iocage_tags.vmm
Display inventory
(env) > ansible-inventory -i hosts -i iocage.ini --graph
@all:
|--@ungrouped:
| |--iocage_02
|--@up:
| |--b2b1ef56
| |--bdf104a6
| |--fd032233
|--@swarm_sw_01:
| |--b2b1ef56
| |--bdf104a6
| |--fd032233
|--@vmm_iocage_04:
| |--b2b1ef56
| |--bdf104a6
| |--fd032233
|--@iocage:
| |--iocage_04
Playbook pb-install.yml
- name: Install packages.
hosts: up
gather_facts: true
remote_user: admin
become: true
tasks:
- name: Install rsnapshot packages.
delegate_to: "{{ iocage_tags.vmm }}"
register: out
community.general.pkgng:
name: "{{ rsnapshot_packages }}"
jail: "{{ iocage_jid }}"
cached: "{{ freebsd_pkgng_cached }}"
use_globs: "{{ freebsd_pkgng_use_globs }}"
- name: Debug.
when: debug | d(false) | bool
ansible.builtin.debug:
var: out
Playbook output - Install packages
The inventory iocage.ini is needed when a task is delegated to an iocage host
(env) > ansible-playbook pb-install.yml -i hosts -i iocage.ini
PLAY [Install packages.] *******************************************************
TASK [Gathering Facts] *********************************************************
ok: [fd032233]
ok: [bdf104a6]
ok: [b2b1ef56]
TASK [Install rsnapshot packages.] *********************************************
changed: [fd032233 -> iocage_04(10.1.0.29)]
changed: [b2b1ef56 -> iocage_04(10.1.0.29)]
changed: [bdf104a6 -> iocage_04(10.1.0.29)]
PLAY RECAP *********************************************************************
b2b1ef56 : ok=2 changed=1 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
bdf104a6 : ok=2 changed=1 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
fd032233 : ok=2 changed=1 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
Playbook pb-test.yml
- name: Test role vbotka.freebsd.rsnapshot
hosts: up
gather_facts: true
remote_user: admin
become: true
roles:
- vbotka.freebsd.rsnapshot
Playbook output - Display variables
(env) > ansible-playbook pb-test.yml -i hosts -t rsnapshot_debug -e rsnapshot_debug=true
PLAY [Test role vbotka.freebsd.rsnapshot] **************************************
TASK [Gathering Facts] *********************************************************
ok: [b2b1ef56]
ok: [fd032233]
ok: [bdf104a6]
TASK [Vars: Include OS vars.] **************************************************
included: vbotka.freebsd.lib for b2b1ef56, bdf104a6, fd032233
TASK [vbotka.freebsd.lib : Al_include_os_vars_path: Vars from /scratch/collections/ansible_collections/vbotka/freebsd/roles/rsnapshot/vars/defaults] ***
ok: [b2b1ef56]
ok: [bdf104a6]
ok: [fd032233]
TASK [vbotka.freebsd.rsnapshot : Debug] ****************************************
ok: [b2b1ef56] =>
msg: |-
rsnapshot_role_version: 2.8.2
ansible_role_name: vbotka.freebsd.rsnapshot
ansible_facts.architecture: amd64
ansible_facts.os_family: FreeBSD
ansible_facts.distribution: FreeBSD
ansible_facts.distribution_major_version: 15
ansible_facts.distribution_version: 15.0
ansible_facts.distribution_release: 15.0-RELEASE-p1
ansible_facts.python_version: 3.11.14
freebsd_install_method: packages
freebsd_use_packages: True
freebsd_cached: False
freebsd_state: present
freebsd_use_globs: False
freebsd_install_retries: 10
freebsd_install_delay: 5
linux_install_retries: 10
linux_install_delay: 5
rsnapshot_install: False
rsnapshot_packages:
- sysutils/rsnapshot
rsnapshot_supported_linux_family: ['Debian', 'RedHat']
rsnapshot_backup_conf: False
rsnapshot_config_template: rsnapshot.conf.j2
rsnapshot_config_version: 1.2
rsnapshot_test: True
rsnapshot_config_template_test: rsnapshot-test.conf.j2
ok: [bdf104a6] =>
msg: |-
rsnapshot_role_version: 2.8.2
ansible_role_name: vbotka.freebsd.rsnapshot
ansible_facts.architecture: amd64
ansible_facts.os_family: FreeBSD
ansible_facts.distribution: FreeBSD
ansible_facts.distribution_major_version: 15
ansible_facts.distribution_version: 15.0
ansible_facts.distribution_release: 15.0-RELEASE-p1
ansible_facts.python_version: 3.11.14
freebsd_install_method: packages
freebsd_use_packages: True
freebsd_cached: False
freebsd_state: present
freebsd_use_globs: False
freebsd_install_retries: 10
freebsd_install_delay: 5
linux_install_retries: 10
linux_install_delay: 5
rsnapshot_install: False
rsnapshot_packages:
- sysutils/rsnapshot
rsnapshot_supported_linux_family: ['Debian', 'RedHat']
rsnapshot_backup_conf: False
rsnapshot_config_template: rsnapshot.conf.j2
rsnapshot_config_version: 1.2
rsnapshot_test: True
rsnapshot_config_template_test: rsnapshot-test.conf.j2
ok: [fd032233] =>
msg: |-
rsnapshot_role_version: 2.8.2
ansible_role_name: vbotka.freebsd.rsnapshot
ansible_facts.architecture: amd64
ansible_facts.os_family: FreeBSD
ansible_facts.distribution: FreeBSD
ansible_facts.distribution_major_version: 15
ansible_facts.distribution_version: 15.0
ansible_facts.distribution_release: 15.0-RELEASE-p1
ansible_facts.python_version: 3.11.14
freebsd_install_method: packages
freebsd_use_packages: True
freebsd_cached: False
freebsd_state: present
freebsd_use_globs: False
freebsd_install_retries: 10
freebsd_install_delay: 5
linux_install_retries: 10
linux_install_delay: 5
rsnapshot_install: False
rsnapshot_packages:
- sysutils/rsnapshot
rsnapshot_supported_linux_family: ['Debian', 'RedHat']
rsnapshot_backup_conf: False
rsnapshot_config_template: rsnapshot.conf.j2
rsnapshot_config_version: 1.2
rsnapshot_test: True
rsnapshot_config_template_test: rsnapshot-test.conf.j2
PLAY RECAP *********************************************************************
b2b1ef56 : ok=4 changed=0 unreachable=0 failed=0 skipped=6 rescued=0 ignored=0
bdf104a6 : ok=4 changed=0 unreachable=0 failed=0 skipped=6 rescued=0 ignored=0
fd032233 : ok=4 changed=0 unreachable=0 failed=0 skipped=6 rescued=0 ignored=0
Playbook output - Configure rsnapshot
(env) > ansible-playbook pb-test.yml -i hosts
PLAY [Test role vbotka.freebsd.rsnapshot] **************************************
TASK [Gathering Facts] *********************************************************
ok: [fd032233]
ok: [b2b1ef56]
ok: [bdf104a6]
TASK [Vars: Include OS vars.] **************************************************
included: vbotka.freebsd.lib for b2b1ef56, bdf104a6, fd032233
TASK [vbotka.freebsd.lib : Al_include_os_vars_path: Vars from /scratch/collections/ansible_collections/vbotka/freebsd/roles/rsnapshot/vars/defaults] ***
ok: [b2b1ef56]
ok: [fd032233]
ok: [bdf104a6]
TASK [vbotka.freebsd.rsnapshot : Configure: Create directory /export/backup/snapshots] ***
changed: [fd032233]
changed: [bdf104a6]
changed: [b2b1ef56]
TASK [vbotka.freebsd.rsnapshot : Configure: Create configuration /usr/local/etc/rsnapshot.conf] ***
changed: [bdf104a6]
changed: [b2b1ef56]
changed: [fd032233]
TASK [vbotka.freebsd.rsnapshot : Test: Create test directory /export/backup/snapshots-test] ***
changed: [b2b1ef56]
changed: [fd032233]
changed: [bdf104a6]
TASK [vbotka.freebsd.rsnapshot : Test: Create test backup_points] **************
changed: [bdf104a6] => (item={'dir': '/scratch/rsnapshot-test/', 'host': 'localhost/'})
changed: [b2b1ef56] => (item={'dir': '/scratch/rsnapshot-test/', 'host': 'localhost/'})
changed: [fd032233] => (item={'dir': '/scratch/rsnapshot-test/', 'host': 'localhost/'})
TASK [vbotka.freebsd.rsnapshot : Test: Create test configuration /usr/local/etc/rsnapshot-test.conf] ***
changed: [b2b1ef56]
changed: [fd032233]
changed: [bdf104a6]
PLAY RECAP *********************************************************************
b2b1ef56 : ok=8 changed=5 unreachable=0 failed=0 skipped=11 rescued=0 ignored=0
bdf104a6 : ok=8 changed=5 unreachable=0 failed=0 skipped=11 rescued=0 ignored=0
fd032233 : ok=8 changed=5 unreachable=0 failed=0 skipped=11 rescued=0 ignored=0
Results
TBD