Create SSH config for borg providers
This commit is contained in:
parent
fbdce3166f
commit
f4152f9a5e
5 changed files with 23 additions and 14 deletions
|
@ -3,7 +3,6 @@
|
||||||
ansible.builtin.slurp:
|
ansible.builtin.slurp:
|
||||||
src: "{{ borg_ssh_key_file_path }}.pub"
|
src: "{{ borg_ssh_key_file_path }}.pub"
|
||||||
register: ssh_key
|
register: ssh_key
|
||||||
check_mode: true
|
|
||||||
|
|
||||||
- name: Add key to borgbase
|
- name: Add key to borgbase
|
||||||
adhawkins.borgbase.borgbase_ssh:
|
adhawkins.borgbase.borgbase_ssh:
|
||||||
|
|
|
@ -9,11 +9,12 @@
|
||||||
|
|
||||||
- name: Setup borgbase backup
|
- name: Setup borgbase backup
|
||||||
ansible.builtin.import_tasks: borgbase.yml
|
ansible.builtin.import_tasks: borgbase.yml
|
||||||
when: borgbase is defined and borgbase
|
when: "'borgbase' in borg_providers"
|
||||||
tags: borgbase
|
tags: borgbase
|
||||||
|
|
||||||
- name: Setup Hetzner storagebox backup
|
- name: Setup Hetzner storagebox backup
|
||||||
ansible.builtin.import_tasks: storagebox.yml
|
ansible.builtin.import_tasks: storagebox.yml
|
||||||
|
when: "'hetzner' in borg_providers"
|
||||||
tags: storagebox
|
tags: storagebox
|
||||||
|
|
||||||
- name: Setup borg
|
- name: Setup borg
|
||||||
|
|
|
@ -22,10 +22,14 @@
|
||||||
owner: "{{ borg_user }}"
|
owner: "{{ borg_user }}"
|
||||||
group: "{{ borg_group }}"
|
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:
|
ansible.builtin.blockinfile:
|
||||||
path: "{{ borg_user_ssh_config_path }}"
|
path: .ssh/config
|
||||||
marker: "### {mark} ANSIBLE MANAGED BLOCK"
|
marker: "### {mark} ANSIBLE MANAGED BLOCK"
|
||||||
block: |
|
block: "{{ lookup('template', 'ssh_config.j2') }}"
|
||||||
Host *.repo.borgbase.com
|
|
||||||
IdentityFile {{ borg_ssh_key_file_path }}
|
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
---
|
---
|
||||||
- name: "Storagebox | Read key from file"
|
- name: "Storagebox | Read key from file"
|
||||||
ansible.builtin.slurp:
|
ansible.builtin.command:
|
||||||
src: "{{ borg_ssh_key_file_path }}.pub"
|
cmd: "cat {{ borg_ssh_key_file_path }}.pub"
|
||||||
register: ssh_key
|
register: ssh_key
|
||||||
check_mode: true
|
|
||||||
|
|
||||||
- name: "Storagebox | Copy key to Hetzner"
|
- name: "Storagebox | Copy key to Hetzner"
|
||||||
ansible.posix.authorized_key:
|
ansible.builtin.command:
|
||||||
user: "{{ hetzner_storagebox_user }}"
|
cmd: "echo {{ ssh_key.stdout_lines }} | ssh {{ hetzner_storagebox.user }}@{{ hetzner_storagebox.server }} -p {{ hetzner_storagebox.port }} install-ssh-key"
|
||||||
key: "{{ (ssh_key.content | b64decode) }}"
|
delegate_to: localhost
|
||||||
delegate_to: "{{ hetzner_storagebox }}"
|
|
||||||
|
|
7
templates/ssh_config.j2
Normal file
7
templates/ssh_config.j2
Normal 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 %}
|
Loading…
Reference in a new issue