Skip to content

Instantly share code, notes, and snippets.

@jctanner
Last active February 8, 2018 21:25
Show Gist options
  • Select an option

  • Save jctanner/e2ec39bda36d9a848422718127091711 to your computer and use it in GitHub Desktop.

Select an option

Save jctanner/e2ec39bda36d9a848422718127091711 to your computer and use it in GitHub Desktop.
openshift lab
  1. sudo ./make_openshift_cluster.sh
  2. sed -i.bak 's/^ose.*//g' ~/.ssh/known_hosts
  3. ./create_admin_inventory.sh
  4. ansible-playbook -v -i inventory.admin prepare_vms.yml
  5. ./run_os_ansible.sh
#!/bin/bash
HOSTS=$(cat /etc/hosts | fgrep "ose3" | awk '{print $2}')
cat /dev/null > inventory.admin
for HOST in $HOSTS; do
echo "$HOST ansible_ssh_pass=redhat1234" >> inventory.admin
done
#!/bin/bash -x
# 373 virt-clone --connect qemu:///system --original template_centos_7 --name EL7TEMPLATE --file /var/lib/libvirt/images/EL7TEMPLATE.qcow2
# 374 virsh list
# 375 virsh list --all
# 376 virt-sysprep -d EL7TEMPLATE
NODES="ose3-master1.test.example.com ose3-master2.test.example.com ose3-master3.test.example.com"
NODES="$NODES ose3-node1.test.example.com ose3-node2.test.example.com"
NODES="$NODES ose3-infra1.test.example.com ose3-infra2.test.example.com"
NODES="$NODES ose3-lb.test.example.com"
#NODES="$NODES ose3-nfs-ansible.test.example.com"
TEMPLATE="template_centos_7"
IMAGE_DIR="/var/lib/libvirt/images"
IMAGE_PASSWORD="redhat1234"
function deletenode {
echo "deleting $1"
virsh dumpxml --domain $1 | fgrep 'source file'
RC=$?
if [[ $RC == 0 ]]; then
SOURCE_FILE=$(virsh dumpxml --domain $1 | fgrep 'source file' | cut -d\' -f2)
virsh shutdown --domain $1
virsh destroy --domain $1
virsh undefine --domain $1
rm -f $SOURCE_FILE
fi
}
function create {
echo "creating $1"
virt-clone --connect qemu:///system --original $TEMPLATE --name $1 --file $IMAGE_DIR/$1.qcow2
virsh setmaxmem $1 4G --config
virsh setmem $1 4G --config
virt-sysprep -d $1 --hostname $1 --root-password password:$IMAGE_PASSWORD
virsh start $1
}
#function getvmip {
# SHORT_NAME=$(echo $1 | cut -d\. -f1)
# THISIP=$(virsh net-dhcp-leases default | fgrep $SHORT_NAME | awk '{print $5}' | cut -d\/ -f1)
# echo $THISIP
#}
function getvmip {
THISIP=$(virsh domifaddr $1 | fgrep 'ipv4' | awk '{print $NF}' | cut -d\/ -f1)
echo $THISIP
}
function set_hostname_in_hosts {
fgrep $1 /etc/hosts
RC=$?
if [[ $RC != 0 ]]; then
echo "$2 $1" >> /etc/hosts
else
sed -i.bak "s/.*${1}//" /etc/hosts
echo "$2 $1" >> /etc/hosts
fi
}
for NODE in $NODES; do
echo $NODE
deletenode $NODE
done
for NODE in $NODES; do
echo $NODE
create $NODE
done
for NODE in $NODES; do
echo $NODE
NODEIP=$(getvmip $NODE)
while [[ $NODEIP == "" ]]; do
echo "waiting for $NODE to obtain an ip ..."
sleep 2
NODEIP=$(getvmip $NODE)
done
echo "$NODE $NODEIP"
set_hostname_in_hosts $NODE $NODEIP
done
# this forces libvirt's dnsmasq to pick up the hosts entries and make them resolvable
systemctl restart libvirtd
- name: get the pubkey info
hosts: localhost
gather_facts: False
tasks:
- name: create local admin inventory
slurp:
src: ~/.ssh/id_ecdsa.pub
register: pubkey_data
- debug: var=pubkey_data
- name: set the pubkey in authorized_keys on all nodes
hosts: all
user: root
gather_facts: False
tasks:
- shell: hostname; whoami
- name: create the .ssh directory
file:
path: /root/.ssh
state: directory
mode: 0700
owner: root
group: root
- name: make the authorized_keys file
copy:
content: "{{ hostvars['localhost']['pubkey_data']['content'] | b64decode }}"
dest: /root/.ssh/authorized_keys
mode: 0700
owner: root
group: root
#!/bin/bash
UPSTREAM_INV="https://raw.githubusercontent.com/sdodson/openshift-ansible/e16158c2ec95ed4ccc3fa8888b78df2776c50649/inventory/hosts.example"
EXTRA_ARGS="-vvv"
#EXTRA_ARGS="$EXTRA_ARGS --forks=1"
if [ ! -d openshift-ansible ]; then
git clone https://github.com/openshift/openshift-ansible
fi
cd openshift-ansible
cd inventory
mv hosts.example hosts.example.orig
wget https://raw.githubusercontent.com/sdodson/openshift-ansible/e16158c2ec95ed4ccc3fa8888b78df2776c50649/inventory/hosts.example
sed -i.bak 's/ose-lb/ose3-lb/g' hosts.example
sed -i.bak 's/openshift_master_cluster_hostname=ose3-lb.test.example./openshift_master_cluster_hostname=ose3-lb.test.example.com/g' hosts.example
echo 'openshift_disable_check=disk_availability,memory_availability,docker_storage' >> hosts.example
cd ..
#exit 0
ansible-playbook $EXTRA_ARGS -i inventory/hosts.example playbooks/prerequisites.yml
RC=$?
if [[ $RC != 0 ]]; then
exit $RC
fi
#exit 0
ansible-playbook $EXTRA_ARGS -i inventory/hosts.example playbooks/deploy_cluster.yml
RC=$?
if [[ $RC != 0 ]]; then
exit $RC
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment