Note to Reader: I have put a lot of thought into these scripts, they represent my work over the free time that I have in the past two weeks! ~ Please Enjoy and Use the code as you see most adequate. Thanks for looking.
I thought about putting a Auo-Install scripts for the differing node types and differing amount of nodes present in each persons cluster, (thinking preferences), I wanted say more database nodes for big couch. I would just need to add a few more couch nodes right?, well what I I wanted to redo the entire cluster with different number of node types based on pr-existing VM installs of CentOS 6? (with Elastic IP addresses already and NS records pointing to them of course).
This Addon helper type installation script is run on each node; simply is a ALPHA model where it create a ssh and grabs identical chef types for itself then installs the non-type model from the identical model. There is a great many improvements if I can get the above change to the above arrayed code over the ALPHA code. The ALPHA is rough and does the job, but theres hardly any automation and no user prompts.
node: that ssh cret is for example only(you need to make one)
ALPHA_CODE
#/bin/bash!
read -n20 -e -s -p "Enter name of server node: "
if [[ ! $REPLY =~ ^[app]$ ]]
then
echo -e "OK! \nnode_dn = $REPLY"
node_dn=$REPLY
node_hn="${node_dn%%.*}"
echo "node_hn = $node_hn"
node_type="${node_hn%%[0-9]*}"
echo "node_type = $node_type"
fi
echo "creating private key"
#wait 2
touch /root/.ssh/dropbear_rsa_host_private_key.key
echo -n "-----BEGIN RSA PRIVATE KEY-----
ssh-dss AAAAB3NzaC1kc3MAAACBAN431nwhJuE5F5HhsTVS7WlSCH1dn/vaPOZQ6WOBvCYIY6k97UkW
XbsLjKIBz2P/jaL2w92U72cUmKiXgVFaxP7LgRylF0UHjFoPfbbesY2isfdHTgGnbmJDOui+RHGNiLl6
f62q0mPIZQxyq6SSyqLD6NiO3IlyrsCSXAerkrdxAAAAFQD7wt2MuZU27cF4oOd6puEcm/jl7wAAAIEA
vQvsiBcgEVvlAIMnZlP2QdO2O96p0wlCoHmKS8WYhwiAEB4QsLypM9ZQ/yG4HO7p9y7gcgo8cyUo/9jd
pOMKAWVJSsujqqH0VBLHZVD5tdBPG4p4i3uws6my2z2AQARMfKN9L/uSmfEi69sDy6JkEah27yOp3zVh
xZInM/hFrVcAAACBAL9K78gikerCL/LFLK4FkQp56drqx2WmubrAuG9SmnPpRQR5SNoA6lYI3CRttLHT
540XW0PYDz53NnBc3C3/v3EE4nokyyUw783mWKbAbI6+jtibViUhfJwbi7xLB2TVyeWMBeHArsxkfHyO
zFyjC4Db4UrmU71tYQfOlzmIipf7 USERNAME@shell.yourdomain.com
-----END RSA PRIVATE KEY-----" >/root/.ssh/dropbear_rsa_host_private_key.key
chmod 0700 /root/.ssh/dropbear_rsa_host_private_key.key
echo "Syncing servers and entering $node_dn"
#wait 1
rsync --delete -auve 'ssh -i /root/.ssh/dropbear_rsa_host_private_key.key' chefsolotest1.yourdomain.com:/ /
# [[ $node_name = *$name* ]]
#[[ $entered_name = *"$small_name"* ]]; echo $?
# user="foo47.example.com"; echo "${user%%0-9*}"
#foo="app123.example.com"; foo_hn="${foo%%.*}"; echo "foo_hn = $foo_hn"; foo_type="${foo_hn%%[0-9]*}"; echo "$foo_type"
# Note:foo_type="${foo_hn%[0-9]*}" will only remove the 3 or node9cluster03 so use exit glob ${var%+([0-9])}
echo "setting /etc/hosts and /etc/sysconfig/network files and running hostname $node_hn to reflect fqdn."
#wait 2
ex -sc '%s/chefsolotest1/'$node_hn'/g|x' /etc/hosts
ex -sc '%s/chefsolotest1/'$node_hn'/g|x' /etc/sysconfig/network
hostname "$node_hn"
echo "running special node configuration based on node_type = $node_type"
case $node_type in
fs)
echo -n '{
"client_id": "foo",
"erlang_cookie": "cookiemonster",
"couchdb_username": "foo",
"couchdb_plaintext_password": "bar",
"run_list": [ "role[winkstart_deploy_whistle_fs]" ]
}' >/root/chef_server_setup/node.json
echo "This is a Freeswitch based Media_Server_Node"
;;
apps)
echo "This is a Whapps/OpenSIP based Application_Server_Node"
echo -n '{
"client_id": "foo",
"erlang_cookie": "cookiemonster",
"couchdb_username": "bar",
"couchdb_plaintext_password": "bar",
"run_list": [ "role[winkstart_deploy_haproxy]", "role[winkstart_deploy_whapps]", "recipe[apache2::winkstart]", "recipe[winkstart]", "role[winkstart_deploy_opensips]" ]
}' >/root/chef_server_setup/node.json
;;
db)
echo -n '{
"client_id": "foo",
"erlang_cookie": "cookiemonster",
"couchdb_username": "foo",
"couchdb_plaintext_password": "bar",
"run_list": [ "role[winkstart_deploy_bigcouch]" ]
}' >/root/chef_server_setup/node.json
echo "This is a CouchDB based DataBase_Server_Node"
;;
esac
echo -n '{
"freeswitch": {
"servers": {
"fs01.yourdomain.com": "fs01.yourdomain.com",
"fs02.yourdomain.com": "fs02.yourdomain.com"
}
},
"id": "kazoo01",
"whapps": {
"servers": {
"apps01.yourdomain.com": "apps01.yourdomain.com",
"apps02.yourdomain.com": "apps02.yourdomain.com",
"apps03.yourdomain.com": "apps03.yourdomain.com"
}
},
"opensips": {
"servers": {
"apps01.yourdomain.com": "apps01.yourdomain.com",
"apps02.yourdomain.com": "apps02.yourdomain.com",
"apps03.yourdomain.com": "apps03.yourdomain.com"
}
},
"bigcouch": {
"servers": {
"db01.yourdomain.com": "db01.yourdomain.com",
"db02.yourdomain.com": "db02.yourdomain.com",
"db03.yourdomain.com": "db03.yourdomain.com",
"db04.yourdomain.com": "db04.yourdomain.com"
}
}
}' >/root/chef_server_setup/kazoo01.json
chmod 0775 /root/chef_server_setup/kazoo01.json
cp /root/chef_server_setup/kazoo01.json /root/data_bags/accounts
source /etc/profile
reboot
END_ALPHA_CODE
This is a new script, and it is a first attempt at furthering Automation, this means its just setting up the array.
This is a first attempt bias at an install script :
note: this is a WIP, I propose this for some simple attachment; or method of calling the ALPHA script above^^ ~ty
read -p "How many server/node types in each cluster?"$'\n'"Enter#:" node
case $node in
[]|0|00) exit;;
[]|01|02|03|04|05|06|07|08|09|10) ;;
*) echo "Please enter a number."$'\n'"Remember to type in the format 0$node not just $node"; exit;;
esac
read -p "How many servers are in each cluster?"$'\n'"Enter#:" num
case $num in
[]|0|00) exit;;
[]|01|02|03|04|05|06|07|08|09|10) ;;
* ) echo "Please enter a number."$'\n'"Remember to type in the format 01 not just 1";;
esac
read -p "How many servers should concaternate into the cluster now?"$'\n'"(#num of servers to start with?)"$'\n'"Don't worry the prompt will remind you how many are left periodically."$'\n'"Note: If you choose less than the total now:($num),"$'\n'" They will be saved later because. . ."$'\n'"They will be used for Server_Optmization!"$'\n'"Enter#:" opt
case $opt in
[]|0|00) exit;;
[]|01|02|03|04|05|06|07|08|09|10) ;;
* ) echo "Please enter a number between 0-$num"$'\n'"Remember to type in the format 01 not just 1";;
esac
read -p "Now, what is the node type/name?"$'\n'"Enter#:" typ
echo "node=$node"
echo "num=$num"
echo "opt=$opt"
echo "typ=$typ"
prime=$(( 10#$num-10#$opt ))
avl=$opt
while [ $avl != 0 ]; do
read -p "How many servers in the $typ node type?"$'\n'"$avl available."$'\n'"Type 0 to stop allocating." count
case $count in
[]|0|00) exit;;
[]|01|02|03|04|05|06|07|08|09|10) ;;
* ) echo "Please enter an number between 0-$avl"$'\n'"Remember to type in the format 01 not just 1";;
esac
avl=$(( 10#$avl-10#$count ))
read -p "Are there More node types (y/n)?" yn
case $yn in
[Yy]* ) ;;
[Nn]* ) exit;;
* ) echo "Please anwser yes or no";;
esac
read -p "$avl available for nodes."$'\n'"$prime saved for later?"$'\n'"Is this correct? (y/n)" yn
case $yn in
[Yy]* ) ;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
echo "$avl nodes left to allocate to servers."
read -p "Finaly, enter the domain name of cluster." dom
echo "There are [$node] servers in a cluster."$'\n'"Typical hostnames range from [$typ][$count].[$dom] for fqdn."$'\n'"[$prime] are still un allocated and therefore available as nodes." ; <<< [1][abc][1][abc]
done
END_BETA_CODE_1
I have other functional models that simply grab the install script from a predetermined reference installation node of non-type like the ALPHA. But these types are run without the chef solo parts running,
So, to attempt a solution in combination that auto arranges how many nodes there names and size and scope of the cluster!
It is this reasoning that I created the below code: the kazoo installation can start afresh chef install for any node type.
