Incus Ansible deployment
--- - name: Create container hosts: incus1.example.com # become: yes tasks: - name: Create incus container community.general.lxd_container: url: "unix:/var/lib/incus/unix.socket" name: u2404 source: type: image mode: pull server: https://images.linuxcontainers.org/ alias: ubuntu/24.04/cloud protocol: simplestreams wait_for_container: true wait_for_ipv4_addresses: true config: limits.cpu: "4" boot.autostart: "true" cloud-init.user-data: | #cloud-config package_upgrade: true locale: en_US.UTF-8 timezone: Europe/Berlin apt_upgrade: true package_upgrade: true packages: - openssh-server # disable_root: false ssh_authorized_keys: - "{{ lookup('file', '~/.ssh/id_rsa.pub') }}" cloud-init.network-config: | network: version: 2 ethernets: eno1: dhcp4: true profiles: ["disk-default", "nic-dev"] register: container - name: Configure temporary user for initial run set_fact: remote_user: ubuntu delegate_to: localhost delegate_facts: True when: container.changed- name: Create container - name: Configure container hosts: u2404.example.com gather_facts: no remote_user: "{{ hostvars['localhost']['remote_user'] | default(lookup('env', 'USER')) }}" become: yes tasks: - name: Create a user 'johnd' with a home directory ansible.builtin.user: name: johnd create_home: yes
Links
https://discuss.linuxcontainers.org/t/creating-container-with-ansible/20050/7
https://documentation.ubuntu.com/lxd/en/latest/cloud-init/
https://docs.ansible.com/ansible/latest/collections/community/general/lxd_container_module.html