Cloud-init pre-configure not working on LXD 3.0/Bionic Beaver


(Stephen Nesbitt) #1

Has something changed in 3.0 with respect to embedding cloud-init provisioning of containers at launch?

Following Simos’s blog post i have created the following profile in the attempt to pre-configure the container on launch/initializtion

$ lxc profile show AWTUbuntu1804
config:
  environment.TZ: ""
  user.user-data: |
    #cloud-config
    package_upgrade: true
    packages:
      - build-essential
    locale: es_ES.UTF-8
    timezone: Europe/Madrid
    runcmd:
      - [touch, /tmp/simos_was_here]
description: Default LXD profile
devices:
  eth0:
    nictype: bridged
    parent: lxdbr0
    type: nic
  root:
    path: /
    pool: default
    type: disk
name: AWTUbuntu1804
used_by:
- /1.0/containers/test3
- /1.0/containers/test6

But it isn’t being executed - python2.7-minimal is not installed and no /tmp/simos_was_here file exists on either test3 or test6. I created test3 with the launch command. test6 was created through init and start.

Thx in advance,

-steve


(David Negreira) #2

Ubuntu 18.04 has no python2.7 by default


(Stephen Nesbitt) #3

Not sure I understand your meaning.

Python2.7-minimal is a package available on Bionic. As I understand it, the profile I have setup up should cause cloud-init to install the package when the container is inited.

-steve


#4

I tried again the tutorial on LXD 3.0.0 and it worked. I got the /tmp/simos_was_here file.
Note that it takes some time to run that command because it first has to do a package upgrade.
To figure out what is going on, you can get a shell into the container as soon as you launch it, and then run ps ax to see the processes. You will be able to see the package upgrade (apt commands and so on) which takes a minute or two to complete.

You mention that python2.7-minimal is not installed on the Ubuntu 18.04 container image.
That is correct; on Ubuntu 18.04, there is no Python 2 whatsoever in the official images and ISOs.
Ubuntu 18.04 is fully transitioned to Python 3.
Here is the output from a freshly launched 18.04 container. The package is there, but not installed.

root@cloudinit:/tmp# apt policy python2.7-minimal
python2.7-minimal:
  Installed: (none)
  Candidate: 2.7.15~rc1-1
  Version table:
     2.7.15~rc1-1 500
        500 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages
root@cloudinit:/tmp# 

To verify that the cloud-init commands have made it to the container, check (in the container) the following:

root@cloudinit:~# cat /var/lib/cloud/seed/nocloud-net/user-data 
#cloud-config
package_upgrade: true
packages:
  - build-essential
locale: es_ES.UTF-8
timezone: Europe/Madrid
runcmd:
  - [touch, /tmp/simos_was_here]
root@cloudinit:~# 

By doing this, you verify that the container was created with the correct profile that has the cloud-init instructions.


(Stephen Nesbitt) #5

What Bionic image are you using?

My bionic image (images:ubuntu/18.04/amd64) doesn’t appear to have cloud-init installed…

apt policy cloud-init
cloud-init:
Installed: (none)
Candidate: 18.2-14-g6d48d265-0ubuntu1
Version table:
18.2-14-g6d48d265-0ubuntu1 500
500 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages


(Stephen Nesbitt) #6

Ok - it’s definitely the image. I switched to ubuntu:18.04 and the python2.7-minimal is being installed.

Is there are any current documentation which lists the image servers available and what their differences are? How does images: differ from ubuntu: and how do I discover available image servers.

Thx for the help - got me asking the right questions.

-steve


#7

Indeed, in general the images from images: are not likely to have cloud-init preinstalled.

Use instead the container image ubuntu:18.04 which has cloud-init.


(David Negreira) #8

You can see all the images on each remote with lxc image list ubuntu: and lxc image list images:. Not sure where can you find information about the images besides of what is in the description field.