Skip to content

Instantly share code, notes, and snippets.

@Miciah
Created May 2, 2018 18:37
Show Gist options
  • Save Miciah/7dc8381116317fe1d2113c000adfe702 to your computer and use it in GitHub Desktop.
Save Miciah/7dc8381116317fe1d2113c000adfe702 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
name="$(find ~/tmp -name mmasters\* |
awk '{ match($0,"([0-9]+)$",arr); if (arr[1] > n) { n = arr[1] } }
END { print "mmasters" strtonum(n+1) }')"
mkdir ~/tmp/"$name"
cd ~/tmp/"$name"
# To obtain a token, 'visit https://console.reg-aws.openshift.com and click
# "Google" to provision your user. After you’re logged in using Google, click
# the question mark (?) on the top right-hand side of the console, then click
# "Command Line Tools" to get your token.'
#
# Token generated on 2018-04-25.
~/src/github.com/openshift/aos-ansible/bin/aws-launcher launch \
--masters 1 \
--username "$name" \
--registry-token 'REDACTED'
#read -p 'Press Enter to continue...'
sleep 3m
# XXX Comment this out if not installing 3.9.
# Set the release to OCP 3.9.
sed -i -e '/^\[OSEv3:vars\]$/a \
openshift_version=3.9\
openshift_release=3.9\
openshift_image_tag=v3.9.27\
openshift_pkg_version=-3.9.27
' hosts
ansible all -i hosts -m copy -a 'src=/home/mmasters/tmp/rhel-7-server-ose-3.9-rpms.repo dest=/etc/yum.repos.d/rhel-7-server-ose-3.9-rpms.repo'
# Make sure we can use the ops registry.
sed -i -e '/^\[OSEv3:vars\]$/a \
cli_docker_additional_registries=registry.ops.openshift.com
' hosts
# Disable checks that are expected to fail in an AWS devenv.
sed -i -e '/^\[OSEv3:vars\]$/a \
openshift_disable_check=disk_availability,memory_availability,package_version,docker_image_availability,sdn
' hosts
# Make sure we can use the ops registry.
sed -i -e '/^\[OSEv3:vars\]$/a \
cli_docker_additional_registries=registry.ops.openshift.com
' hosts
# Disable the service catalog.
sed -i -e '/^\[OSEv3:vars\]$/a \
openshift_enable_service_catalog=false
' hosts
# Set parameters for logging in case the user enables it.
public_ip_addr="$(grep -o -P -e '(?<=openshift_public_ip=)\S+' -m1 hosts)"
sed -i -e '/^\[OSEv3:vars\]$/a \
openshift_logging_kibana_hostname=kibana.'"$public_ip_addr"'.xip.io\
openshift_logging_elasticsearch_memory_limit=512Mi\
openshift_client_binary=/bin/oc
' hosts
# Enable extended validation of routes.
sed -i -e '/^\[OSEv3:vars\]$/a \
openshift_hosted_router_extended_validation=true
' hosts
# Add some swap since this instance has limited memory and is not production.
# (OpenShift Origin is sometimes not even able to compile with only 4GiB RAM.)
ansible-playbook -i hosts ~/src/ansible/add_swap.yaml -e swap_size=4096
# See <https://github.com/openshift/aos-ansible/commit/4ab7091f85f6163057d91472980560108d69341c#r25904302>.
#sed -i -e '/openshift_docker_additional_registries/s/$/:443/' hosts
#sed -i -e '/:443/!s/registry.reg-aws.openshift.com/&:443/' hosts
# I'd use the package module, but (a) it requires facts and (b) I cannot figure
# out how to do with_items using an ad hoc command.
#ansible -i hosts -m package -a 'name="{{ item }}" state=latest with_items=["iptables","iptables-services"]'
#ansible all -i hosts -m package -a 'name=iptables state=latest'
#ansible all -i hosts -m package -a 'name=iptables-services state=latest'
ansible all -i hosts -m command -a 'yum install -y iptables iptables-services docker docker-client docker-rhel-push-plugin'
# Prepare the host, configured to pull from the reg-aws registry.
ansible-playbook -i hosts \
~/src/github.com/openshift/aos-ansible/playbooks/aws_install_prep.yml \
# -e reg_username='[email protected]' \
# -e reg_password='REDACTED' \
# -e reg_name='registry.reg-aws.openshift.com:443' \
# -e reg_openshift_prefix='registry.reg-aws.openshift.com:443/openshift3/ose-${component}:${version}'
# Install prerequisites. The playbook has existed since 3.7 (as a placeholder)
# and has been a required step since 3.9.
ansible-playbook -i hosts \
~/src/github.com/openshift/openshift-ansible/playbooks/prerequisites.yml
# Run the installer. First try the new filename (in 3.9 and later).
install_playbook=~/src/github.com/openshift/openshift-ansible/playbooks/deploy_cluster.yml
# If that fails, try the old path name (before 3.9).
if [[ ! -e "$install_playbook" ]]
then install_playbook=~/src/github.com/openshift/openshift-ansible/playbooks/byo/config.yml
fi
if [[ ! -e "$install_playbook" ]]
then
echo 'Cannot find the install playbook.'
exit 1
fi
ansible-playbook -i hosts "$install_playbook"
# Need to restart dbus in order for dnsmasq to start, and need to restart
# systemd-logind after restarting dbus.
# XXX Proper solution would probably be to reboot.
ansible all -i hosts -m systemd -a 'state=restarted name=dbus'
ansible all -i hosts -m systemd -a 'state=restarted name=systemd-logind'
ansible all -i hosts -m systemd -a 'state=restarted name=dnsmasq'
echo "Launched ${name}."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment