Cloud boothook¶
Simple Example¶
#cloud-boothook
#!/bin/sh
echo 192.168.1.130 us.archive.ubuntu.com > /etc/hosts
Example of once-per-instance script¶
#cloud-boothook
#!/bin/sh
# Early exit 0 when script has already run for this instance-id,
# continue if new instance boot.
cloud-init-per instance do-hosts /bin/false && exit 0
echo 192.168.1.130 us.archive.ubuntu.com >> /etc/hosts
Explanation¶
A cloud boothook is similar to a user-data script
in that it is a script run on boot. When run,
the environment variable INSTANCE_ID is set to the current instance ID
for use within the script.
The boothook is different in that:
It is run very early in boot, during the network stage, before any cloud-init modules are run.
It runs every boot.
Warning
Use of INSTANCE_ID variable within boothooks is deprecated.
Use jinja templates with
v1.instance_id instead.