Ubuntu VM and public/private network

Hello,

LXD Version: 4.5
Host on Ubuntu 20.04

I tried to create an ansible playbook to create VM Ubuntu Focal with two interfaces and user ansible configured.

This part of my playbook

- name: Creation profile vm_lanprofile LXD
  lxd_profile:
    name: vm_lanprofile
    state: present
    config:
      user.network-config: | 
        version: 1
        config:
          - type: physical
            name: eth0
            subnets:
              - type: dhcp
          - type: physical
            name: eth1
            subnets:
              - type: dhcp
      user.user-data: | 
        #cloud-config
        ssh_pwauth: yes
        users:
        - default
        - name: ansible
          gecos: ansible
          groups: sudo
          sudo: ALL=(ALL) NOPASSWD:ALL
          shell: /bin/bash
          lock-passwd: false
          passwd: "crypt_password"
          ssh_authorized_keys:
            - ssh-key xxxxxxxxx

    description: VM conf for eth on lan dhcp
    devices:
      config:
        source: cloud-init:config
        type: disk
      eth0:
        name: eth0
        nictype: bridged
        parent: lxdbr0
        type: nic
      eth1:
        name: eth1
        nictype: bridged
        parent: brvlan
        type: nic
      root:
        path: /
        pool: data
        type: disk

- name: Demarrage de la VM
  shell: "lxc launch {{ vm_os }} {{ vm_name }} --vm -c security.secureboot=false -c limits.cpu={{ cpu_limit }} -c limits.memory={{ ram_gb }}GB -p {{ vm_profile }}"

And defaults vars:

        vm_user: "ansible"
        vm_user_password: "blablablabla"
        vm_name: "sandbox"
        vm_os: "images:ubuntu/20.04/cloud"
#        vm_os: "ubuntu:20.04"
        ram_gb: 4
        cpu_limit: 2
        vm_profile: vm_lanprofile

When I use vm_os: "ubuntu:20.04"

  • I have my user but I needed to first time to ssh connect with user ubuntu@sandbox, and after ansible@sanbox to works.
  • But only one interface ensp5

When I use vm_os: "images:ubuntu/20.04/cloud"

  • No network working at all
  • I don’t know if user is work.

I try to comment when I use /cloud image

#        source: cloud-init:config
#        type: disk

But no more works.

lxc network list

+-----------------+----------+---------+---------------+------+-------------+---------+
|      NAME       |   TYPE   | MANAGED |     IPV4      | IPV6 | DESCRIPTION | USED BY |
+-----------------+----------+---------+---------------+------+-------------+---------+
| br-fb5620c190cf | bridge   | NO      |               |      |             | 0       |
+-----------------+----------+---------+---------------+------+-------------+---------+
| brvlan          | bridge   | NO      |               |      |             | 11      |
+-----------------+----------+---------+---------------+------+-------------+---------+
| docker0         | bridge   | NO      |               |      |             | 0       |
+-----------------+----------+---------+---------------+------+-------------+---------+
| enp0s25         | physical | NO      |               |      |             | 0       |
+-----------------+----------+---------+---------------+------+-------------+---------+
| lxdbr0          | bridge   | YES     | 10.69.10.1/24 | none |             | 14      |
+-----------------+----------+---------+---------------+------+-------------+---------+

lxc profile show vm_lanprofile

config:
  user.network-config: |
    version: 1
    config:
      - type: physical
        name: eth0
        subnets:
          - type: dhcp
      - type: physical
        name: eth1
        subnets:
          - type: dhcp
  user.user-data: |
    #cloud-config
    ssh_pwauth: yes
    users:
    - default
    - name: ansible
      gecos: ansible
      groups: sudo
      sudo: ALL=(ALL) NOPASSWD:ALL
      shell: /bin/bash
      lock-passwd: false
      passwd: "crypt_password"
      ssh_authorized_keys:
        - ssh-key xxxxxx
description: VM conf for eth on lan dhcp
devices:
  eth0:
    name: eth0
    nictype: bridged
    parent: lxdbr0
    type: nic
  eth1:
    name: eth1
    nictype: bridged
    parent: brvlan
    type: nic
  root:
    path: /
    pool: data
    type: disk
name: vm_lanprofile
used_by:
- /1.0/instances/sandbox

I don’t know what to do now.

Thanks

Here is an example of a cloud-init config that successfully creates a user called user with a password of ubuntu so you can login from the console:

config:
  user.user-data: |
    #cloud-config
    ssh_pwauth: yes

    users:
      - name: user
        passwd: "$6$s.wXDkoGmU5md$d.vxMQSvtcs1I7wUG4SLgUhmarY7BR.5lusJq1D9U9EnHK2LJx18x90ipsg0g3Jcomfp0EoGAZYfgvT22qGFl/"
        lock_passwd: false
        groups: lxd
        shell: /bin/bash
        sudo: ALL=(ALL) NOPASSWD:ALL

Then:

lxc launch images:ubuntu/20.04/cloud v1 --vm
# Wait until started (and can see IP info from lxc ls)
lxc console v1
# Login using user/ubuntu.

Keep in mind that cloud-init configs only apply on first boot.

I would suggest you try simplifying your config first, so try using a single network connected to the default lxdbr0 and getting your user logins working, and then tackle the more advanced network config. That way you will know which part is breaking your config.