From d81091f77b5735eff1169c45dbc2e56bedc32277 Mon Sep 17 00:00:00 2001
From: nd <git@notandy.de>
Date: Fri, 2 Sep 2022 01:09:33 +0200
Subject: [PATCH] add option to copy keys from root

---
 defaults/main.yml |  2 ++
 tasks/main.yml    | 12 ++++++++++++
 2 files changed, 14 insertions(+)
 create mode 100644 defaults/main.yml

diff --git a/defaults/main.yml b/defaults/main.yml
new file mode 100644
index 0000000..ce68c33
--- /dev/null
+++ b/defaults/main.yml
@@ -0,0 +1,2 @@
+ssh_initramfs:
+  copy_from_root: false
diff --git a/tasks/main.yml b/tasks/main.yml
index 7b2ea30..beb06cc 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -12,6 +12,7 @@
     group: root
 
 - name: write authorized_keys file for dropbear-initramfs
+  when: not ssh_initramfs.copy_from_root
   notify: update initramfs
   template:
     src: authorized_keys.j2
@@ -19,3 +20,14 @@
     mode: 0644
     owner: root
     group: root
+
+- name: copy authorized_keys file from root user to dropbear-initramfs
+  when: ssh_initramfs.copy_from_root
+  notify: update initramfs
+  copy:
+    src: /root/.ssh/authorized_keys
+    remote_src: true
+    dest: /etc/dropbear-initramfs/authorized_keys
+    mode: 0644
+    owner: root
+    group: root
-- 
GitLab