From 9b84a7f3eaa195247ce0886a5e7dbbbd7af25bd2 Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Wed, 30 Nov 2022 14:55:57 +0100 Subject: [PATCH] make unlock user aware --- hetzner/autoinstall/tasks/unlock.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hetzner/autoinstall/tasks/unlock.yml b/hetzner/autoinstall/tasks/unlock.yml index a01fc1a..2280149 100644 --- a/hetzner/autoinstall/tasks/unlock.yml +++ b/hetzner/autoinstall/tasks/unlock.yml @@ -1,5 +1,6 @@ - name: send unlock command raw: "printf '{{ autoinstall_disk_encryption_secret }}' | cryptroot-unlock" + - name: wait for boot wait_for: delay: 5 @@ -8,3 +9,19 @@ search_regex: OpenSSH|dropbear timeout: 300 delegate_to: localhost + +- name: test ssh connection with {{ ansible_user }} + shell: | + ssh -p{{ ansible_ssh_port|default(22) }} \ + -i {{ ansible_ssh_private_key_file }} \ + -oStrictHostkeyChecking=no \ + -oBatchMode=yes \ + {{ ansible_user }}@{{ ansible_ssh_host }} echo test + register: connection_test + ignore_errors: yes + changed_when: False + +- name: set ansible_user + set_fact: + ansible_ssh_user: "{{ bootstrap_user|default('root') }}" + when: connection_test is succeeded