Skip to content
Merged

Qemu #506

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Ansible/inventory
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Server types
[bare]
core01.rc reboot_async=true
core02.rc
Expand All @@ -8,7 +9,7 @@ web02.rc
[rasp]
rasp01.rc

[lxc:children]
[lxc_containers:children]
lxc_core01
lxc_core02

Expand All @@ -25,10 +26,19 @@ dns01b.rc
dhcp01b.rc
web01b.rc

# Services
[lxc]
core01.rc
core02.rc

[podman]
core01.rc
web02.rc

[qemu]
core01.rc

# Other
[antiz_fr]
web01a.rc branch=dev
web01b.rc branch=dev
Expand Down
4 changes: 2 additions & 2 deletions Ansible/playbooks/backup_lxc_containers.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: "Backup lxc containers"
hosts: bare
- name: "Backup LXC containers"
hosts: lxc
become: true
roles:
- role: "backup_lxc_containers"
6 changes: 6 additions & 0 deletions Ansible/playbooks/backup_qemu_vms.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: "Backup Qemu VMs"
hosts: qemu
become: true
roles:
- role: "backup_qemu_vms"
14 changes: 14 additions & 0 deletions Ansible/roles/backup_qemu_vms/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Backup Qemu VMs

Backup all qemu virtual machines.

## Variables

The following variable is defined in `defaults/main.yml`:

- backup_retention: `3` (numbers of backups to keep).

The following variables are defined in `vars/main.yml`:

- source_dir: `/data/qemu/vms/` (directory containing the qemu vms to backup).
- backup_base_dir: `/backup/qemu/` (base directory to store backups).
5 changes: 5 additions & 0 deletions Ansible/roles/backup_qemu_vms/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#SPDX-License-Identifier: MIT-0
---
# defaults file for backup_qemu_vms

backup_retention: 3
3 changes: 3 additions & 0 deletions Ansible/roles/backup_qemu_vms/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#SPDX-License-Identifier: MIT-0
---
# handlers file for backup_qemu_vms
35 changes: 35 additions & 0 deletions Ansible/roles/backup_qemu_vms/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#SPDX-License-Identifier: MIT-0
galaxy_info:
author: your name
description: your role description
company: your company (optional)

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)

min_ansible_version: 2.2

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
40 changes: 40 additions & 0 deletions Ansible/roles/backup_qemu_vms/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#SPDX-License-Identifier: MIT-0
---
# tasks file for backup_qemu_vms

- name: "Create backup directory"
ansible.builtin.file:
path: "{{ backup_base_dir }}{{ ansible_facts['date_time']['date'] }}"
state: directory
mode: "0750"

- name: "Backup qemu vms via RSYNC" # noqa: command-instead-of-module
ansible.builtin.shell:
cmd: rsync -aAXHv --numeric-ids --delete "{{ source_dir }}" "{{ ansible_facts['date_time']['date'] }}"
changed_when: true
args:
chdir: "{{ backup_base_dir }}"

- name: "Get backup directories list"
ansible.builtin.find:
paths: "{{ backup_base_dir }}"
file_type: directory
register: list_backup_dirs

- name: "Delete old backup directories"
ansible.builtin.file:
path: "{{ item.path }}"
state: absent
loop: "{{ (list_backup_dirs.files | sort(attribute='ctime'))[:-backup_retention] }}"
when: list_backup_dirs.files | length > backup_retention

- name: "List backup directories"
ansible.builtin.shell:
cmd: ls -ltrh "{{ backup_base_dir }}"
register: ls_backup_dirs
changed_when: false

- name: "Show backup directories"
ansible.builtin.debug:
msg: "{{ ls_backup_dirs.stdout_lines }}"
when: ls_backup_dirs.stdout_lines | length > 0
3 changes: 3 additions & 0 deletions Ansible/roles/backup_qemu_vms/tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#SPDX-License-Identifier: MIT-0
localhost

6 changes: 6 additions & 0 deletions Ansible/roles/backup_qemu_vms/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#SPDX-License-Identifier: MIT-0
---
- hosts: localhost
remote_user: root
roles:
- backup_qemu_vms
6 changes: 6 additions & 0 deletions Ansible/roles/backup_qemu_vms/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#SPDX-License-Identifier: MIT-0
---
# vars file for backup_qemu_vms

source_dir: "/data/qemu/vms"
backup_base_dir: "/backup/qemu/"
Loading