The ssh module will only run once per instance. On subsequent boot, you'll see that the keys are no longer affected. Every module is set to run at least once, but if initialization fails, the module won't run until a subsequent run of cloud-init.
We clear out host keys on first successful boot because a common use case is to take an existing instance, create a snapshot of it, and then launch new images from that. We don't want keys from those older instances being copied over to newer instances. This can be disabled with the `ssh_deletekeys` cloud-config key. This is explained more fully in the docs at https://cloudinit.readthedocs.io/en/latest/topics/modules.html#host-keys Since there's a way to disable this behavior with the `ssh_deletekeys` key, I'm going to close this as Invalid. If there's something I have missed here, please provide more context and set it back to New. ** Changed in: cloud-init Status: New => Invalid -- You received this bug notification because you are a member of Yahoo! Engineering Team, which is subscribed to cloud-init. https://bugs.launchpad.net/bugs/1945196 Title: cloud-init regenerating ssh host keys on Azure Status in cloud-init: Invalid Bug description: cloud-init fails in "crawl_metadata" phase in first boot of Ubuntu 20.04 VM on Azure cloud. After few reboots, the cloud-init succeeds in "crawl metadata" phase and it then regenerates the ssh host keys. The communication between hosts of the cluster is broken thereafter, and cluster formation fails. Changing host keys in general is an issue, and should be avoided. Expected behavior: if the cloud-init succeeds in later reboots, it shouldn't regenerate host keys. To manage notifications about this bug go to: https://bugs.launchpad.net/cloud-init/+bug/1945196/+subscriptions -- Mailing list: https://launchpad.net/~yahoo-eng-team Post to : [email protected] Unsubscribe : https://launchpad.net/~yahoo-eng-team More help : https://help.launchpad.net/ListHelp

