From 7f39e408e3804922433514c0dc665723e6ae312e Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Wed, 29 Aug 2018 13:28:24 +0100 Subject: [PATCH] MNAIO: Inject the host ssh public key into the image To allow a downloaded set of file-backed images to be used on another host, the new host's public ssh key needs to be injected into the VM disks so that ansible is able to connect to it and complete the rest of the preparation. Change-Id: I6b9b5efb88283417c15f74f40cfb91943bb8774d --- multi-node-aio/playbooks/deploy-vms.yml | 16 ++++++++++++++++ multi-node-aio/playbooks/vars/ubuntu.yml | 1 + 2 files changed, 17 insertions(+) diff --git a/multi-node-aio/playbooks/deploy-vms.yml b/multi-node-aio/playbooks/deploy-vms.yml index 04ae039f..cfec64f4 100644 --- a/multi-node-aio/playbooks/deploy-vms.yml +++ b/multi-node-aio/playbooks/deploy-vms.yml @@ -118,6 +118,22 @@ - hostvars[item]['server_vm'] | default(false) | bool with_items: "{{ groups['pxe_servers'] }}" + # Note (odyssey4me): + # This will only work on a host which has + # libguestfs >= 1.35.2 and >= 1.34.1 + # Ubuntu bionic works, but xenial does not (even with UCA). + # ref: https://bugs.launchpad.net/ubuntu/+source/libguestfs/+bug/1615337. + - name: Inject the host ssh key into the VM disk image + command: >- + virt-sysprep + --enable customize + --ssh-inject root:file:/root/.ssh/id_rsa.pub + --add {{ _virt_pools.pools.default.path | default('/data/images') }}/{{ hostvars[item]['server_hostname'] }}.img + when: + - vm_use_snapshot | bool + - hostvars[item]['server_vm'] | default(false) | bool + with_items: "{{ groups['pxe_servers'] }}" + - name: Wait for guest capabilities to appear command: "virsh capabilities" register: virsh_caps diff --git a/multi-node-aio/playbooks/vars/ubuntu.yml b/multi-node-aio/playbooks/vars/ubuntu.yml index 8f918056..b107ed26 100644 --- a/multi-node-aio/playbooks/vars/ubuntu.yml +++ b/multi-node-aio/playbooks/vars/ubuntu.yml @@ -34,6 +34,7 @@ mnaio_host_distro_packages: - bridge-utils - ifenslave - iptables-persistent + - libguestfs-tools - libvirt-bin - lvm2 - ntp