Skip to content

Instantly share code, notes, and snippets.

@omaciel
Last active August 29, 2015 14:13
Show Gist options
  • Save omaciel/2ee4172a55fc2b36e387 to your computer and use it in GitHub Desktop.
Save omaciel/2ee4172a55fc2b36e387 to your computer and use it in GitHub Desktop.
Install SAM on EC2
#!/usr/bin/env sh
# Install SAM on to an Amazon EC2 instance. Make sure to set the variables
# in the head of this script.
set -o errexit -o nounset
# Default user for EC2 images is "ec2-user", so switch to "root"
sudo su -
# By default the EC2 instance's hostname matches its internal hostname. The
# fields ${public_ip} and ${public_dns} can be found in the EC2 Dashboard page
# when you select your instance.
readonly public_ip=
readonly public_dns=
# Red hat username, pool ID and password.
readonly rh_username=
readonly rh_poolid=
readonly rh_password=
#-------------------------------------------------------------------------------
# Update hostname to use public dns values
echo "${public_ip} ${public_dns}" >> /etc/hosts
hostname "${public_dns}"
# Check which version of RHEL we got
if uname -r | grep -q el6; then OS_VERSION=6; else OS_VERSION=7; fi
# We need to install a few packages, so let's configure our Red Hat
# subscription and enable a repo.
subscription-manager register --force --username=${rh_username} --password=${rh_password}
subscription-manager subscribe --pool=${rh_poolid}
# Disable all existing Red Hat repositories
subscription-manager repos --disable "*"
# Enable only what we need
subscription-manager repos --enable rhel-${OS_VERSION}-server-sam-rpms
subscription-manager repos --enable rhel-${OS_VERSION}-server-rpms
# Install and start ntpd
yum install -y ntp
service ntpd start
# Install SAM
yum install -y katello-headpin-all
# Update the iptables rules
iptables -I INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT
iptables -I INPUT -m state --state NEW -p tcp --dport 5671 -j ACCEPT
iptables -I INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -m state --state NEW -p tcp --dport 8140 -j ACCEPT
iptables -I INPUT -m state --state NEW -p tcp --dport 8088 -j ACCEPT
iptables -I INPUT -m state --state NEW -p tcp --dport 9090 -j ACCEPT
iptables -I INPUT -m state --state NEW -p tcp --dport 22 -j ACCEPT
iptables-save > /etc/sysconfig/iptables
service iptables restart
# SElinux ON
setenforce 1
# Initial configuration with some defaults
katello-configure \
--deployment=sam \
--user-pass=admin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment