Create SSH config for borg providers

This commit is contained in:
phil 2023-05-08 11:21:21 +02:00
parent fbdce3166f
commit f4152f9a5e
5 changed files with 23 additions and 14 deletions

View file

@ -3,7 +3,6 @@
ansible.builtin.slurp:
src: "{{ borg_ssh_key_file_path }}.pub"
register: ssh_key
check_mode: true
- name: Add key to borgbase
adhawkins.borgbase.borgbase_ssh:

View file

@ -9,11 +9,12 @@
- name: Setup borgbase backup
ansible.builtin.import_tasks: borgbase.yml
when: borgbase is defined and borgbase
when: "'borgbase' in borg_providers"
tags: borgbase
- name: Setup Hetzner storagebox backup
ansible.builtin.import_tasks: storagebox.yml
when: "'hetzner' in borg_providers"
tags: storagebox
- name: Setup borg

View file

@ -22,10 +22,14 @@
owner: "{{ borg_user }}"
group: "{{ borg_group }}"
- name: "SSH | Insert borgbase configuration"
- name: "SSH | Ensure configuration exists"
ansible.builtin.file:
path: .ssh/config
state: touch
mode: "0644"
- name: "SSH | Create SSH configuration"
ansible.builtin.blockinfile:
path: "{{ borg_user_ssh_config_path }}"
path: .ssh/config
marker: "### {mark} ANSIBLE MANAGED BLOCK"
block: |
Host *.repo.borgbase.com
IdentityFile {{ borg_ssh_key_file_path }}
block: "{{ lookup('template', 'ssh_config.j2') }}"

View file

@ -1,12 +1,10 @@
---
- name: "Storagebox | Read key from file"
ansible.builtin.slurp:
src: "{{ borg_ssh_key_file_path }}.pub"
ansible.builtin.command:
cmd: "cat {{ borg_ssh_key_file_path }}.pub"
register: ssh_key
check_mode: true
- name: "Storagebox | Copy key to Hetzner"
ansible.posix.authorized_key:
user: "{{ hetzner_storagebox_user }}"
key: "{{ (ssh_key.content | b64decode) }}"
delegate_to: "{{ hetzner_storagebox }}"
ansible.builtin.command:
cmd: "echo {{ ssh_key.stdout_lines }} | ssh {{ hetzner_storagebox.user }}@{{ hetzner_storagebox.server }} -p {{ hetzner_storagebox.port }} install-ssh-key"
delegate_to: localhost

7
templates/ssh_config.j2 Normal file
View file

@ -0,0 +1,7 @@
{% if 'borgbase' in borg_providers %}
Host *.repo.borgbase.com
IdentityFile {{ borg_ssh_key_file_path }}
{% elif 'hetzner' in borg_providers %}
Host *.your-storagebox.de
IdentityFile /root/.ssh/borgbackup
{% endif %}