69 lines
2.0 KiB
YAML
69 lines
2.0 KiB
YAML
|
- 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
|