forked from infra/ansible
copr-be: provide ssh key in config.iso drive for libvirt
This is the way to tell the instance's cloud-init what is the (currently rotated) correct ssh pub key.
This commit is contained in:
parent
5c07c25ce1
commit
736b083568
1 changed files with 19 additions and 3 deletions
|
|
@ -200,6 +200,21 @@ class LibvirtSpawner:
|
|||
"""
|
||||
|
||||
todo_files = copy.copy(self.config_files)
|
||||
|
||||
# Make sure the machine trusts our buildsys.pub key (via cloud-init).
|
||||
with open("/var/lib/resallocserver/provision/files/buildsys.pub", "r",
|
||||
encoding='utf-8') as file:
|
||||
public_key = file.read()
|
||||
|
||||
user_data = f"""\n
|
||||
#cloud-config
|
||||
ssh_authorized_keys:
|
||||
- {public_key}
|
||||
"""
|
||||
todo_files.append(ConfigFile('user-data', user_data))
|
||||
meta_data = "instance-id: {self.vm_name}\n"
|
||||
todo_files.append(ConfigFile('meta-data', meta_data))
|
||||
|
||||
startup_script = self.get_startup_script()
|
||||
if startup_script:
|
||||
todo_files.append(startup_script)
|
||||
|
|
@ -216,9 +231,10 @@ class LibvirtSpawner:
|
|||
|
||||
image = os.path.join(self.workdir, 'config.iso')
|
||||
|
||||
# The 'eimg_config' label is not important, we search for /dev/sr0
|
||||
# anyway.
|
||||
if self.call(['mkisofs', '-o', image, '-V', 'eimg_config', '-r', '-J',
|
||||
# The 'cidata' label is important, otherwise cloud-init can't take the
|
||||
# image as NoCloud drive. Other files shouldn't be a problem for cloud
|
||||
# init.
|
||||
if self.call(['mkisofs', '-o', image, '-V', 'cidata', '-r', '-J',
|
||||
'--quiet', config_dir]) != 0:
|
||||
raise Exception("mkisofs failed")
|
||||
return image
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue