I am configuring an OpenStack box using cloud-init/cloud-config. I intend to wait until it is fully configured before I start using it.
This is not all that hard to do using some marker file or detecting if the cloud-init process is still running, though it seems quite cumbersome to do that in every cloud-init script. Is there some recommended way? Natively supported by cloud-init, ideally?
Boot Time Analysis - cloud-init analyze log file into formatted and sorted events. It allows for detailed analysis of the most costly cloud-init operations are to determine the long-pole in cloud-init configuration and setup. These subcommands default to reading /var/log/cloud-init. log.
By default, cloud-init attempts to determine which case it is running in by checking the instance ID in the cache against the instance ID it determines at runtime. If they do not match, then this is an instance's first boot; otherwise, it's a subsequent boot. Internally, cloud-init refers to this behavior as check .
Cloud-init config is provided in two places: /etc/cloud/cloud. cfg. /etc/cloud/cloud.
The following command does the trick:
cloud-init status --wait
From https://ubuntu.com/blog/cloud-init-v-18-2-cli-subcommands:
cloud-init status
gives simple human-readable or programmatic output for what cloud-init is doing and whether it has finished successfully. It can be used as a sanity check on a machine or in scripts to block until cloud-init has completed successfully.
As @flyxiao pointed out, cloud-init put status information into a dedicated directory on a filesystem: /run/cloud-init/
(preferred over /var/lib/cloud/data/
as it is guaranteed to describe last init process). status.json
contains detailed about all init phases and result.json
denotes the whole init is completed. The project documentation suggest a python script to detect cloud-init completion:
fin = "/run/cloud-init/result.json"
if os.path.exists(fin):
ret = json.load(open(fin, "r"))
if len(ret['v1']['errors']):
print "Finished with errors:" + "\n".join(ret['v1']['errors'])
else:
print "Finished no errors"
else:
print "Not Finished"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With