Skip to content

Instantly share code, notes, and snippets.

@timhughes
Last active December 31, 2015 14:19
Show Gist options
  • Save timhughes/7999298 to your computer and use it in GitHub Desktop.
Save timhughes/7999298 to your computer and use it in GitHub Desktop.
Install a puppet master with Apache and Passenger using puppet modules. This script works nicely on a CentOS 6 install.
#!/bin/bash
hostname $1
grep -q '^HOSTNAME' /etc/sysconfig/network && sed -i "s/HOSTNAME=.*$/HOSTNAME=$(hostname -f)/g" /etc/sysconfig/network || echo "HOSTNAME=$(hostname -f)" >> /etc/sysconfig/network
grep -q '^search' /etc/resolv.conf && sed -i "s/search=.*/search $(hostname -d)/g" /etc/resolv.conf || echo "search $(hostname -d)" >> /etc/resolv.conf
echo $(hostname -i|awk '{print $1}') $(hostname) >> /etc/hosts && cat /etc/hosts|uniq > /etc/hosts_tmp && /bin/mv /etc/hosts_tmp /etc/hosts
system-config-network-cmd -i <<EOF
DeviceList.Ethernet.eth0.BootProto=static
DeviceList.Ethernet.eth0.Device=eth0
DeviceList.Ethernet.eth0.IP=$(hostname -i)
DeviceList.Ethernet.eth0.Netmask=255.255.255.0
DeviceList.Ethernet.eth0.OnBoot=True
EOF
# Need to fix this. We should be able to run puppet aunder selinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0
TMP_WORK=$(mktemp -d)
TMP_MODULE_DIR=$(mktemp -d)
cd $TMP_WORK
echo $TMP_MODULE_DIR
urlgrabber https://github.com/timhughes/puppet-selinux/archive/master.zip
python -c "import zipfile;zipfile.ZipFile('master.zip').extractall('.')"
/bin/rm master.zip
mv * $TMP_MODULE_DIR/selinux
urlgrabber https://github.com/timhughes/puppet-apache_httpd/archive/master.zip
python -c "import zipfile;zipfile.ZipFile('master.zip').extractall('.')"
/bin/rm master.zip
mv * $TMP_MODULE_DIR/apache_httpd
urlgrabber https://github.com/timhughes/puppet-puppet/archive/master.zip
python -c "import zipfile;zipfile.ZipFile('master.zip').extractall('.')"
/bin/rm master.zip
mv * $TMP_MODULE_DIR/puppet
urlgrabber https://github.com/timhughes/timhughes-repos/archive/master.zip
python -c "import zipfile;zipfile.ZipFile('master.zip').extractall('.')"
/bin/rm master.zip
mv * $TMP_MODULE_DIR/repos
cat <<EOF > $TMP_WORK/manifest.pp
include repos::epel
include repos::centos
include repos::puppetlabs
include puppet::agent
class { '::puppet::master':
runtype => 'passenger'
}
EOF
yum -y localinstall http://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm
yum -y install puppet
# this creates the certificates that apache will need to start
puppet cert generate $(hostname)
puppet apply --modulepath=$TMP_MODULE_DIR $TMP_WORK/manifest.pp
chkconfig iptables on
service iptables start
LINENUM=$(iptables -nL INPUT --line-numbers |grep dpt:22|awk '{print $1}')
iptables -I INPUT $(( $LINENUM + 1 )) -m state --state NEW -m tcp -p tcp --dport 8140 -j ACCEPT
service iptables save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment