Creating an Incus Instance with cloud‑init
To verify that an Ansible role works correctly I need to test it on multiple instances with Molecule. I require, to accomplish this, an SSH server, a sudo user that allows SSH login with my public key, and a few missing packages. Rather than creating a separate model for each Linux distribution and repeating the process with every new release, I’ll use an Incus profile with cloud‑init to deploy the same configuration everywhere.
To do this we must first have Incus configured.
To create and edit the Molecule profile, run:
incus profile create moleculeincus profile edit moleculeIn the profile‑editing window:
### This is a YAML representation of the profile.### Any line starting with a '#' will be ignored.###### A profile consists of a set of configuration items followed by a set of### devices.###### An example would look like:### name: onenic### config:### raw.lxc: lxc.aa_profile=unconfined### devices:### eth0:### nictype: bridged### parent: mybr0### type: nic###### Note that the name is shown but cannot be changed
config: cloud-init.user-data: | #cloud-config package_upgrade: true packages: - acl - openssh-server - python3-apt users: - name: ansible groups: sudo sudo: ALL=(ALL) NOPASSWD:ALL shell: /bin/bash ssh_authorized_keys: - ssh-ed25519 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXdescription: ""devices: {}name: moleculeused_by: []In order, package_upgrade updates the Apt packages, then packages installs the selected packages, and finally a user is created with the name ansible, added to the sudo group, configured for password‑less sudo, and given an SSH public key for login. You can find further references for configuring the file in the official documentation.
Once configured you can launch a test instance with:
incus launch images:debian/trixie/cloud test-cloud-init --profile default --profile molecule