Custom cloud-init creating a 'deploy loop'

I have created a file (/var/snap/maas/current/preseeds/curtin_userdata_ubuntu)

#cloud-config
early_commands:
  bash_script: [mkdir, '-p', '/root/script.sh']

write_files:
  bash_script:
    path: /root/script.sh
    content: |
      #!/bin/bash
      cp /etc/netplan/50-cloud-init.yaml /tmp/50-cloud-init.yaml
      sudo sed -i '/gateway*/d' /etc/netplan/50-cloud-init.yaml
      sudo sed -i 's/0.0.0.0\/0/default/' /etc/netplan/50-cloud-init.yaml
      sudo sed -i -n '/default/{x;d;};1h;1!{x;p;};${x;p;}' /etc/netplan/50-cloud-init.yaml
      sudo sed -i 's/^[ ]*to: default/            -   to: default/' /etc/netplan/50-cloud-init.yaml
      sudo netplan apply
    permissions: '0755'

late_commands:
  99-cmd: ["curtin", "in-target", "--", "/bin/bash", "/root/script.sh"]

I’ve created this script to update the gateway post-deployment as I’m unable to ping the public world post-deployment. However, when deploying a system, what happens is it creates a sort of deploy loop, where it will PXE boot, load ephemeral, config storage, install os, config os, and repeat. This loop wont stop either.

From the message logs of the machine it seems to be okay:

2022-06-30T20:09:41+00:00 suited-imp cloud-init[1738]: TIMED INSTALL_COMMAND: 163.600
2022-06-30T20:09:41+00:00 suited-imp cloud-init[1738]: finish: cmd-install: SUCCESS: curtin command install
2022-06-30T20:09:41+00:00 suited-imp cloud-init: #############################################################
2022-06-30T20:09:41+00:00 suited-imp cloud-init: -----BEGIN SSH HOST KEY FINGERPRINTS-----
2022-06-30T20:09:41+00:00 suited-imp cloud-init: 1024 SHA256:ZCHJLYtX6IcD2xVfK7dAQAQQmNryPXsz+zGx+xrDzs0 root@suited-imp (DSA)
2022-06-30T20:09:41+00:00 suited-imp cloud-init: 256 SHA256:b6DSjexQGxr2H6FzIm9clUXivQtBQYkli7YetPaGdyM root@suited-imp (ECDSA)
2022-06-30T20:09:41+00:00 suited-imp cloud-init: 256 SHA256:V/JaZMt08PrgLo6fyGyqptgFXvgwbSoBJG+qBYc9GRo root@suited-imp (ED25519)
2022-06-30T20:09:41+00:00 suited-imp cloud-init: 3072 SHA256:AnwfTkbEz4jKdm39VrILY4xPry8IK5fgkOK/wBm6hq4 root@suited-imp (RSA)
2022-06-30T20:09:41+00:00 suited-imp cloud-init: -----END SSH HOST KEY FINGERPRINTS-----
2022-06-30T20:09:41+00:00 suited-imp cloud-init: #############################################################
2022-06-30T20:09:41+00:00 suited-imp cloud-init[1738]: Cloud-init v. 22.2-0ubuntu1~20.04.2 running 'modules:final' at Thu, 30 Jun 2022 20:06:26 +0000. Up 86.23 seconds.
2022-06-30T20:09:41+00:00 suited-imp cloud-init[1738]: Cloud-init v. 22.2-0ubuntu1~20.04.2 finished at Thu, 30 Jun 2022 20:09:41 +0000. Datasource DataSourceMAAS [http://192.168.251.251:5248/MAAS/metadata/curtin].  Up 281.86 seconds
2022-06-30T20:09:41+00:00 suited-imp systemd[1]: Finished Execute cloud user/final scripts.
2022-06-30T20:09:41+00:00 suited-imp systemd[1]: Reached target Cloud-init target.
2022-06-30T20:09:41+00:00 suited-imp systemd[1]: Startup finished in 19.982s (kernel) + 4min 22.100s (userspace) = 4min 42.083s.

But it still continues the pxe boot and cycle again.

Hi James,

we don’t recommend modifying curtin preseeds, since it’s easy to break things.

What exactly are you trying to do? Maybe we can find a better way of solving your problem.

2 Likes

Hi Bjornt,

Originally I was trying to fix gateway issues. It took a while and honestly, I didn’t think I was going to solve it in MaaS, hence the post. But somehow I lucked out and was able to figure it out and immediately documented it here:
https://jamesbenson.weebly.com/blog/setting-maas-gateways-the-right-way
It wasn’t intuitive to me, perhaps because I’m not a network guy, that I didn’t need to set the gateway IP for the internal network but still set a static route. Hopefully it’ll help others.

That said, while not related to my original post, I’d still like to figure out how to get the curtin working properly. It wouldn’t be for the original sed commands above, but maybe even a simple apt update && apt upgrade on every ubuntu release.

hey, @james-o-benson, can you start another thread here on curtin, with more details on what you’re thinking? curtin is always a topic of conversation, and it wouldn’t hurt to chase that down separately.

nice blog, by the way. i have something new to add to my reading rotation. :slight_smile:

1 Like