Adding puppet3-agent scripts

Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/80fe499d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/80fe499d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/80fe499d

Branch: refs/heads/master
Commit: 80fe499db614e1bf97979669d80a463b10651f21
Parents: 301d865
Author: Melan Nimesh <[email protected]>
Authored: Thu Feb 27 14:10:52 2014 +0530
Committer: Melan Nimesh <[email protected]>
Committed: Thu Feb 27 14:10:52 2014 +0530

----------------------------------------------------------------------
 tools/puppet3-agent/config.sh                   |  94 +++++
 tools/puppet3-agent/init.sh                     | 142 +++++++
 tools/puppet3-agent/puppetinstall/puppetinstall | 397 +++++++++++++++++++
 tools/puppet3-agent/stratos_sendinfo.rb         |  29 ++
 4 files changed, 662 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/80fe499d/tools/puppet3-agent/config.sh
----------------------------------------------------------------------
diff --git a/tools/puppet3-agent/config.sh b/tools/puppet3-agent/config.sh
new file mode 100755
index 0000000..58f874e
--- /dev/null
+++ b/tools/puppet3-agent/config.sh
@@ -0,0 +1,94 @@
+#!/bin/bash
+# --------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# --------------------------------------------------------------
+shopt -s nocasematch
+ECHO=`which echo`
+RM=`which rm`
+READ=`which read`
+TR=`which tr`
+HEAD=`which head`
+WGET=`which wget`
+MKDIR=`which mkdir`
+GREP=`which grep`
+SED=`which sed`
+
+
+DATE=`date +%d%m%y%S`
+RANDOMNUMBER="`${TR} -c -d 0-9 < /dev/urandom | ${HEAD} -c 4`${DATE}"
+
+function valid_ip()
+{
+    local  ip=$1
+    local  stat=1
+
+    if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
+        OIFS=$IFS
+        IFS='.'
+        ip=($ip)
+        IFS=$OIFS
+        [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
+            && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
+        stat=$?
+    fi
+    return $stat
+}
+
+read -p "This script will install and configure puppet agent, do you want to 
continue [y/N]" answer
+if [[ $answer = y ]] ; then
+
+       ${MKDIR} -p /tmp/payload
+       ${WGET} http://169.254.169.254/latest/user-data -O 
/tmp/payload/launch-params
+
+       read -p "Please provide stratos service-name:" SERVICE_NAME
+       if [[ -z $SERVICE_NAME ]]; then
+       echo "service name cannot be empty!"
+       exit -1
+       fi
+
+       read -p "Please provide puppet master IP:" PUPPET_IP
+       if ! valid_ip $PUPPET_IP ; then
+       echo "invalid IP address format!"
+       exit -1
+       fi
+
+       read -p "Please provide puppet master hostname [puppet.stratos.org]:" 
DOMAIN
+       DOMAIN=${DOMAIN:-puppet.stratos.org}
+       #essential to have PUPPET_HOSTNAME at the end in order to auto-sign the 
certs
+
+       #read -p "Please provide stratos deployment:" DEPLOYMENT
+       #DEPLOYMENT=${DEPLOYMENT:-default}
+       DEPLOYMENT="default"
+
+       NODEID="${RANDOMNUMBER}.${DEPLOYMENT}.${SERVICE_NAME}"
+       
+       ${ECHO} -e "\nNode Id ${NODEID}\n"
+       ${ECHO} -e "\nDomain ${DOMAIN}\n"
+    
+       ARGS=("-n${NODEID}" "-d${DOMAIN}" "-s${PUPPET_IP}")
+       ${ECHO} "\nRunning puppet installation with arguments: ${ARGS[@]}"
+       exec /root/bin/puppetinstall/puppetinstall "${ARGS[@]}"
+       ${GREP} -q '/root/bin/init.sh > /tmp/puppet_log' /etc/rc.local || 
${SED} -i 's/exit 0$/\/root\/bin\/init.sh \> \/tmp\/puppet_log\nexit 0/' 
/etc/rc.local
+       ${RM} -rf /tmp/puppet*
+       ${RM} -rf /var/lib/puppet/ssl/*
+
+fi
+
+# END

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/80fe499d/tools/puppet3-agent/init.sh
----------------------------------------------------------------------
diff --git a/tools/puppet3-agent/init.sh b/tools/puppet3-agent/init.sh
new file mode 100755
index 0000000..172bf54
--- /dev/null
+++ b/tools/puppet3-agent/init.sh
@@ -0,0 +1,142 @@
+#!/bin/bash
+# --------------------------------------------------------------
+#
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# --------------------------------------------------------------
+
+MKDIR=`which mkdir`
+UNZIP=`which unzip`
+ECHO=`which echo`
+FIND=`which find`
+GREP=`which grep`
+RM=`which rm`
+XARGS=`which xargs`
+SED=`which sed`
+CUT=`which cut`
+AWK=`which awk`
+IFCONFIG=`which ifconfig`
+HOSTNAME=`which hostname`
+SLEEP=`which sleep`
+TR=`which tr`
+HEAD=`which head`
+WGET=`which wget`
+PUPPETD=`which puppet`
+AGENT="agent"
+PUPPETAGENT="${PUPPETD} ${AGENT}"
+
+COMMAND="${PUPPETAGENT} -vt"
+IP=`${IFCONFIG} eth0 | ${GREP} -e "inet addr" | ${AWK} '{print $2}' | ${CUT} 
-d ':' -f 2`
+LOG=/tmp/puppet-init.log
+
+HOSTSFILE=/etc/hosts
+HOSTNAMEFILE=/etc/hostname
+PUPPETCONF=/etc/puppet/puppet.conf
+
+read_master() {
+       ${COMMAND}
+}
+
+
+is_public_ip_assigned() {
+
+while true
+do
+   wget http://169.254.169.254/latest/meta-data/public-ipv4
+   if [ ! -f public-ipv4 ]
+       then
+       echo "Public ipv4 file not found. Sleep and retry" >> $LOG
+       sleep 2;
+       continue;
+       else
+       echo "public-ipv4 file is available. Read value" >> $LOG
+       # Here means file is available. Read the file
+       read -r ip<public-ipv4;
+       echo "value is **[$ip]** " >> $LOG
+
+       if [ -z "$ip" ]
+               then
+               echo "File is empty. Retry...." >> $LOG
+               sleep 2
+               rm public-ipv4
+               continue
+               else
+               echo "public ip is assigned. value is [$ip]. Remove file" >> 
$LOG
+               rm public-ipv4
+               break
+               fi
+       fi
+done
+}
+
+
+DATE=`date +%d%m%y%S`
+RANDOMNUMBER="`${TR} -c -d 0-9 < /dev/urandom | ${HEAD} -c 4`${DATE}"
+
+if [ ! -d /tmp/payload ]; then
+
+       ## Check whether the public ip is assigned
+       is_public_ip_assigned
+
+       echo "Public ip have assigned. Continue.." >> $LOG
+
+       ## Clean old poop
+       ${ECHO} "Removing all existing certificates .."
+       #${FIND} /var/lib/puppet -type f -print0 | ${XARGS} -0r ${RM}
+
+       ${MKDIR} -p /tmp/payload
+       ${WGET} http://169.254.169.254/latest/user-data -O 
/tmp/payload/launch-params
+
+       cd /tmp/payload
+       SERVICE_NAME=`sed 's/,/\n/g' launch-params | grep SERVICE_NAME | cut -d 
"=" -f 2`
+       DEPLOYMENT=`sed 's/,/\n/g' launch-params | grep DEPLOYMENT | cut -d "=" 
-f 2`
+       INSTANCE_HOSTNAME=`sed 's/,/\n/g' launch-params | grep HOSTNAME | cut 
-d "=" -f 2`
+       PUPPET_IP=`sed 's/,/\n/g' launch-params | grep PUPPET_IP | cut -d "=" 
-f 2`
+       PUPPET_HOSTNAME=`sed 's/,/\n/g' launch-params | grep PUPPET_HOSTNAME | 
cut -d "=" -f 2`
+       PUPPET_ENV=`sed 's/,/\n/g' launch-params | grep PUPPET_ENV | cut -d "=" 
-f 2`
+       NODEID="${RANDOMNUMBER}.${DEPLOYMENT}.${SERVICE_NAME}"
+       #essential to have PUPPET_HOSTNAME at the end in order to auto-sign the 
certs
+       DOMAIN="${PUPPET_HOSTNAME}"
+       ${ECHO} -e "\nNode Id ${NODEID}\n"
+       ${ECHO} -e "\nDomain ${DOMAIN}\n"
+       sed -i "s/server=.*/server=${PUPPET_HOSTNAME}/g"  ${PUPPETCONF}
+       /etc/init.d/puppet restart    
+       ARGS=("-n${NODEID}" "-d${DOMAIN}" "-s${PUPPET_IP}")
+       HOST="${NODEID}.${DOMAIN}"
+       ${HOSTNAME} ${HOST}
+       ${ECHO} "${HOST}" > ${HOSTNAMEFILE}
+       ${ECHO} "${PUPPET_IP}  ${PUPPET_HOSTNAME}" >> ${HOSTSFILE} 
+       ${ECHO} "127.0.0.1 ${HOST}" >> ${HOSTSFILE}
+       /etc/init.d/hostname start
+
+       PUPPET=`which puppet`
+        PUPPETAGENT="${PUPPET} agent"
+        RUNPUPPET="${PUPPETAGENT} -vt"
+
+        ${SLEEP} 5
+
+        ${PUPPETAGENT} --enable
+
+        ${RUNPUPPET}
+
+        ${PUPPETAGENT} --disable
+       ${ECHO} -e "Initialization completed successfully."
+
+fi
+
+# END
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/80fe499d/tools/puppet3-agent/puppetinstall/puppetinstall
----------------------------------------------------------------------
diff --git a/tools/puppet3-agent/puppetinstall/puppetinstall 
b/tools/puppet3-agent/puppetinstall/puppetinstall
new file mode 100755
index 0000000..32b0bc3
--- /dev/null
+++ b/tools/puppet3-agent/puppetinstall/puppetinstall
@@ -0,0 +1,397 @@
+#!/bin/bash
+ 
+# Puppet Installer.
+#
+#
+# Thilina Piyasundara
+# 2014-02-12
+# last updated on : 2014-02-12
+#
+#
+# Copyright [2014] [Thilina Piyasundara]
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Exit on fail
+set -e
+
+# General commands
+MV=`which mv`
+CP=`which cp`
+ID=`which id`
+CAT=`which cat`
+CUT=`which cut`
+AWK=`which awk`
+SED=`which sed`
+WGET=`which wget`
+DATE=`which date`
+ECHO=`which echo`
+UNAME=`which uname`
+HOSTNAME=`which hostname`
+SLEEP=`which sleep`
+
+# Parameters
+MASTER=0
+VERBOSE=0
+MASTERIP=""
+NODENAME=""
+DOMAIN=""
+OSDIST=""
+TIMEZONE="Asia/Colombo"
+
+# Execute bashtrap function when user press [Ctrl]+[c]
+trap bashtrap INT
+
+function print_usage(){
+       ${ECHO} -e "Puppet Installer v1 2014-02-12"
+       ${ECHO} -e "This script will install PuppetLab puppet v3."
+       ${ECHO} -e "Thilina Piyasundara. <[email protected]>"    
+       ${ECHO} -e ""
+       ${ECHO} -e "Usage: "
+       ${ECHO} -e "    puppetinstall [-m|--master or -n|--node <node 
hostname>] -d <domain> -s <puppet master server ip> "
+       ${ECHO} -e ""
+       ${ECHO} -e "Commands:"
+       ${ECHO} -e "Either long or short options are allowed."
+       ${ECHO} -e "    -m, --master            Install puppet master on the 
system."
+       ${ECHO} -e "    -n, --node <hostname> Install puppet agent on the 
system."
+       ${ECHO} -e "                            If you use -m tag with this, -n 
tag will be ignored."
+       ${ECHO} -e "    -d, --domain <domain> Domain name of the environment. 
This will act as a"
+       ${ECHO} -e "                            prefix to all the servers of 
the domain."
+       ${ECHO} -e "                            eg: "
+       ${ECHO} -e "                            if a serrver is: 
server23.dc1.example.com"
+       ${ECHO} -e "                            your domain must be : 
dc1.example.com"
+       ${ECHO} -e "    -s, --serverip <ip>   IP address of the puppet master 
server."
+       ${ECHO} -e "                            This IP address will added to 
the /etc/hosts file."
+       ${ECHO} -e "    -h, --help              This will print this message."
+       ${ECHO} -e "    -v, --verbose           This will activate verbose 
mode."
+       ${ECHO} -e ""
+       ${ECHO} -e "Examples: "
+       ${ECHO} -e "    sudo puppetinstall -m -d example.com"
+       ${ECHO} -e "            This will install puppet master on example.com 
domain."
+       ${ECHO} -e ""
+       ${ECHO} -e "    sudo puppetinstall -n node001 -d example.com -s 
192.168.122.1"
+       ${ECHO} -e "            This will install puppet agent on example.com 
domain. "
+       ${ECHO} -e "            Agent hostname will be node001.example.com and 
will point"
+       ${ECHO} -e "            to the puppet master on 192.168.122.1 server."
+       ${ECHO} -e ""
+       ${ECHO} -e "Report bugs/issues on 
https://github.com/thilinapiy/puppetinstall/issues";
+}
+
+function print_message(){
+       if [ ${VERBOSE} -eq 1 ]; then
+       ${ECHO} -en $1
+       fi    
+}
+
+function print_ok(){
+       if [ ${VERBOSE} -eq 1 ]; then
+       ${ECHO} -e " [Done]"     
+       fi
+}
+
+function print_error(){
+       if [ ${VERBOSE} -eq 1 ]; then
+       ${ECHO} -e " [Error]\n"$1
+       else
+       ${ECHO} -e "[Error]" $1
+       fi
+       exit 1
+}
+
+function get_distro(){
+# Check for distribution
+       print_message "Checking for the distribution ... "
+       if [ -f /etc/debian_version ]; then
+       OSDIST="Debian"
+       print_ok
+       elif [ -f /etc/redhat-release ]; then
+       OSDIST="RedHat"
+       print_ok
+       else
+       OSDIST="unknown"
+       print_ok
+       fi
+}
+
+function check_user(){
+# Check for root
+       print_message "Checking for user permission ... "
+       if [ `${ID} -u` != 0 ] ; then
+       print_error "Need root access.\nRun the script as 'root' or with 'sudo' 
permissions. "
+       else
+       print_ok
+       fi
+}
+
+function check_for_puppet(){
+# Checking for puppet
+       print_message "Checking for previous puppet installations ... "    
+       if [[ -d '/etc/puppet/' || -d '/var/lib/puppet' ]]; then
+       print_error "Puppet exist on this system."
+       else
+       print_ok
+       fi
+}
+
+function get_confirmation(){
+# Get user confirmation    
+       ${ECHO} -e "Puppet Installer v1 2014-02-12"
+       ${ECHO} -e "This script will install PuppetLab puppet v3."
+       ${ECHO} -e "Thilina Piyasundara. <[email protected]>"    
+       ${ECHO} -e ""
+       ${ECHO} -e "== [Caution] 
==========================================================="
+       ${ECHO} -e "This script will replace existing '/etc/hosts' and 
'/etc/hostname'          "
+       ${ECHO} -e "files and will update hostname of the system with following 
parameter.  "
+       ${ECHO} -e ""
+       ${ECHO} -en "Installing puppet          : "
+                       [ ${MASTER} -eq 1 ] && ${ECHO} -e "Master" || ${ECHO} 
-e "Agent "  
+       ${ECHO} -e "Puppet Master FQDN name   : "${MASTERHOSTNAME}
+       ${ECHO} -e "Puppet Masters IP address : "${MASTERIP}
+       ${ECHO} -e "Domain of the deployment  : "${DOMAIN}
+       ${ECHO} -e "FQDN of this node           : "${NODEHOSTNAME}
+       ${ECHO} -e "Operating system            : "${OSDIST}
+       ${ECHO} -e ""
+       ${ECHO} -e "Please check your input and confirm by pressing [Enter] to 
continue.        "
+       ${ECHO} -e "Or press [Ctrl] + [c] to stop the installationan exit.      
                "
+       ${ECHO} -e ""
+       ${ECHO} -e "Report bugs/issues on 
https://github.com/thilinapiy/puppetinstall/issues";
+       ${ECHO} -e 
"========================================================================"
+
+       #read input
+       #if [ ${VERBOSE} -eq 0 ]; then
+       ${ECHO} -e "Installation started. Please wait ... "
+       #fi    
+}
+
+bashtrap(){
+       print_error "\n[Ctrl] + [c] detected ... \nScript will exit now."
+}
+
+function update_host(){
+# Update '/etc/hosts'
+       print_message "Updating '/etc/hosts' ... "
+       ${MV} /etc/hosts /etc/hosts-`${DATE} +%Y%m%d-%H%M%S`  && : || 
print_error "Failed to update '/etc/hosts' file. "
+       ${ECHO} "127.0.0.1  localhost" >/etc/hosts && : || print_error "Failed 
to update '/etc/hosts' file. "
+       if [ ! ${MASTER} -eq 1 ]; then
+       ${ECHO} "127.0.0.1  ${NODEHOSTNAME}" >>/etc/hosts && : || print_error 
"Failed to update '/etc/hosts' file. "
+       fi
+       ${ECHO} "${MASTERIP}  ${MASTERHOSTNAME}" >>/etc/hosts && print_ok || 
print_error "Failed to update '/etc/hosts' file. "
+
+# Update hostname
+       print_message "Updating hostname ... "
+       ${HOSTNAME} ${NODEHOSTNAME} && : || print_error "Failed to update 
hostname. "
+       ${ECHO} ${NODEHOSTNAME} >/etc/hostname && print_ok || print_error 
"Failed to update '/etc/hostname' file. "
+}
+
+function install_on_ubuntu(){
+# Install puppet master or agent on a Ubuntu/Debian system
+#Ubuntu/Debian specific commands.
+       APT=`which apt-get`
+       NTPDEBIAN=`which ntpdate-debian`
+       DPKG=`which dpkg`
+       DPKGRECONF=`which dpkg-reconfigure`
+
+# Do a time sync
+       print_message "Updating system time ... "
+       ${ECHO} "${TIMEZONE}" > /etc/timezone && : || print_error "Failed to 
add timezone"
+       ${APT} remove locales -y
+       export LANGUAGE=en_US.UTF-8
+       export LANG=en_US.UTF-8
+       export LC_ALL=en_US.UTF-8
+       ${APT} install locales -y
+       ${DPKGRECONF} locales
+       ${DPKGRECONF} --frontend noninteractive tzdata  && : || print_error 
"Failed to reconfigure timezone"
+       ${NTPDEBIAN} && print_ok || print_error "Failed to synchronize time. "
+
+# Install puppet repository
+       print_message "Downloading repo file from puppetlabs ... "
+       if [ ${VERBOSE} -eq 1 ]; then
+       ${WGET} http://apt.puppetlabs.com/puppetlabs-release-precise.deb && 
print_ok || print_error "Failed to download the repository file from 
puppetlabs."
+       else
+       ${WGET} -q http://apt.puppetlabs.com/puppetlabs-release-precise.deb && 
print_ok || print_error "Failed to download the repository file from 
puppetlabs."
+       fi
+       print_message "Installing puppet repository ... "
+       ${DPKG} -i puppetlabs-release-precise.deb && print_ok || print_error 
"Failed to install the repository file of puppetlabs."
+
+# Update repository list
+       print_message "Updating system repository list ... "
+       if [ ${VERBOSE} -eq 1 ]; then
+       ${APT} update && print_ok || print_error "Failed to update repository 
lists."
+       else
+       ${APT} update -q=2 && : || print_error "Failed to update repository 
lists."
+       fi
+
+if [ ${MASTER} -eq 1 ]; then
+# Install puppet master
+       print_message "Installing puppet master ... "
+       ${APT} install puppetmaster -y && print_ok || print_error "Failed to 
install puppet master."
+#configure puppet master
+       print_message "Configuring puppet master ... "
+       ${SED} -i 's/START=no/START=yes/' /etc/default/puppetmaster && : || 
print_error "Failed to configure puppet master's '/etc/default/puppetmaster'."
+       ${ECHO} -e "*.${DOMAIN}" > /etc/puppet/autosign.conf && : || 
print_error "Failed to configure puppet master's '/etc/puppet/autosign.conf'."
+       ${SED} -i "2i server=${MASTERHOSTNAME}" /etc/puppet/puppet.conf && 
print_ok || print_error "Failed to configure puppet master's 
'/etc/puppet/puppet.conf'."
+       print_message "Restarting puppet master service ... "
+       /etc/init.d/puppetmaster restart && ${ECHO} -e "Installation completed 
successfully." || print_error "Failed to restart puppet master."
+       else
+# Install puppet agent
+       print_message "Installing puppet agent ... "
+       ${APT} install puppet -q=2 -y && print_ok || print_error "Failed to 
install puppet agent."
+    ${ECHO} -e "Copying Stratos facter file to /usr/lib/ruby/1.8"
+       if [ -d /usr/lib/ruby/1.8 ]; then
+               cp /root/bin/stratos_sendinfo.rb /usr/lib/ruby/1.8
+       fi
+
+       print_message "Configuring puppet agent ... "
+       ${SED} -i 's/START=no/START=yes/' /etc/default/puppet && : || 
print_error "Failed to configure puppet agent's '/etc/default/puppet'."
+       ${SED} -i "2i server=${MASTERHOSTNAME}" /etc/puppet/puppet.conf && 
print_ok || print_error "Failed to configure puppet agent's 
'/etc/puppet/puppet.conf'."
+    /etc/init.d/puppet stop
+    
+    PUPPET=`which puppet`
+    PUPPETAGENT="${PUPPET} agent"
+    RUNPUPPET="${PUPPETAGENT} -vt"
+
+    ${SLEEP} 5
+
+    ${PUPPETAGENT} --enable
+    
+    ${RUNPUPPET}
+
+    ${PUPPETAGENT} --disable
+    ${ECHO} -e "Installation completed successfully."
+fi
+}
+
+function install_on_redhat(){
+# Install puppet master and agent on redhat base systems
+       YUM=`which yum`
+       RPM=`which rpm`
+       EL_VERSION=$( ${UNAME} -r | ${AWK} -F "el" '{print $2}' | ${AWK} -F "." 
'{print $1}')
+       
REPO_URL="http://yum.puppetlabs.com/puppetlabs-release-el-${EL_VERSION}.noarch.rpm";
+
+# Do a time sync
+       print_message "Updating system time ... "
+       which ntpdate && : || (echo "Installing ntpdate ..."; ${YUM} install -y 
-q ntpdate)
+       NTPDATE="ntpdate"
+       ${CP} /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && : || 
print_error "Failed to reconfigure timezone"
+       ${NTPDATE} pool.ntp.org && print_ok || print_error "Failed to 
synchronize time. "
+
+# Install puppet repository
+       print_message "Downloading repo file from puppetlabs ... "
+       if [ ${VERBOSE} -eq 1 ]; then
+       ${WGET} ${REPO_URL} && print_ok || print_error "Failed to download the 
repository file from puppetlabs."
+       else
+       ${WGET} -q ${REPO_URL} && print_ok || print_error "Failed to download 
the repository file from puppetlabs."
+       fi
+       print_message "Installing puppet repository ... "
+       ${RPM} -i puppetlabs-release-*.rpm && print_ok || print_error "Failed 
to install puppetlabs repository."
+
+if [ ${MASTER} -eq 1 ]; then
+# Install puppet master
+       print_message "Installing puppet server ... "
+       ${YUM} install puppet-server -q -y && print_ok || print_error "Failed 
to install puppet server."
+#configure puppet master
+       print_message "Configuring puppet server ... "
+       ${ECHO} -e "*.${DOMAIN}" > /etc/puppet/autosign.conf && : || 
print_error "Failed to configure puppet server's '/etc/puppet/autosign.conf'."
+       ${SED} -i "2i server=${MASTERHOSTNAME}" /etc/puppet/puppet.conf && 
print_ok || print_error "Failed to configure puppet server's 
'/etc/puppet/puppet.conf'."
+       print_message "Restarting puppet server service ... "
+       /etc/init.d/puppetmaster restart && ${ECHO} -e "Installation completed 
successfully. \nOpen port 8140 via IPtables." || print_error "Failed to restart 
puppet server."
+       else
+# Install puppet agent
+       print_message "Installing puppet agent ... "
+       ${YUM} install puppet -y && print_ok || print_error "Failed to install 
puppet agent."
+       print_message "Configuring puppet agent ... "
+       ${SED} -i "2i server=${MASTERHOSTNAME}" /etc/puppet/puppet.conf && 
print_ok || print_error "Failed to configure puppet agent's 
'/etc/puppet/puppet.conf'."
+       print_message "Restarting puppet agent service ... "
+       /etc/init.d/puppet restart && ${ECHO} -e "Installation completed 
successfully." || print_error "Failed to restart puppet agent."
+fi
+}
+
+# Check all input parameters.
+while getopts ":vhmd:n:s: --help --verbose --master --node --domain 
--serverip" opt; do
+       case ${opt} in
+       h|--help)
+               print_usage
+               exit 0
+               ;;
+       v|--verbose)
+               VERBOSE=1
+               ;;
+       d|--domain)
+               DOMAIN=${OPTARG}
+               ;;
+       n|--node)
+               NODENAME=${OPTARG}
+               ;;
+       m|--master)
+               MASTER=1
+               ;;
+       s|--serverip)
+               MASTERIP=${OPTARG}
+               ;;
+       :)
+               ${ECHO} -e "puppetinstall: Option -${OPTARG} requires an 
argument."
+               ${ECHO} -e "puppetinstall: '--help or -h' gives usage 
information."
+               exit 1
+               ;;
+       \?)
+               ${ECHO} -e "puppetinstall: Invalid option: -${OPTARG}"
+               ${ECHO} -e "puppetinstall: '--help or -h' gives usage 
information."
+               exit 1
+               ;;
+       esac
+done
+
+# Validate the user
+check_user
+
+if [ ${MASTER} -eq 1 ]; then
+       NODENAME="puppet"
+       [ -z ${MASTERIP} ] && MASTERIP="127.0.0.1" || :
+fi
+
+if [ -z ${DOMAIN} ] || [ -z ${MASTERIP} ] || [ -z ${NODENAME} ]; then
+       ${ECHO} -e "puppetinstall: Require a domain, host/node name and puppet 
master ip address."
+       ${ECHO} -e "puppetinstall: '--help or -h' gives usage information."
+       exit 1
+fi
+
+# Set the hostname
+MASTERHOSTNAME="${DOMAIN}"
+NODEHOSTNAME="${NODENAME}.${DOMAIN}"
+
+# Check puppet exist on the system
+check_for_puppet
+# Get the operating system distribution
+get_distro
+get_confirmation
+
+case ${OSDIST} in
+       Debian)
+       update_host
+       install_on_ubuntu
+       ;;
+       RedHat)
+       update_host
+       install_on_redhat
+       ;;
+       Fedora)
+       print_error "Fedora is not recommended. Try to use CentOS."
+       ;;
+       *)
+       print_error "System was not identified."
+       ;;
+esac
+
+
+exit 0

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/80fe499d/tools/puppet3-agent/stratos_sendinfo.rb
----------------------------------------------------------------------
diff --git a/tools/puppet3-agent/stratos_sendinfo.rb 
b/tools/puppet3-agent/stratos_sendinfo.rb
new file mode 100755
index 0000000..272c291
--- /dev/null
+++ b/tools/puppet3-agent/stratos_sendinfo.rb
@@ -0,0 +1,29 @@
+censed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# --------------------------------------------------------------
+
+
+configs = File.read("/tmp/payload/launch-params").split(",").map(&:strip)
+
+configs.each { |x| key_value_pair = x.split("=").map(&:strip)
+       Facter.add("stratos_instance_data_" + key_value_pair[0].to_s){
+               setcode { key_value_pair[1].to_s
+               }
+       }
+ }
+

Reply via email to