Skip to content

Instantly share code, notes, and snippets.

@davehughes
Last active February 1, 2019 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davehughes/1f9245c8d286e7559b36032e4f749b0a to your computer and use it in GitHub Desktop.
Save davehughes/1f9245c8d286e7559b36032e4f749b0a to your computer and use it in GitHub Desktop.
#!/bin/bash
MINION_NAME=${minion_name}
MASTER_HOST=${master_host}
# -----------------------------------------------------------------------------
# Set hostname matching minion name by updating /etc/hostname and /etc/hosts
# -----------------------------------------------------------------------------
hostnamectl set-hostname $MINION_NAME
cat > /etc/hosts <<END
127.0.0.1 localhost $MINION_NAME
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
END
# -----------------------------------------------------------------------------
# Install and configure salt-minion
# -----------------------------------------------------------------------------
# This version is HEAD on the develop branch as of 2016.09.12
BS_URL="https://raw.githubusercontent.com/saltstack/salt-bootstrap/7206d7304362ea0f143db76cacada288a89abff9/bootstrap-salt.sh"
BS_EXPECTED_MD5="8532d4a20533a2210b0a893faa354bce"
curl -sL -o /tmp/bootstrap-salt.sh "$BS_URL"
BS_ACTUAL_MD5=$(md5sum /tmp/bootstrap-salt.sh | awk '{print $1}')
if [ "$BS_EXPECTED_MD5" -ne "$BS_ACTUAL_MD5" ];
then
echo "MD5 signature mismatch, mayday!"
touch /root/.salt-md5-mismatch
exit 1
fi
BS_SALT_MASTER_ADDRESS=$MASTER_HOST bash /tmp/bootstrap-salt.sh
cat > /etc/salt/minion_id <<END
$MINION_NAME
END
cat > /etc/salt/minion <<END
master: $MASTER_HOST
hash_type: SHA256
END
service salt-minion restart
variable "minion-count" {
type = "string"
default = 1
}
data "template_file" "minionize-data" {
count = "${var.minion-count}"
template = "${file("minionize.sh.tpl")}"
vars {
minion_name = "${format("minion%02d", count.index)}"
master_host = "saltmaster.example.com"
bootstrap_key = "${aws_key_pair.minion-bootstrap.public_key}"
}
}
resource "aws_instance" "minion" {
count = "${var.minion-count}"
ami = "${var.base_ami}"
subnet_id = "${aws_subnet.my_infrastructure.id}"
instance_type = "m4.large"
vpc_security_group_ids = [
# ...
]
tags = {
Name = "${format("minion%02d", count.index)}"
}
root_block_device {
volume_type = "standard"
volume_size = 100
}
user_data = "${element(data.template_file.minionize-data.*.rendered, count.index)}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment