Backups: Add backup host config
This commit is contained in:
parent
75c04207b6
commit
1c617917e6
68
ansible/plays/backup.yaml
Normal file
68
ansible/plays/backup.yaml
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
- name: Setup Infra Meta Host
|
||||||
|
hosts: backup.unruhig.eu
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: Create user [backup]
|
||||||
|
become: true
|
||||||
|
ansible.builtin.user:
|
||||||
|
name: backup
|
||||||
|
comment: Used for receiving borg backups
|
||||||
|
shell: /bin/bash
|
||||||
|
create_home: true
|
||||||
|
state: present
|
||||||
|
generate_ssh_key: true
|
||||||
|
ssh_key_type: "ed25519"
|
||||||
|
ssh_key_file: ".ssh/storagebox"
|
||||||
|
- name: Create mount directory
|
||||||
|
become: true
|
||||||
|
become_user: backup
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "/home/backup/storagebox"
|
||||||
|
state: directory
|
||||||
|
- name: Create systemd user config directory
|
||||||
|
become: true
|
||||||
|
become_user: backup
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "/home/backup/.config/systemd/user"
|
||||||
|
state: directory
|
||||||
|
- name: Check if user is lingering
|
||||||
|
become: true
|
||||||
|
stat:
|
||||||
|
path: "/var/lib/systemd/linger/backup"
|
||||||
|
register: user_lingering
|
||||||
|
- name: Enable lingering for user if needed
|
||||||
|
become: true
|
||||||
|
command: "loginctl enable-linger backup"
|
||||||
|
when:
|
||||||
|
- not user_lingering.stat.exists
|
||||||
|
- name: Create mount unit
|
||||||
|
become: true
|
||||||
|
become_user: backup
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: mount-storagebox.mount.j2
|
||||||
|
dest: /home/backup/.config/systemd/user/var-home-backup-storagebox.mount
|
||||||
|
- name: Create automount unit
|
||||||
|
become: true
|
||||||
|
become_user: backup
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: mount-storagebox.automount.j2
|
||||||
|
dest: /home/backup/.config/systemd/user/var-home-backup-storagebox.automount
|
||||||
|
- name: Start storagebox Mount Service
|
||||||
|
become: true
|
||||||
|
become_user: backup
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: var-home-backup-storagebox.mount
|
||||||
|
state: started
|
||||||
|
enabled: true
|
||||||
|
daemon_reload: true
|
||||||
|
scope: user
|
||||||
|
- name: enable storagebox automount Mount Unit
|
||||||
|
become: true
|
||||||
|
become_user: backup
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: var-home-backup-storagebox.automount
|
||||||
|
enabled: true
|
||||||
|
scope: user
|
||||||
|
|
||||||
|
|
||||||
|
# vim: ft=yaml.ansible
|
8
ansible/plays/templates/mount-storagebox.automount.j2
Normal file
8
ansible/plays/templates/mount-storagebox.automount.j2
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=storagebox automount
|
||||||
|
|
||||||
|
[Automount]
|
||||||
|
Where=/var/home/backup/storagebox
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
14
ansible/plays/templates/mount-storagebox.mount.j2
Normal file
14
ansible/plays/templates/mount-storagebox.mount.j2
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Mount storagebox with sshfs
|
||||||
|
After=network-online.target
|
||||||
|
Wants=network-online.target
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=default.target
|
||||||
|
|
||||||
|
[Mount]
|
||||||
|
What=u309229-sub6@u309229.your-storagebox.de:
|
||||||
|
Where=/var/home/backup/storagebox
|
||||||
|
Type=fuse.sshfs
|
||||||
|
Options=_netdev,reconnect,delay_connect,ServerAliveInterval=30,ServerAliveCountMax=5,x-systemd.automount,Port=23,IdentityFile=/var/home/backup/.ssh/storagebox
|
||||||
|
TimeoutSec=60
|
Loading…
Reference in New Issue
Block a user