Skip to content

Instantly share code, notes, and snippets.

@cmcornejocrespo
Created July 20, 2018 16:42
Show Gist options
  • Save cmcornejocrespo/901ec849d3e8ac42b8f054268a873599 to your computer and use it in GitHub Desktop.
Save cmcornejocrespo/901ec849d3e8ac42b8f054268a873599 to your computer and use it in GitHub Desktop.
#!/bin/bash
## see: https://youtu.be/aqXSbDZggK4
export DOMAIN=${DOMAIN:="$(curl ipinfo.io/ip).nip.io"}
export USERNAME=${USERNAME:="$(whoami)"}
export PASSWORD=${PASSWORD:=password}
export VERSION=${VERSION:="v3.9.0"}
export BRANCH=${BRANCH:=release-3.9}
export METRICS=${METRICS:="False"}
export LOGGING=${LOGGING:="False"}
export SCRIPT_REPO=${SCRIPT_REPO:="https://raw.githubusercontent.com/cmcornejocrespo/installcentos/master"}
export IP=${IP:="$(ip route get 8.8.8.8 | awk '{print $NF; exit}')"}
export API_PORT=${API_PORT:="8443"}
echo "******"
echo "* Your domain is $DOMAIN "
echo "* Your IP is $IP "
echo "* Your username is $USERNAME "
echo "* Your password is $PASSWORD "
echo "* OpenShift version: $VERSION "
echo "* OpenShift branch: $BRANCH "
echo "* OpenShift metrics version: $METRICS_VERSION "
echo "* OpenShift logging version: $LOGGING_VERSION "
echo "******"
# install the following base packages
yum install -y git zile nano net-tools docker-1.13.1\
bind-utils iptables-services \
bridge-utils bash-completion \
kexec-tools sos psacct openssl-devel \
httpd-tools NetworkManager \
python-cryptography python2-pip python-devel python-rhsm-certificates python-passlib \
java-1.8.0-openjdk-headless "@Development Tools"
#install epel
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# Disable the EPEL repository globally so that is not accidentally used during later steps of the installation
sed -i -e "s/^enabled=1/enabled=0/" /etc/yum.repos.d/epel.repo
systemctl | grep "NetworkManager.*running"
if [ $? -eq 1 ]; then
systemctl start NetworkManager
systemctl enable NetworkManager
fi
# install the packages for Ansible
yum -y --enablerepo=epel install ansible pyOpenSSL
[ ! -d openshift-ansible ] && git clone https://github.com/openshift/openshift-ansible.git
cd openshift-ansible && git fetch && git checkout ${BRANCH} && cd ..
cat <<EOD > /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
${IP} $(hostname) console console.${DOMAIN}
EOD
if [ -z $DISK ]; then
echo "Not setting the Docker storage."
else
cp /etc/sysconfig/docker-storage-setup /etc/sysconfig/docker-storage-setup.bk
echo DEVS=$DISK > /etc/sysconfig/docker-storage-setup
echo VG=DOCKER >> /etc/sysconfig/docker-storage-setup
echo SETUP_LVM_THIN_POOL=yes >> /etc/sysconfig/docker-storage-setup
echo DATA_SIZE="100%FREE" >> /etc/sysconfig/docker-storage-setup
systemctl stop docker
rm -rf /var/lib/docker
wipefs --all $DISK
docker-storage-setup
fi
systemctl restart docker
systemctl enable docker
if [ ! -f ~/.ssh/id_rsa ]; then
ssh-keygen -q -f ~/.ssh/id_rsa -N ""
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh -o StrictHostKeyChecking=no root@$IP "pwd" < /dev/null
fi
memory=$(cat /proc/meminfo | grep MemTotal | sed "s/MemTotal:[ ]*\([0-9]*\) kB/\1/")
if [ $METRICS = "True" ] && [ "$memory" -lt "4194304" ]; then
echo Not enough memory, disabling metrics...
export METRICS="False"
fi
if [ $LOGGING = "True" ] && [ "$memory" -lt "8388608" ]; then
echo Not enough memory, disabling logging...
export LOGGING="False"
fi
curl -o inventory.download $SCRIPT_REPO/inventory.ini
envsubst < inventory.download > inventory.ini
ansible-playbook -i inventory.ini openshift-ansible/playbooks/prerequisites.yml
ansible-playbook -i inventory.ini openshift-ansible/playbooks/deploy_cluster.yml
htpasswd -b /etc/origin/master/htpasswd ${USERNAME} ${PASSWORD}
htpasswd -b /etc/origin/master/htpasswd system admin
/usr/local/bin/oc adm policy add-cluster-role-to-user cluster-admin ${USERNAME}
/usr/local/bin/oc adm policy add-cluster-role-to-user cluster-admin system
rm -f /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt
systemctl restart origin-master-api
echo "******"
echo "* Your console is https://console.$DOMAIN:$API_PORT"
echo "* Your username is $USERNAME "
echo "* Your password is $PASSWORD "
echo "*"
echo "* Login using:"
echo "*"
echo "$ oc login -u ${USERNAME} -p ${PASSWORD} https://console.$DOMAIN:$API_PORT/"
echo "******"
/usr/local/bin/oc login -u ${USERNAME} -p ${PASSWORD} https://console.$DOMAIN:$API_PORT/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment