Commit 8e1bb27a authored by Scotty Logan's avatar Scotty Logan
Browse files

puppet updates

parent 1c549fa8
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -3,4 +3,7 @@ forge "https://forgeapi.puppet.com"
metadata

mod 'puppetlabs-apache', :latest
mod 'puppet-systemd', :latest

mod 'derdanne-nfs', :latest

files/dns-update

0 → 100644
+98 −0
Original line number Diff line number Diff line
#! /bin/bash
# Update the Route53 record for this server

MDURL=http://169.254.169.254/latest/meta-data

set -e

if ! type aws >/dev/null; then
  echo Failed to find aws CLI >&2
  exit 0
fi

mac=$(wget -qO - ${MDURL}/mac)
ipv6=$(wget -qO - ${MDURL}/network/interfaces/macs/${mac}/ipv6s | head -1)
public_ip=$(wget -qO - ${MDURL}/public-ipv4)
instance_id=$(wget -qO - ${MDURL}/instance-id)
avail_zone=$(wget -qO - ${MDURL}/placement/availability-zone)
region=${avail_zone%[a-z]}


# we have the aws CLI
# extract tags for this EC2 instance
eval $(aws ec2 describe-tags \
    --region ${region} \
    --filter Name=resource-type,Values=instance Name=resource-id,Values=${instance_id} \
    --output text --query 'Tags[*].[Key,Value]' |\
  tr ':\011' '_=')

# use the zone ID from tags; default to the IT Lab zone
zone_id=/hostedzone/${zone:-Z11XFUMVHH2M4Z}

# if there was a hostname tag, use that value
# otherwise, use the fqdn
hostname=${hostname:-$(hostname -f)}

# if there was no tag, and hostname -f returned
# localhost, use hostname output instead
[[ ${hostname} == localhost ]] && hostname=$(hostname)

if [[ -z ${hostname} ]] || [[ ${hostname} == localhost ]]; then
  echo Did not find a usable hostname >&2
  exit 0
fi

# check hostname
if [[ $(hostname) != ${hostname} ]]; then
  # set hostname
  echo ${hostname} > /etc/hostname
  hostname ${hostname}

  # fix /etc/hosts
  echo '# created at' $(date -Iseconds)  >/etc/hosts.$$
  echo 127.0.0.1 ${hostname} localhost  >>/etc/hosts.$$
  if [[ -n ${ipv6} ]]; then
    echo '::1' ${hostname} localhost    >>/etc/hosts.$$
  fi
  egrep -v '(^#|127.0.0.1)' /etc/hosts  >>/etc/hosts.$$
  mv /etc/hosts.$$ /etc/hosts

fi

update=/tmp/route53-up.json

rm -f ${update}

cat >${update} <<ROUTE53_JSON
{
  "Changes": [{
    "Action": "UPSERT",
    "ResourceRecordSet": {
      "Name": "${hostname}",
      "Type": "A",
      "TTL": 300,
      "ResourceRecords": [ { "Value": "${public_ip}" } ]
    }
ROUTE53_JSON

if [[ -n ${ipv6} ]]; then
  cat >>${update} <<ROUTE53_JSON_IPV6
  },{
    "Action": "UPSERT",
    "ResourceRecordSet": {
      "Name": "${hostname}",
      "Type": "AAAA",
      "TTL": 300,
      "ResourceRecords": [ { "Value": "${ipv6}" } ]
    }
ROUTE53_JSON_IPV6

fi

echo '}]}' >>${update}

aws route53 change-resource-record-sets \
  --hosted-zone-id ${zone_id} \
  --change-batch file://${update}

exit 0
+18 −0
Original line number Diff line number Diff line
[Unit]
Description=Update Route53 DNS Record
After=cloud-init-local.service
After=networking.service
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/dns-update
RemainAfterExit=yes
TimeoutSec=0

# Output needs to appear in instance console output
StandardOutput=journal+console

[Install]
WantedBy=multi-user.target
+36 −0
Original line number Diff line number Diff line
@@ -8,6 +8,42 @@ class webapp (
) {
  Exec['apt_update'] -> Package<| |>

  file { '/usr/local/bin':
    ensure => directory,
    owner  => 'root',
    group  => 'root',
    mode   => '0755',
  }

  file { '/usr/local/bin/dns-update':
    ensure  => present,
    owner   => 'root',
    group   => 'root',
    mode    => '0755',
    source  => "puppet:///modules/${module_name}/dns-update",
    require => File['/usr/local/bin'],
  }
  systemd::unit_file { 'dns-update.service':
    content => file("${module_name}/dns-update.service"),
    enable  => true,
    active  => true,
    require => File['/usr/local/bin/dns-update'],
  }

  class { '::nfs':
    server_enabled => false,
    client_enabled => true,
    nfs_v4_client => true,
  }

  nfs::client::mount { '/efs':
    ensure      => 'mounted',
    server      => 'fs-85ab5b2c.efs.us-west-2.amazonaws.com',
    share       => '/',
    options_nfs => '_netdev,nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2',
    atboot      => true,
  }

  class { 'apache':
    service_enable      => false,
    service_ensure      => false,