Now that we’ve got that covered, let’s look deeper into a very cool feature – the ability to customize the instance and automate its startup and configuration. For example, at instance creation time you can specify a snappy application to be installed. cloud-init is what allows you to do this, and it is installed inside the Snappy image. cloud-init receives this information from the user in the form of ‘user-data’.
One of the formats that can be fed to cloud-init is called ‘cloud-config’. cloud-config is yaml formatted data that is interpreted and acted on by cloud-init. For Snappy, we’ve added a couple specific configuration values. Those are included under the top level ‘snappy’.
When running inside snappy, cloud-init still provides many of the features it provides on traditional instances. Some useful configuration entries:
Some cloud-init config modules are simply not going to work. For example, traditional packages will not be installed by ‘apt’ as the root filesystem is read-only.
Its always easiest to start from a working example. Below is one that demonstrates the usage of the config options listed above. Please note that user data intended to be consumed as cloud-config must contain the first line ‘#cloud-config‘.
– content: |
echo “==== Hello Snappy! It is now $(date -R) ====”
– /writable/greet | tee /run/hello.log
Follow yesterday’s blog post to get a functional tool. Then, save the example config file above to a file, and launch you’re instance with it.
$ uvt-kvm create –wait –add-user-data=my-config.yaml snappy1 release=devel
Our user-data instructed cloud-init to do a number of different things. First, it wrote a file via ‘write_files’ to a writable space on disk, and then executed that file with ‘runcmd’. Lets verify that was done:
$ uvt-kvm ssh snappy1 cat /run/hello.log
==== Hello Snappy! It is now Thu, 11 Dec 2014 18:16:34 +0000 ====
It also instructed cloud-init to install the Snappy ‘xkcd-webserver’ application.
$ uvt-kvm ssh snappy1 snappy versions
Part Tag Installed Available Fingerprint Active
ubuntu-core edge 141 – 7f068cb4fa876c *
xkcd-webserver edge 0.3.1 – 3a9152b8bff494 *
There we can see that xkcd-webserver was installed, lets check that it is running:
$ uvt-kvm ip snappy1
$ wget -O – –quiet http://192.168.122.80/ | grep <title>
The same user-data listed above also works on Microsoft Azure. Follow the instructions for setting up the azure command line tools, and then launch the instance with and provide the ‘–custom-data‘ flag. A full command line might look like:
$ azure vm create snappy-test $imgid ubuntu \
–location “North Europe” –no-ssh-password \
–ssh-cert ~/.ssh/azure_pub.pem –ssh \
Have fun playing with cloud-init!
From home control to drones, robots and industrial systems, Ubuntu Core and Snaps provide robust security, app stores and reliable updates for all your IoT devices.
Robots are an increasingly important part of our lives, in more ways than we realise. I’m not talking just about Roombas, or the toy robots that inhabit the wish lists of the world’s children (and the young at heart). Robots are…
A couple of weeks ago, we talked about snap security, taking a journey through the eyes of a developer and handing over to a user who wants to install applications from the Snap Store. We discussed concepts like application confinement,…
Canonical today published Ubuntu Core 18, bringing the popular Ubuntu 18.04 LTS to high-security embedded devices. “Dell has been working closely with Canonical over the past three years to certify Ubuntu Core on all our Edge Gateway…