summaryrefslogtreecommitdiff
path: root/ansible/roles/borg-rsyncnet/tasks/borg-init.yml
diff options
context:
space:
mode:
Diffstat (limited to 'ansible/roles/borg-rsyncnet/tasks/borg-init.yml')
-rw-r--r--ansible/roles/borg-rsyncnet/tasks/borg-init.yml67
1 files changed, 67 insertions, 0 deletions
diff --git a/ansible/roles/borg-rsyncnet/tasks/borg-init.yml b/ansible/roles/borg-rsyncnet/tasks/borg-init.yml
new file mode 100644
index 0000000..9b6980d
--- /dev/null
+++ b/ansible/roles/borg-rsyncnet/tasks/borg-init.yml
@@ -0,0 +1,67 @@
+# - debug: var=client.value
+
+- with_items: "{{ client.value.repos }}"
+ assert:
+ that:
+ - "item in borg__passphrases[client.key]"
+ fail_msg: "{{ item }} is missing from borg-secrets.yml"
+ success_msg: ""
+
+- set_fact:
+ ssh_key: "{{ client.value.ssh_key_path if client.value.ssh_key_path is defined else default_file_path }}"
+ vars:
+ default_file_path: "files/borg/{{ client.key }}/ssh-key"
+# - debug: var=ssh_key
+
+- name: mkdir client dir
+ loop: "{{ client.value.repos | dict2items }}"
+ local_action: command ssh {{ ansible_user }}@{{ inventory_hostname }} mkdir -p "{{ borg_rsyncnet__home }}/{{ client.key }}"
+
+- name: ls client dir
+ local_action: command {{ ssh }} mkdir -p "{{ borg_rsyncnet__home }}/{{ client.key }}"; ls "{{ borg_rsyncnet__home }}/{{ client.key }}"
+ register: dirs
+ changed_when: False
+# - debug: var=dirs
+
+# This doesn't work as the ssh command doesn't allow sending
+# environment variables and borg the passphrase to be sent via env
+# variables.
+# - name: borg init
+# loop: "{{ client.value.repos | dict2items }}"
+# loop_control:
+# label: "{{ item.key }}"
+# local_action: command {{ ssh }} /usr/local/bin/borg1/borg1 init --encryption repokey "{{ path }}"
+# environment:
+# BORG_PASSPHRASE: "{{ borg__passphrases[client.key][item.key] }}"
+# when: item.key not in dirs.stdout_lines
+# vars:
+# remote: "{{ ansible_user }}@{{ inventory_hostname }}"
+# path: "{{ borg_rsyncnet__home }}/{{ client.key }}/{{ item.key }}"
+
+- name: borg init
+ loop: "{{ client.value.repos | dict2items }}"
+ loop_control:
+ label: "{{ item.key }}"
+ local_action: command borg init --encryption repokey "{{ remote }}:{{ path }}"
+ environment:
+ BORG_PASSPHRASE: "{{ borg__passphrases[client.key][item.key] }}"
+ when: item.key not in dirs.stdout_lines
+ vars:
+ remote: "{{ ansible_user }}@{{ inventory_hostname }}"
+ path: "{{ borg_rsyncnet__home }}/{{ client.key }}/{{ item.key }}"
+
+- local_action:
+ module: stat
+ path: "{{ ssh_key }}"
+ register: ssh_key_stat
+
+- local_action:
+ module: file
+ path: "{{ (playbook_dir + '/' + ssh_key) | dirname }}"
+ state: directory
+ become: no
+
+- name: Generating SSH key
+ local_action: command ssh-keygen -t ed25519 -N "" -f "{{ ssh_key }}" -C "borg@{{ client.key }}"
+ when: not ssh_key_stat.stat.exists
+ become: no