Ubuntu server autoinstall rebooting without finishing late-commands

Ubuntu Version:
22.04/24.04

Desktop Environment (if applicable):
Server

Problem Description:
EDIT: autoinstall not going through the entire late-commands, and rebooted after doing the first command.
EDIT2: autoinstall doesn’t run curtin commands in 22.04 server

I wanna create and enable a systemd service that would show the IP without logging in. I tried via Systemd service:

  late-commands:
    - sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /target/etc/ssh/sshd_config
    - curtin in-target --target=/target -- bash -c 'cat > /etc/systemd/system/show-ip-issue.service <<EOF
[Unit]
Description=Update /etc/issue with Ubuntu version and IP
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/bash -c "echo -e \'Ubuntu \$(lsb_release -rs)\\nSystem in barebones state\\nGive Ubuntu IP to IT for deployment\\n\$(hostname -I)\n\' > /etc/issue"
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
EOF'
    - curtin in-target --target=/target -- systemctl daemon-reload
    - curtin in-target --target=/target -- systemctl enable show-ip-issue.service

However, it doesn’t seem to show up on the target computer

Relevant System Information:

Screenshots or Error Messages:

What I’ve Tried:


Instead of using late-commands perhaps you could use cloud-init commands at the end of your autoinstall file. They might look something like this:

    user-data:

        disable_root: false

        write_files:
            - content: |
                [Unit]
                Description=Update /etc/issue with Ubuntu version and IP
                After=network-online.target

                [Service]
                Type=oneshot
                ExecStart=/usr/bin/bash -c "echo -e \'Ubuntu \$(lsb_release -rs)\\nSystem in barebones state\\nGive Ubuntu IP to IT for deployment\\n\$(hostname -I)\n\' > /etc/issue"
                RemainAfterExit=yes

                [Install]
                WantedBy=multi-user.target
              path: /etc/systemd/system/show-ip-issue.service
              permissions: '0644'

        runcmd:
            - |
                systemctl daemon-reload
                systemctl enable show-ip-issue.service

You might want to use systemctl enable --now for that last command since the cloud-init commands won’t run until the first boot. I guess that means the very first login prompt won’t show this customization.

2 Likes

thanks for this. This one seems to be working!

I’m curious to know, if I wanna write multiple files, do I do

write_files:
  - content: |
      ...
    path:
write_files:
  - content: |
      ...
    path:
runcmd:
  - |
       ..
write_files:
  - content: |
      ...
    path:
runcmd:
  - |
       ..

You write all of the files with one write_files, and run all commands with one runcmd:

        write_files:
            - content: |
                 ...
              path: ...

            - content: |
                 ...
              path: ...

            - content: |
                 ...
              path: ...

        runcmd:
            - |
                ...
                ...
                ...

2 Likes