mirror of
https://github.com/borgbase/ansible-role-borgbackup.git
synced 2025-07-24 13:48:08 +02:00
49 lines
1.7 KiB
YAML
49 lines
1.7 KiB
YAML
---
|
|
- name: Create ssh-key (if neeeded) for {{ borgbackup_user }}
|
|
when:
|
|
- backup_id_rsa is not defined or backup_id_rsa | length == 0
|
|
tags:
|
|
- install_backup
|
|
block:
|
|
- name: Ensire directory exist
|
|
ansible.builtin.file:
|
|
path: "{{ backup_user_info.home }}/.ssh/"
|
|
state: directory
|
|
mode: "0700"
|
|
owner: "{{ borgbackup_user }}"
|
|
group: "{{ borgbackup_group }}"
|
|
|
|
- name: Generate an OpenSSH keypair with the default values (4096 bits, rsa)
|
|
community.crypto.openssh_keypair:
|
|
path: "{{ backup_user_info.home }}/.ssh/id_rsa"
|
|
mode: "0600"
|
|
owner: "{{ borgbackup_user }}"
|
|
group: "{{ borgbackup_group }}"
|
|
|
|
- name: Set key permission
|
|
ansible.builtin.file:
|
|
path: "{{ backup_user_info.home }}/.ssh/id_rsa.pub"
|
|
mode: "0644"
|
|
owner: "{{ borgbackup_user }}"
|
|
group: "{{ borgbackup_group }}"
|
|
|
|
- name: Read ssh key
|
|
ansible.builtin.slurp:
|
|
src: "{{ backup_user_info.home }}/.ssh/id_rsa.pub"
|
|
register: backup_local_ssh_key
|
|
|
|
- name: Set authorized key taken from file
|
|
when:
|
|
- borgmatic_initialization_repo is defined and borgmatic_initialization_repo
|
|
ansible.posix.authorized_key:
|
|
# borg_repository: m5vz9gp4@m5vz9gp4.repo.borgbase.com:repo
|
|
# habe thee parts: "username"@"FQDN":"path/to/store/backup", specific:
|
|
# a) user: m5vz9gp4
|
|
# b) fqdn: m5vz9gp4.repo.borgbase.co
|
|
# c) dir: repo
|
|
user: "{{ borg_repository | regex_search('(.*)@', '\\1') | first }}" # part a)
|
|
state: present
|
|
key: "{{ backup_local_ssh_key['content'] | b64decode }}"
|
|
delegate_to: "{{ borg_repository | regex_search('@(.*):', '\\1') | first }}" # part b)
|
|
...
|