6

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?

3
  • 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 :: Dec 1, 2015 at 18:02
  • 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> Dec 1, 2015 at 18:02
  • 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 yet Dec 1, 2015 at 18:02

1 Answer 1

2

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.

4
  • Thanks for your suggestion. I have tried to follow the steps. I have edited my question to include all the steps, but I cannot make it work. May 12, 2015 at 10:19
  • From the docs, it's not clear the configuration in the virtual machine. How should I configure cloud-init in the VM? Jun 11, 2015 at 8:32
  • I don't understand your question. From your answer posted 5/14 it sounds like you were able to get things working. At this point you may want to open a new question...
    – larsks
    Jun 11, 2015 at 13:10
  • I configured /etc/cloud/cloud.cfg file in the VM, but it didn't work. I ran "dpkg-reconfigure cloud-init' and specified the NoCloud datasource, and it partially worked." Some keywords work (setting password and hostname). Others do not (e.g. runcmd, write_files). So is there any configuration missing in the VM? Are there commands that cannot be used in the NoCloud setup? Feb 29, 2016 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.