diff --git a/inventory/group_vars/all/vars.yml b/inventory/group_vars/all/vars.yml index f7d9db91..00359b3f 100644 --- a/inventory/group_vars/all/vars.yml +++ b/inventory/group_vars/all/vars.yml @@ -3,3 +3,8 @@ pve_api_url: "https://jupiter.renner.uno:8006" pve_user: "root@pam" pve_token_id: "ansible" ansible_python_interpreter: /usr/bin/python3 + +# SSH Public Keys for Cloud-Init +common_ssh_public_keys: | + ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPzFNBP3bq2m/6JqDqod9w+FP/uxXxHMolqhq3Ojflr1 krenner@fortress + ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBmeUbEJm00nNwYn4HdGAU4ktcSy1VGF9s8Og3zaQnGe ansible-runner@ci diff --git a/plays/create-template.yml b/plays/create-template.yml index 8dce0319..86c8b724 100644 --- a/plays/create-template.yml +++ b/plays/create-template.yml @@ -49,9 +49,7 @@ - name: Create temp ssh key file copy: - content: | - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPzFNBP3bq2m/6JqDqod9w+FP/uxXxHMolqhq3Ojflr1 krenner@fortress - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBmeUbEJm00nNwYn4HdGAU4ktcSy1VGF9s8Og3zaQnGe ansible-runner@ci + content: "{{ common_ssh_public_keys }}" dest: /tmp/sshkeys.pub - name: Configure VM Hardware diff --git a/plays/setup-caddy-ha.yml b/plays/setup-caddy-ha.yml index 33d2dc7e..559a8a9c 100644 --- a/plays/setup-caddy-ha.yml +++ b/plays/setup-caddy-ha.yml @@ -33,6 +33,24 @@ when: vm_check.rc != 0 delegate_to: "{{ target_node }}" + - name: Copy SSH Keys to Proxmox + copy: + content: "{{ common_ssh_public_keys }}" + dest: "/tmp/caddy_ssh_keys.pub" + mode: '0644' + delegate_to: "{{ target_node }}" + + - name: Apply SSH Keys to VM + command: "qm set {{ new_vmid }} --sshkeys /tmp/caddy_ssh_keys.pub" + delegate_to: "{{ target_node }}" + changed_when: false + + - name: Reboot VM if running to apply keys + command: "qm reboot {{ new_vmid }}" + when: vm_check.rc == 0 and "running" in vm_check.stdout + delegate_to: "{{ target_node }}" + changed_when: true + - name: Ensure VM is started command: "qm start {{ new_vmid }}" when: vm_check.rc != 0 or "stopped" in vm_check.stdout