feat: Add SSH key management for Proxmox VMs and update template playbook
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user