backups/ansible/configure-server.yml

105 lines
2.5 KiB
YAML
Raw Normal View History

---
- hosts: backup_server
tasks:
# - name: install necessary packages
# ansible.builtin.apt:
# name:
# - rsnapshot
# - nfs-common
# state: present
# update_cache: yes
- name: Copy systemd mount file
ansible.builtin.copy:
src: files/systemd-mount.mount
dest: /etc/systemd/system/mnt-syno-InfraBackups.mount
owner: root
group: root
mode: 0644
register: systemd_mount
- name: Reload systemd
ansible.builtin.systemd:
daemon_reload: yes
when: systemd_mount.changed
- name: Start & Enable systemd mount
ansible.builtin.systemd:
name: mnt-syno-InfraBackups.mount
state: started
enabled: yes
when: systemd_mount.changed
- name: Generate ssh key
ansible.builtin.openssh_keypair:
path: /root/.ssh/id_rsa_rsnapshot
type: rsa
size: 4096
state: present
- name: Register ssh public key in variable
slurp:
src: /root/.ssh/id_rsa_rsnapshot.pub
register: rsnapshot_ssh_key_slurp
- name: Set ssh public key in variable
set_fact:
rsnapshot_ssh_key: "{{ rsnapshot_ssh_key_slurp['content'] | b64decode }}"
- name: Copy rsnapshot template file
ansible.builtin.template:
src: files/rsnapshot.conf.j2
dest: /etc/rsnapshot.conf
owner: root
group: root
mode: 0644
register: rsnapshot_conf
tags: rsnapshot
- name: Copy systemd unit files
ansible.builtin.copy:
src: files/{{ item }}
dest: /etc/systemd/system/
owner: root
group: root
mode: 0644
with_items:
- rsnapshot@.service
- rsnapshot-daily.timer
- rsnapshot-weekly.timer
- rsnapshot-monthly.timer
register: rsnapshot_service
- name: Reload systemd
ansible.builtin.systemd:
daemon_reload: yes
when: rsnapshot_service.changed
- name: Enable rsnapshot timers
ansible.builtin.systemd:
name: '{{ item }}'
enabled: yes
with_items:
- rsnapshot-daily.timer
- rsnapshot-weekly.timer
- rsnapshot-monthly.timer
register: rsnapshot_timers
when: rsnapshot_service.changed
- name: Reboot ## IDK how to start a timer
ansible.builtin.reboot:
when: rsnapshot_timers.changed
- hosts: backup_clients
gather_facts: no
vars:
backup_server: backup.lan.k3s.fr
tasks:
- name: Allow ssh from rsnapshot server
authorized_key:
user: root
state: present
key: "{{ hostvars[backup_server]['rsnapshot_ssh_key'] | trim }} root@{{ hostvars[backup_server]['ansible_default_ipv4']['address'] }}"