зеркало из https://github.com/mozilla/hubs-ops.git
Dynamic hostnames
This commit is contained in:
Родитель
87aadef85e
Коммит
50820eef71
|
@ -26,15 +26,29 @@
|
|||
"ami_name": "hab-base-{{timestamp}}"
|
||||
}],
|
||||
"provisioners": [
|
||||
{ "type": "file", "source": "../shared/files/hostname-adjectives", "destination": "hostname-adjectives" },
|
||||
{ "type": "file", "source": "../shared/files/hostname-nouns", "destination": "hostname-nouns" },
|
||||
{ "type": "file", "source": "../shared/files/set_hostname.sh", "destination": "set_hostname.sh" },
|
||||
{ "type": "file", "source": "../shared/files/set_host_type_prompt.sh", "destination": "set_host_type_prompt.sh" },
|
||||
{ "type": "file", "source": "../shared/files/set-hostname.service", "destination": "set-hostname.service" },
|
||||
{
|
||||
"type": "shell",
|
||||
"execute_command": "echo 'packer' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'",
|
||||
"inline": [
|
||||
"apt-get update",
|
||||
"apt install -y unattended-upgrades python awscli jq",
|
||||
"mv hostname-nouns /usr/share/dict",
|
||||
"mv hostname-adjectives /usr/share/dict",
|
||||
"mv set_host_type_prompt.sh /usr/bin",
|
||||
"mv set_hostname.sh /usr/bin",
|
||||
"mv set-hostname.service /etc/systemd/system/default.target.wants",
|
||||
"chown root:root /etc/systemd/system/default.target.wants/set-hostname.service",
|
||||
"chown root:root /usr/share/dict/hostname-nouns",
|
||||
"chown root:root /usr/share/dict/hostname-adjectives",
|
||||
"chown root:root /usr/bin/set_hostname.sh",
|
||||
"chown root:root /usr/bin/set_host_type_prompt.sh",
|
||||
"chmod +x /usr/bin/set_host_type_prompt.sh",
|
||||
"chmod +x /usr/bin/set_hostname.sh",
|
||||
"echo \". /usr/bin/set_host_type_prompt.sh\" >> /home/ubuntu/.bashrc",
|
||||
"echo \". /usr/bin/set_host_type_prompt.sh\" >> /root/.bashrc"
|
||||
]
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
admiring
|
||||
adoring
|
||||
affectionate
|
||||
agitated
|
||||
amazing
|
||||
angry
|
||||
awesome
|
||||
blissful
|
||||
boring
|
||||
brave
|
||||
clever
|
||||
cocky
|
||||
compassionate
|
||||
competent
|
||||
condescending
|
||||
confident
|
||||
cranky
|
||||
dazzling
|
||||
determined
|
||||
distracted
|
||||
dreamy
|
||||
eager
|
||||
ecstatic
|
||||
elastic
|
||||
elated
|
||||
elegant
|
||||
eloquent
|
||||
epic
|
||||
fervent
|
||||
festive
|
||||
flamboyant
|
||||
focused
|
||||
friendly
|
||||
frosty
|
||||
gallant
|
||||
gifted
|
||||
goofy
|
||||
gracious
|
||||
happy
|
||||
hardcore
|
||||
heuristic
|
||||
hopeful
|
||||
hungry
|
||||
infallible
|
||||
inspiring
|
||||
jolly
|
||||
jovial
|
||||
keen
|
||||
kind
|
||||
laughing
|
||||
loving
|
||||
lucid
|
||||
mystifying
|
||||
modest
|
||||
musing
|
||||
naughty
|
||||
nervous
|
||||
nifty
|
||||
nostalgic
|
||||
objective
|
||||
optimistic
|
||||
peaceful
|
||||
pedantic
|
||||
pensive
|
||||
practical
|
||||
priceless
|
||||
quirky
|
||||
quizzical
|
||||
relaxed
|
||||
reverent
|
||||
romantic
|
||||
sad
|
||||
serene
|
||||
sharp
|
||||
silly
|
||||
sleepy
|
||||
stoic
|
||||
stupefied
|
||||
suspicious
|
||||
tender
|
||||
thirsty
|
||||
trusting
|
||||
unruffled
|
||||
upbeat
|
||||
vibrant
|
||||
vigilant
|
||||
vigorous
|
||||
wizardly
|
||||
wonderful
|
||||
xenodochial
|
||||
youthful
|
||||
zealous
|
||||
zen
|
|
@ -0,0 +1,33 @@
|
|||
ardent
|
||||
artificer
|
||||
balrog
|
||||
barbarian
|
||||
bard
|
||||
cleric
|
||||
druid
|
||||
dwarf
|
||||
elf
|
||||
ent
|
||||
fighter
|
||||
giant
|
||||
goblin
|
||||
halfling
|
||||
hobbit
|
||||
illusionist
|
||||
invoker
|
||||
mage
|
||||
monk
|
||||
mystic
|
||||
orc
|
||||
paladin
|
||||
psion
|
||||
ranger
|
||||
rogue
|
||||
seeker
|
||||
sorcerer
|
||||
thief
|
||||
troll
|
||||
vampire
|
||||
warlock
|
||||
werewolf
|
||||
wizard
|
|
@ -0,0 +1,8 @@
|
|||
[Unit]
|
||||
Description=Set Hostname and DNS
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/bash /usr/bin/set_hostname.sh
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
EXISTING_IP=""
|
||||
NEW_HOSTNAME=""
|
||||
|
||||
HOSTED_ZONE_ID="Z26OTGLBBCAHK4"
|
||||
HOSTED_ZONE_NAME="reticulum.io"
|
||||
|
||||
if [[ ! -z "$(hostname | grep $HOSTED_ZONE_NAME)" ]] ; then
|
||||
echo "Hostname already set, exiting."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
PUBLIC_IP=$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4)
|
||||
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
|
||||
REGION=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed 's/[a-z]$//')
|
||||
|
||||
attempt_generate_hostname() {
|
||||
ADJECTIVE=$(cat /usr/share/dict/hostname-adjectives | shuf | head -n1)
|
||||
NOUN=$(cat /usr/share/dict/hostname-nouns | shuf | head -n1)
|
||||
|
||||
NEW_HOSTNAME="${ADJECTIVE}-${NOUN}"
|
||||
DNS_IP=$(dig $NEW_HOSTNAME A +short)
|
||||
|
||||
if [[ ! -z "$DNS_IP" ]] ; then
|
||||
EXISTING_IP=$(aws ec2 --region $REGION describe-instances | grep $DNS_IP)
|
||||
fi
|
||||
}
|
||||
|
||||
attempt_generate_hostname
|
||||
|
||||
while [[ ! -z $EXISTING_IP ]]
|
||||
do
|
||||
attempt_generate_hostname
|
||||
done
|
||||
|
||||
echo "Setting hostname to ${NEW_HOSTNAME} and registering ${PUBLIC_IP}"
|
||||
|
||||
ROUTE53_RECORD="{ \"ChangeBatch\": { \"Changes\": [ { \"Action\": \"UPSERT\", \"ResourceRecordSet\": { \"Name\": \"${NEW_HOSTNAME}.${HOSTED_ZONE_NAME}.\", \"Type\": \"A\", \"TTL\": 900, \"ResourceRecords\": [ { \"Value\": \"$PUBLIC_IP\" } ] } } ] } }"
|
||||
|
||||
aws route53 change-resource-record-sets --hosted-zone-id "$HOSTED_ZONE_ID" --cli-input-json "${ROUTE53_RECORD}"
|
||||
aws ec2 create-tags --region $REGION --resources "${INSTANCE_ID}" --tags "Key=Name,Value=${NEW_HOSTNAME}"
|
||||
sudo hostname "$NEW_HOSTNAME.$HOSTED_ZONE_NAME"
|
Загрузка…
Ссылка в новой задаче