[ubuntu-cloud] Documentation for cloud-config?

Scott Moser smoser at ubuntu.com
Mon Oct 1 12:51:02 UTC 2012

On Sat, 29 Sep 2012, Dave Hein wrote:

> I've searched quite a bit but can find no sufficient documentation of the
> cloud-init syntax.

The best doc there is is in the source code at doc/examples/.
Almost all config values are documented somewhere in there.

For a specific release, you can look at a tag, or the ubuntu branches such
as lp:ubuntu/precise/cloud-init .

> I'm particularly interested in cloud-config commands that control apt. For
> example, I'd like to tell apt to apply only security updates, but that
> requires setting the apt sources to the subset that contain reliable
> security updates. Looking at the python source code for CloudInit, I can
> see hints that there might be some cloud-init commands to control the apt
> sources, but I can't say for sure.

I think for this specific case, the best thing to do is to add a boothook
that writes whatever you want to /etc/cloud/templates/sources.list.tmpl .
That file will then be rendered to /etc/apt/sources.list during boot
(prior to 'apt-get update', and can contain '$mirror' and '$codename'
references.  See the example in an instance.

In 12.10, you could write this file using the 'files' config syntax also
(which runs pretty much first thing in boot).  See example there at
doc/examples/cloud-config-write-files.txt .

> It seems to me that a full set of the cloud-config commands available to
> users should be documented and published somewhere public. Without that it
> is going to hard to get anyone except ubuntu cloud insiders to use cloud
> init as it was meant to be used.

The doc *is* installed in the package, see /usr/share/doc/cloud-init .
> I've been able to guess some things by looking at emails and a smattering
> of web pages, but there is much that I'm missing.
> In the meantime, if someone could suggest the commands I'd need to do the
> equivalent of:
> #! /bin/sh
> #
> # Get security and distribution updates
> #
> apt-get update --assume-yes
> # The file sec.sources.list is a subset of sources.list that contains only
> security update sources
> apt-get upgrade --assume-yes \
>    -o Dir::Etc::sourcelist=/etc/apt/sec.sources.list
> #
> # reboot here if kernel updated ... cloud-config uses
> apt_reboot_if_required: True
> #
> # Get llvm updates
> #
> apt-get update --assume-yes
> apt-get install llvm-3.0 --install-suggests --assume-yes
> apt-get install llvm-3.0-doc --install-suggests --assume-yes
> apt-get install llvm-3.0-dev --install-suggests --assume-yes
> apt-get install clang --install-suggests --assume-yes
What you have above isn't really all that bad.  I'd combine your apt-get
lines into one, and suggest some more flags:
apt() {
   DEBIAN_FRONTEND=noninteractive apt-get --install-suggests \
     --assume-yes --option "Dpkg::Options::=--force-confold" \
     "$@" </dev/null
apt upgrade -o Dir::Etc::sourcelist=/etc/apt/sec.sources.list
apt install llvm-3.0 llvm-3.0-doc llvm-3.0-dev clang
[ ! -f /var/run/reboot-required ] || reboot

but other than that, it really does look reasonable.

You can't really intermix 'apt_reboot_if_required' in the above, as that
is just going to be run as a shell script, and actually wont have an
affect .

There really is no harm in doing things via '#!' rather than cloud-config.
The benefit of using the some of the more involved (or config) syntax is
that you can run things earlier in boot.

> So far I've got:
> #cloud-config
> apt_update: True
> apt_upgrade: True
> apt_reboot_if_required: True

This is only available in 12.10.

> but I've no idea how to set the sources, or how to install specific
> packages _and_ their suggested packages.

In 12.10, this would get you something close to what you wanted.
but would have the negative affect of making 'install-suggests' the
default and removing other entries from your /etc/apt/sources.list.

In 12.04, you'd have to use a 'bootcmd' or 'boothooks' and multipart (or
cloud-config-archive) input to write the files yourself.

##### untested ####
apt_update: True
apt_upgrade: True
apt_reboot_if_required: True

packages: [llvm-3.0, llvm-3.0-doc, llvm-3.0-dev, clang]

 - content: |
    APT::Install-Suggests "false";
   owner: root:root
   path: /etc/apt/apt.conf.d/99install-suggests
 - content: |
    deb http://security.ubuntu.com/ubuntu $codename-security main universe
   path: /etc/cloud/templates/sources.list.tmpl
##### end file ####

More information about the Ubuntu-cloud mailing list