6
votes

I have created an environment with several Linux hosts based on KVM. I'm using virt-manager to create different VMs and I'm using Linux bridges to create connectivity between VMs in different hosts.

Now, I would like to have an auto-configuration server so that my VMs can auto-configure their name, IP address, run some scripts, etc based on a unique id that each of them has. Is it possible to replicate a sort of cloud-init setup in a non-openstack environment?

I have tried using cloud-init the datasource NoCloud in the following way. First, I have installed cloud-init in the VM and configured cloud.cfg:

datasource:
  NoCloud
datasource_list: [ NoCloud ]
disable_ec2_metadata: True

Then, I have created a user-data file and meta-data file with the following content:

user-data:

#cloud-config
hostname: prueba
password: passw0rd
chpasswd: { expire: False }
ssh_pwauth: True

meta-data:

instance-id: iid-local01
local-hostname: prueba

Then, I have generated an iso file:

genisoimage  -output seed.iso -volid cidata -joliet -rock user-data meta-data

Finally, I have attached the disk to the VM and started it. This is the relevant part of the XML:

<disk type='file' device='disk'>
  <driver name='qemu' type='raw'/>
  <source file='/opt/images/seed.iso'/>
  <backingStore/>
  <target dev='vdb' bus='virtio'/>
  <alias name='virtio-disk1'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</disk>

When the VM starts, it says:

2015-05-12 12:12:40,394 - util.py[WARNING]: Getting data from <class 'cloudinit.sources.DataSourceNoCloud.DataSourceNoCloudNet'> failed
 * Stopping Read required files in advance (for other mountpoints)                           [ OK ]
 * Stopping Read required files in advance (for other mountpoints)                           [ OK ]
 * Stopping Read required files in advance (for other mountpoints)                           [ OK ]
2015-05-12 12:12:48,808 - url_helper.py[WARNING]: Calling 'http://169.254.169.254/2009-04-04/meta-data/instance-id' failed [3/120s]: request error [HTTPConnectionPool(host='169.254.169.254', port=80): Max retries exceeded with url: /2009-04-04/meta-data/instance-id (Caused by <class 'socket.error'>: [Errno 113] No route to host)]

Any suggestions on how to make it work?

1
Data sources in /etc/cloud/cloud.cfg didn't work properly for me. I've run 'dpkg-reconfigure cloud-init' and specified the NoCloud datasource. The process for generating the image with the user-data and meta-data was also a bit different: truncate --size 2M init.img mkfs.vfat -n cidata init.img mcopy -oi init1.img user-data meta-data ::garciadeblas
I inserted a new disk and the result in XML libvirt domain descriptor of the VM was like this: <disk type='file' device='disk'> <driver name='qemu' type='raw' cache='none'/> <source file='/images/init.img'/> <target dev='vdb' bus='virtio'/> </disk>garciadeblas
With the upper config, I can make some cloud config commands work properly (setting password and hostname), while others such as runcmd or write_files do not work yetgarciadeblas

1 Answers

2
votes

Is it possible to replicate a sort of cloud-init setup in a non-openstack environment?

Sure.

Cloud-init does not require a network metadata service (like that provided by EC2 and OpenStack) in order to operate. It will happily read configuration information from a local CD-ROM device; see, for example, the "Loggin in to your Atomic machine" section of this document, which described how to create the necessary filesystem.

This is documented here in the cloud-init documentation.