Created
May 30, 2018 00:01
-
-
Save rwiggins/53dcb7be6f248e37283db8283fd933b4 to your computer and use it in GitHub Desktop.
Set AWS EC2 instance hostname using cloud-config's bootcmd as userdata. Useful for autoscaling group launch configurations. Uses a prefix + instance ID, useful for Consul hosts for example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#cloud-config | |
bootcmd: | |
- HOSTNAME=my-prefix-"$INSTANCE_ID" | |
- echo "$HOSTNAME" > /etc/hostname && hostname -F /etc/hostname | |
- grep -q "127.0.0.1 $HOSTNAME" /etc/hosts || echo "127.0.0.1 $HOSTNAME" >> /etc/hosts | |
- grep -q "::1 $HOSTNAME" /etc/hosts || echo "::1 $HOSTNAME" >> /etc/hosts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment