cloud-config

LXD cloud-config profile

- name: Create cloud-config profile
  lxd_profile:
    name: cloud-config
    config:
      user.user-data: |
        #cloud-config
        locale: en_US.UTF-8
        timezone: Europe/Berlin
        # apt:
        #   disable_suites: [release, updates, backports, security]
        #   primary:
        #     - arches: [amd64]
        #       uri: http://mirror.example.com/current/ubuntu
        apt:        
          sources_list: |
            deb [arch=amd64] http://mirror.example.com/current/ubuntu $RELEASE main restricted universe multiverse
            deb [arch=amd64] http://mirror.example.com/current/ubuntu $RELEASE-updates main restricted universe multiverse
            deb [arch=amd64] http://mirror.example.com/current/ubuntu $RELEASE-security main restricted universe multiverse
            deb [arch=amd64] http://mirror.example.com/current/ubuntu $RELEASE-backports main restricted universe multiverse
        apt_upgrade: true
        package_upgrade: true
        packages:
          - openssh-server
        disable_root: false
        ssh_authorized_keys:
          - "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"          
      user.network-config: |
        version: 1
        config:
          - type: physical
            name: mgmt
            subnets:
              - type: dhcp

Links
https://cloudinit.readthedocs.io/en/latest/topics/examples.html
https://www.digitalocean.com/community/tutorials/how-to-use-cloud-config-for-your-initial-server-setup