Commit 26b1554a authored by Jens-Petter Salvesen's avatar Jens-Petter Salvesen

code for creating docker hosts en masse

parent b1826be7
# servers to create
# set this to something like export list=("083" "093")
export list=()
# set some params we'll use throughout the scripts
export postfix="-test" # set to "" for production
export os_avail_zone="osl2" #osl2,osl3,osl4 - the availability zone we're creating VMs in
export os_disk_size=0 # set to 0 for no external storage (for the g2* flavors)
export os_key_name="jeppe"
export os_flavor="gp2.medium"
export os_server_group="73d3e872-8029-4e98-86c2-944e842a6a88"
#!/usr/bin/env bash
# set this to something like export list=("083" "093")
export list=()
# abort on error
set -e
# create dir for yamls unless it already exists
mkdir -p ./yamls/
# restart the mpssh_hosts file for this run
# adding this enables us to use mpssh for shutting down the VMs
echo '%fqdns' > ./mpssh_hosts
# create yamls
# start by writing this to template.yml.
echo "#cloud-config
hostname: dockerplaceholder$postfix
fqdn: dockerplaceholder$postfix.api.c.bitbit.net
manage_etc_hosts: localhost
timezone: Europe/Oslo
bootcmd:
- ['/sbin/ifconfig', 'eth0', 'mtu', '1450']
- ['/bin/sleep','10']
- ['/sbin/pvresize', '/dev/vda2']
- ['/bin/bash','-c', 'wget -qO /root/puppetlabs-release-trusty.deb https://apt.puppetlabs.com/puppetlabs-release-trusty.deb']
- ['/usr/bin/dpkg','-i','/root/puppetlabs-release-trusty.deb']
- ['/usr/bin/apt','update']
- ['/usr/bin/apt','install','oidentd','-y']
- ['/usr/bin/apt','install','apt-transport-https','-y']
- ['/bin/bash','-c','wget -qO /root/getcert https://puppetca.i.bitbit.net/getcert']
- ['/bin/bash','/root/getcert']
- ['/usr/bin/apt','install','puppet=3.8.7-1puppetlabs1','-y']
- ['/etc/init.d/puppet','stop']
- ['/usr/bin/puppet','agent','--enable']
- ['/usr/bin/puppet','agent','-t','--server','puppet.api.c.bitbit.net','--environment','api_docker_master']
" > ./template.yml
# go over the servers in the list and create a yaml for it inside yamls/
for i in ${list[@]}; do
hostname="docker$i$postfix"
cp ./template.yml ./yamls/$hostname.api.yaml
sed -i "s/placeholder/$i/g" ./yamls/$hostname.api.yaml
sed -i "s/puppetenv/$puppetenv/g" ./yamls/$hostname.api.yaml
echo "$hostname.api.c.bitbit.net" >> ./mpssh_hosts
done
set +e
#!/usr/bin/env bash
# set this to something like export list=("083" "093")
export list=()
# abort on error
set -e
# create instances:
for i in ${list[@]};do
hostname="docker$i$postfix"
echo "making vm for $hostname"
cmd="openstack server create "
cmd+="--flavor $os_flavor "
cmd+="--user-data ./yamls/$hostname.api.yaml "
cmd+="--availability-zone $os_avail_zone "
cmd+="--port '$hostname (vlan:931)' "
cmd+="--key-name $os_key_name "
cmd+="--config-drive True "
cmd+="--hint group=$os_server_group "
cmd+="--image rlnc-ubuntu-14.04-lvm "
cmd+="$hostname.api";
eval $cmd
done
set +e
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment