Hetzner support

This commit is contained in:
Dieter Verhelst 2018-01-11 23:21:43 +01:00
parent 7b080ece6e
commit 4e2f4bf3fe
3 changed files with 36 additions and 17 deletions

View file

@ -37,12 +37,12 @@
when: item.type == 'normal'
with_items: "{{ borgbackup_servers }}"
# rsync.net has no python, so we can only use raw to manage ssh keys - workaround with local tmp file
- name: client | get rsync.net authorized_keys file
raw: scp {{ item.user }}@{{ item.fqdn }}:.ssh/authorized_keys /tmp/rsync.net-{{ item.fqdn }}-authkeys
# rsync.net and hetzner have no python, so we can only use raw to manage ssh keys - workaround with local tmp file
- name: client | get authorized_keys file
raw: scp {{ item.user }}@{{ item.fqdn }}:.ssh/authorized_keys /tmp/authkeys-{{ item.type }}-{{ item.fqdn }}-authkeys
delegate_to: localhost
become: no
when: item.type == 'rsync.net'
when: item.type in ['rsync.net','hetzner']
with_items: "{{ borgbackup_servers }}"
changed_when: false
@ -51,7 +51,7 @@
user: "{{ ansible_user_id }}"
key: "{{ sshkey.stdout }}"
key_options: 'command="cd {{ item.pool }}/{{ inventory_hostname }};/usr/local/bin/borg1 serve {% if borgbackup_appendonly %}--append-only {% endif %} --restrict-to-path {{ item.pool }}/{{ inventory_hostname }}",no-port-forwarding,no-X11-forwarding,no-pty,no-agent-forwarding,no-user-rc'
path: "/tmp/rsync.net-{{ item.fqdn }}-authkeys"
path: "/tmp/authkeys-{{ item.type }}-{{ item.fqdn }}-authkeys"
manage_dir: no
delegate_to: localhost
become: no
@ -59,16 +59,28 @@
with_items: "{{ borgbackup_servers }}"
register: authkeys
- name: client | upload local authorized_keys to rsync.net
raw: scp /tmp/rsync.net-{{ item.fqdn }}-authkeys {{ item.user }}@{{ item.fqdn }}:.ssh/authorized_keys
- name: client | modify local hetzner authorized_keys
authorized_key:
user: "{{ ansible_user_id }}"
key: "{{ sshkey.stdout }}"
path: "/tmp/authkeys-{{ item.type }}-{{ item.fqdn }}-authkeys"
manage_dir: no
delegate_to: localhost
become: no
when: item.type == 'rsync.net' and authkeys.changed
when: item.type == 'hetzner'
with_items: "{{ borgbackup_servers }}"
register: authkeys
- name: client | upload local authorized_keys to rsync.net / hetzner
raw: scp /tmp/authkeys-{{ item.type }}-{{ item.fqdn }}-authkeys {{ item.user }}@{{ item.fqdn }}:.ssh/authorized_keys
delegate_to: localhost
become: no
when: item.type in ['rsync.net','hetzner'] and authkeys.changed
with_items: "{{ borgbackup_servers }}"
- name: client | remove tmp authorized_keys files
file:
path: /tmp/rsync.net-{{ item.fqdn }}-authkeys
path: /tmp/authkeys-{{ item.type }}-{{ item.fqdn }}-authkeys
state: absent
delegate_to: localhost
become: no