What am I doing wrong with Cloud-init

I’m trying to create a simple profile for a mariadb server. I’ve created the following config:

$ lxc profile show mariadb
config:
  user.user-data: |
    package_update: true
    packages:
      - mariadb-server
description: Mariadb server profile
devices:
  eth0:
    name: eth0
    network: lxdbr0
    type: nic
  root:
    path: /
    pool: default
    type: disk
name: mariadb
used_by:
- /1.0/instances/mdb1
- /1.0/instances/mdb2
- /1.0/instances/mdb3

I just copied the default profile and added the user-data section.

When I start a new instance:

lxc launch ubuntu:lts mdb3 -p mariadb

Not only is mariadb-server not installed - I cannot even see the package as available until I do an apt-get update to refresh the repositories. Which I would’ve thought was covered by package_update: true in the profile…

Where did I go wrong here?

edit - On Ubuntu 18.04 lxd version 4.1 - installed from snap

1 Like

Its doesn’t look like the right format and doesn’t start with #cloud-config like it should,

put the following in a file

#cloud-config
package_update: true
packages:
  - mariadb-server

then create a profile for it

lxc create profile mariadb-deploy

set the user data from the file

lxc profile set mariadb-deploy user.user-data - < /path/to/above/yaml/file

then launch the profile

lxc launch ubuntu:lts mariadb-01 -p default -p mariadb-deploy

in the future when testing cloud-config be aware of the log files

/var/log/cloud-init-*
#/var/log/cloud-init-output.log being the most intreseting

Ok I ran through these steps and that seems to have solved the problem. Thanks!

Seems kinda odd though… I wonder if it was just because I missed the #cloud-config part? or I had some stuff left over from the default config that was conflicting. Maybe, I had a spacing issue or something too… in any event, thanks for the help.

Go into the containers and look in the files /var/log/cloud-init.log & /var/log/cloud-init-output.log but its probably because it didnt start with #cloud-config

also be aware of