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:

2 Likes

Hello @james-o-benson,

We have a similar problem, I would suggest creating a separate cloud-init that contains the code you mentioned and this runs during the deployment of the OS, you can do this via the MAAS GUI or via the MAAS API.

hey, @james-o-benson, i didn’t ever find another post on this related to curtin, just seeing if you found a solution?

Hi @billwear,

Sorry, I haven’t been very active here as of late. No, I hadn’t dug into it as much as I wanted to so no solution as of yet. I’ll try the MAAS GUI method @cmills , I’m running 3.2.7 and have never seen an option in the GUI, where is it? Or is that a new feature in 3.3.x? Thanks.

@billwear I’ve tested the GUI method of the cloud-init and seems to work fine. It can be found once you select the deploy option, on the same pane as where you choose the OS/kernel/etc.

I used the following for those that care, and all 4 items seem to have passed. It would be great to have the ability to have option to always have a cloud-init enabled by default or at least saved as an option instead of consistently uploading/copy-paste it.

#cloud-config
users:
  - name: test
    groups: sudo
    shell: /bin/bash
    sudo: ['ALL=(ALL) NOPASSWD:ALL']
    ssh-authorized-keys:
      - ssh-ed25519 [omitted]
package_update: true
package_upgrade: true
write_files:
  - path: /test.txt
    content: |
      Here is a line.
      Another line is here.

There’s a check box, that allows you to select or past in your cloud-init once you choose deploy through the GUI.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.