aboutsummaryrefslogtreecommitdiffstats
path: root/tasks/client_setup.yml
diff options
context:
space:
mode:
Diffstat (limited to 'tasks/client_setup.yml')
-rw-r--r--tasks/client_setup.yml21
1 files changed, 14 insertions, 7 deletions
diff --git a/tasks/client_setup.yml b/tasks/client_setup.yml
index 5d162ed..ab09926 100644
--- a/tasks/client_setup.yml
+++ b/tasks/client_setup.yml
@@ -39,10 +39,7 @@
- name: Compute SSH key path
ansible.builtin.set_fact:
borg_ssh_key_path: >-
- {{ borg_client_user_home }}/.ssh/id_{{ borg_ssh_key_type }}
- {%- if borg_ssh_key_per_repo -%}
- _borgbackup_{{ borg_ssh_key_identifier }}
- {%- endif -%}
+ {{ borg_client_user_home }}/.ssh/id_{{ borg_ssh_key_type }}{%- if borg_ssh_key_per_repo -%}_borgbackup_{{ borg_ssh_key_identifier }}{%- endif -%}
- name: Create SSH Directory
ansible.builtin.file:
@@ -73,6 +70,16 @@
become: true
register: ssh_key
+- name: Normalize SSH public key for matching
+ ansible.builtin.set_fact:
+ ssh_public_key: "{{ ssh_key.public_key | trim }}"
+ ssh_public_key_material: >-
+ {{
+ (ssh_key.public_key | trim)
+ | regex_search('^[^ ]+ [^ ]+')
+ | default(ssh_key.public_key | trim)
+ }}
+
- name: Ensure authorized_keys file exists on borg server
ansible.builtin.file:
path: "{{ borg_server_user_home }}/.ssh/authorized_keys"
@@ -97,7 +104,7 @@
existing_line: >-
{{
(auth_keys_content.content | b64decode).splitlines()
- | select("search", ssh_key.public_key | trim | regex_escape)
+ | select("search", ssh_public_key_material | regex_escape)
| first
| default("")
}}
@@ -149,11 +156,11 @@
- name: Update authorized_keys entry for this host
ansible.builtin.lineinfile:
path: "{{ borg_server_user_home }}/.ssh/authorized_keys"
- search_string: "{{ ssh_key.public_key | trim }}"
+ search_string: "{{ ssh_public_key_material }}"
line: >-
restrict,command="borg serve{{ " --append-only" if borg_mode_append_only }}{{ " --storage-quota " ~ borg_storage_quota if borg_storage_quota }}
{{ all_repos | map('regex_replace', '^', '--restrict-to-repository ') | join(' ') }}"
- {{ ssh_key.public_key | trim }} {{ borg_client_user }}@{{ inventory_hostname }}
+ {{ ssh_public_key }} {{ borg_client_user }}@{{ inventory_hostname }}
state: present
become: true
delegate_to: "{{ borg_server_host }}"