1

Reviewing cloudinit configs on my new Lightsail VM, it seems to be talking to a metadata API for settings like hostname. I don't see any lightsail UI component to set the hostname, but if I poke at the ec2 metadata from the VM, I see some user-data. Is there any way to write to it so that cloudinit won't override a hostname I set?

EDIT:

Looks like Lightsail has its own purpse for user-data:

$ cat /var/lib/cloud/instances/user-data.txt

#!/bin/sh
echo Lightsail: Starting Instance Initialization.

cat > /etc/ssh/lightsail_instance_ca.pub << EOF
ssh-rsa nope EOF
echo Lightsail: SSH CA Public Key created. 

echo >> /etc/ssh/sshd_config
echo 'TrustedUserCAKeys /etc/ssh/lightsail_instance_ca.pub' >> /etc/ssh/sshd_config
echo Lightsail: SSH CA Public Key registered.

service sshd restart
echo Lightsail: sshd restarted.

#cloud-config
hostname: pwnguin

So in cloud-init output log, it complains about hostname: command not found. I can probably put a shell command to set a hostname, but I might be out of luck on the cloudconfig route.

Ward - Trying Codidact
  • 12,899
  • 28
  • 46
  • 59
jldugger
  • 14,342
  • 20
  • 77
  • 129

1 Answers1

2

When launching your instance, you can pass the user-data containing your initial configuration (eg. hostname) as follows:

aws lightsail create-instances --instance-names <value> --availability-zone <value> --blueprint-id <value> --bundle-id <value> --user-data file:///full/path/to/myconfig

The content of myconfig file should be:

#cloud-config
hostname: test-vm
jldugger
  • 14,342
  • 20
  • 77
  • 129
Alaa Chatti
  • 406
  • 2
  • 6
  • ah, I see. the ubuntu packaged version didn't have lightsail commands. Since they just launched this month, probably. Will test out and report back! – jldugger Dec 29 '16 at 21:33
  • You should install the latest aws cli version: sudo pip install -U awscli. Then you would be able to execute this command – Alaa Chatti Dec 29 '16 at 21:52
  • Welp, that's unfortunate. Lightsail is already using user-data for a few things. Will update question. – jldugger Dec 30 '16 at 05:28
  • @jldugger Yes it does have default initial config, but you should know that setting your own config should be done at launch time. So for now, what you can do is to manually set the hostname, and in the future that's how you can instantiate the instance. One other thing, the user-data format could be either a cloud config (starts with #cloud-config) or a shell script (starts with #!) – Alaa Chatti Dec 30 '16 at 09:30