To to clarify, I under you can user hostname in a cloud-config, the problem I am solving is for autoscaling launch configuration and needing a common base hostname (for config management purposes and only for humans to identify) but unique amongst them.
So the host name I am setting is:
prd-myshinnyhostname-ap-southeast-1a-$RANDOM
Which I can't see anyway to do in cloud-config unfortunately, otherwise I would stick to use that for this autoscale launch config.
I am injecting into /etc/cloud/cloud.cfg to save having to have a cloud-config file at all. Just lazy maybe, but figured it works best with how I am setting the hostname (cloud-config hostname is useless for this use case)
So back to the issue, I had the below. The boothook worked but the shell script didn't touch the file in /etc or the test file.
(the work around I have for now is to just have a boothook, and the boothook injects into /etc/rc.local the shell script and then adds a line to clean up after it has run so as to have a one-time run of the shell script. Working well)
Thanks for the info Scott.
To to clarify, I under you can user hostname in a cloud-config, the problem I am solving is for autoscaling launch configuration and needing a common base hostname (for config management purposes and only for humans to identify) but unique amongst them.
So the host name I am setting is:
prd-myshinnyhos tname-ap- southeast- 1a-$RANDOM
Which I can't see anyway to do in cloud-config unfortunately, otherwise I would stick to use that for this autoscale launch config. cloud.cfg to save having to have a cloud-config file at all. Just lazy maybe, but figured it works best with how I am setting the hostname (cloud-config hostname is useless for this use case)
I am injecting into /etc/cloud/
So back to the issue, I had the below. The boothook worked but the shell script didn't touch the file in /etc or the test file.
(the work around I have for now is to just have a boothook, and the boothook injects into /etc/rc.local the shell script and then adds a line to clean up after it has run so as to have a one-time run of the shell script. Working well)
I will try your user-data file and report back.
_______ _______ _______ ___
Content-Type: multipart/mixed; boundary= "====== ======= ==2371311152411 390760= ="
MIME-Version: 1.0
--===== ======= ===237131115241 1390760= = boothook; charset="us-ascii" Transfer- Encoding: 7bit Disposition: attachment; filename="boothook"
Content-Type: text/cloud-
MIME-Version: 1.0
Content-
Content-
#cloud-boothook
#!/bin/bash
if [ ! -f /etc/id ] hostname/ preserve_ hostname: True/g' /etc/cloud/ cloud.cfg preserve_ sources_ list/apt_ preserve_ sources_ list: True/g' /etc/cloud/ cloud.cfg TEST-ap- southeast- 1 domain. edu.au ${NEW} >> /etc/hosts
then
sed -i 's/preserve_
sed -i 's/apt_
# set hostname
OLD=prd-
NEW=${OLD}-$RANDOM
echo ${NEW} > /etc/hostname
hostname ${NEW}
echo 127.0.1.2 ${NEW}.
echo $INSTANCE_ID > /etc/id
fi
exit 0
--===== ======= ===237131115241 1390760= = Transfer- Encoding: 7bit Disposition: attachment; filename= "boothook- script"
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-
Content-
#!/bin/bash -x
touch /etc/$(date +%F)
H=test
echo $H > /etc/test