Tags

, , , , , , , ,

While provisioning LXD instance; we can define post deployment task using cloud-init. This will help us to import your public SSH keys, add new user, update packages and install new packages if required. To do that we use lxc profile.

First check what lxc profile you have. There should be one default profile.

# lxc profile list

Copy default profile and create new one

# lxc profile copy default production

Edit newly created profile

# lxc profile edit production

Use the following configuration. This is YAML file and for better formatting please download it from here

config:
user.user-data: |
#cloud-config
users:
– name: fakrul
ssh_authorized_keys:
– ssh-rsa  AAAAB3NzaC1yc2EAAAADAQABAAABAQDEgjB+5olN+5DuCkYJfZC6e/lMlW30inWEKkL0ThIVzgDh4hbjgvjaZGapYeS94PAE17Lk8FQnWb1bFQmBXP9jjbnExD9473AueJvN6Lhrc5GVnpIQ+K+9fxJfaS0k4CQbqDfMfL5+VRYG/M8mm98rGz4ZleG7I/lKlgsoeXI8UZTl+gg6HO5vCmRglncKUIMmOuy06Z6DuO8dCh+pUnwBZW8bGcisZFDr6g3G7ZpVTDygOZQ08qV47VGutDkr3cBS8llQ8EzU9CBT+HRlSlbnfICWfY6nem4mwm+Ef2bvLlO3VVSoLgk+VvDLEi8oGMxQ38nFxGnW6K/cJsomo3hd fakrul@au-mohammad-macbook.local
sudo: ALL=(ALL) NOPASSWD:ALL
groups: sudo
shell: /bin/bash
passwd: $1$hUDF3Apy$jJztHAqAE8qxMX3yl0rnK/
gecos: Fakrul Alam
# Update timezone
locale: es_ES.UTF-8
timezone: Australia/Sydney
# Update apt database on first boot (run ‘apt-get update’).
package_update: true
# Install required packages
packages:
– whois
– inetutils-traceroute
– traceroute
– net-tools
description: LXD Custom Profile
devices:
eth0:
name: eth0
nictype: bridged
parent: lxdbr0
type: nic
root:
path: /
pool: container_storage
type: disk
name: production
used_by: []

Now launch new instance

# lxc launch --profile production ubuntu:18.04 testvm03

This will create new instance with username fakrul, copy the SSH key and update all the packages!

You can check the profile

# lxc profile show production

Screen Shot 2020-01-10 at 4.57.45 pm.png