Score:2

Combine cloud-init autoinstall with other cloud-init modules

br flag
Tom

I'm trying to provision a VM with cloud-init and the server live image. (I'm not using the cloud image, for infrastructural reasons I have to install from ISOs)

However, whenever I'm trying to combine autoinstall with e.g. write_files, the write_files part does not seem to succeed.

The following installs Ubuntu:

#cloud-config
autoinstall:
  version: 1
  identity:
    hostname: boxy-001
    password: "$1$k46kl1..."
    username: alice
  storage:
    layout:
      name: lvm
  ssh:
    install-server: true
    authorized-keys: 
      - "ecdsa-sha2-nistp256 AAAAE2...."
     
write_files:              
- content: |              
    cloud_init_has_run    
  path: /cloud_init_flag  

But the file is not written at /cloud_init_flag.

Are modules missing? Is cloud-config incomplete on the Server live ISOs?

Edit the file is written, but it's written in the installation environment! Instead, I should likely use the autoinstall.user-data key to provide the user-data for the target system.

Andrew Lowther avatar
jp flag
Your `write_files` config works for me using the `20.04` live server installer. Is the rest of the `autoinstall` working? How are you confirming the file is missing?
br flag
Tom
So, when using this user-data while installing Ubuntu 20.04 LTS with the live installer, the `/cloud_init_flag` is actually created?
Andrew Lowther avatar
jp flag
I took your `write_files` section and added it to my `user-data` file. I started an install and opened a shell in the installer environment. The `/cloud_init_flag` was created with the configured content. My guesses: 1. your autoinstall file is not being used at all. 2. your autoinstall file is invalid and not getting parsed. 3. you expect the file to be on the installed system when it is just on the installation environment
br flag
Tom
Aaah, that must be it. All cloud-init functions are executed in the install environment? Can I ask, how would I get cloud-init to run on the _installed_ system in combination with `autoinstall`?
Score:3
jp flag

how would I get cloud-init to run on the installed system in combination with autoinstall?

There is a user-data config key for the autoinstall file.

For example, if you want your write_files configuration to be used by cloud-init on the installed system then this snippet could be included as part of the autoinstall file.

#cloud-config
autoinstall:
  version: 1
  user-data:
    write_files:
    - content: |
        cloud_init_has_run
      path: /cloud_init_flag
...

How it works

  • During the install, subiquity will create configuration for cloud-init at /target/var/lib/cloud/seed/nocloud-net/user-data.
  • During the first boot of the installed system, cloud-init will use this config file to perform some of the install tasks. Notably, this is how the first user is created.
  • If a user-data section is included in the autoinstall file then subiquity will merge the user-data section into the generated /target/var/lib/cloud/seed/nocloud-net/user-data file.

Using the snippet above, the merged configuration resulted in this file content.

#cloud-config
growpart: {mode: 'off'}
locale: en_US.UTF-8
preserve_hostname: true
resize_rootfs: false
...
write_files:
- {content: 'cloud_init_has_run

    ', path: /cloud_init_flag}

During first boot, cloud-init did create the /cloud_init_flag file with the configured content.

br flag
Tom
Thank you. This would be a great addition to the concise documentation at https://ubuntu.com/server/docs/install/autoinstall-reference#user-data
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.