Commits

Johan Bakker committed d2d11f3

add missing file & add module path

Comments (0)

Files changed (1)

+#!/bin/bash
+# script : bootstrap-puppet-ec2.sh
+# Usage  : bootstrapping puppet on EC2 node
+# Author : Johan Bakker (jbakker@atlassian.com)
+VER=0.0.1
+
+usage() {
+  echo "
+  bootstrap-puppet-ec2.sh $VER
+  Usage: bootstrap-puppet.sh [-hy] [-FP]
+     -h: print usage informations and exit
+     -y: Answers all questions with yes (this applies to installing ruby and creating folders)
+     -B: Path to puppet bootstrap file (defaults to /tmp/bootstrap.pp)
+     -C: Folder to store configfiles (defaults to /etc/puppet)
+     -F: Facter version (default to latest)
+     -P: Puppet version (defaults to latest)
+  "
+}
+
+install_rubygems() {
+	which 'gem' &> /dev/null
+	if [ ! $? = 0 ]; then
+  	  echo -e "The rubygems package is not installed\n\nCan I install it?"
+  	  if [ ! $YES ]; then
+  		select yn in 'Yes' 'No'; do
+  	  	case $yn in 
+  	  	  Yes) break
+  	  	  ;;
+  	  	  No) echo "Please install the rubygems package and restart this script!"
+  	  	    exit 1
+  	  	  ;;
+  	  	esac
+  		done
+  	  else
+  	     echo "Yes"
+  	  fi
+  	  sudo $pkgadd rubygems || ERRCODE=$?
+  	  if [ ! $ERRCODE = 0 ]; then
+  	    echo "Rubygems install failed ($ERRCODE)"
+  	    exit $ERRCODE
+	  fi
+        fi
+}
+
+install_facter() {
+	#install facter
+	if [ ! -x /usr/bin/facter ]; then
+  	echo "Installing facter..."
+  	sudo gem install facter $FACTERVERSION --no-rdoc --no-ri
+	fi  
+}
+
+install_puppet() {
+	#install puppet
+	if [ ! -x /usr/bin/puppet ]; then
+  	echo "Installing puppet..."
+  	sudo gem install puppet $PUPPETVERSION --no-rdoc --no-ri
+	fi
+
+	#Create puppet config file
+	if [ ! -f $CONF_DIR/puppet.conf ]; then
+  	echo "[main]
+report = false
+reports = none
+
+[production]
+modulepath = /data/bitbucket/puppet/modules
+" > $CONF_DIR/puppet.conf
+	fi
+}
+
+create_privkey() {
+   /bin/ech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ZW4FJt1uJIfOM9drTp3H72jLn7OhKvkCgYBxvXXPH9aJQH7xXkdnGd9y
+/iz/1/AWKIDt9w8cI4OfoVkOSjJAW+bxV3cBHek1GBucHIZ+aTynSYhxKp7buVdk
+qGoK0jRIDZwjA9CN+TSJeVMKUQ3UbojiTQAHYBLrOGCfegEGZrMSdwhG027UBB+j
+O1R/xILzxy0AvEZlmm3F8QKBgGJDZnPmQ33TWhu6g9kOdg1krYh8NOuvOzcIvnrL
+IGMndgzIu09mK5KAtYSUvHm/Ulj41GQ7/rtGsVJJ62vsY1WRi9eDwbMMBS1sE6xz
+m09hjvfKXJG9cQJeNy8Ff5fsDS1ZCMeijC/nDsvJz2IVFzqwIaXsiB2XAQxsg1tP
+1ZIpAoGBAN02RurDVbcpKMsYOY7slfPX0KVoVHlxz/kJQkv8dpV1VqCD0B15xkCv
+5jnFx6pbkV2tmLK969UOZyK5SVno7/Dx1bYHBaPB+Tq1ur8vm3xLivi/8kFLLVd5
+MYbhOXY/S2fpoTydOBYm165N312QZnTIHrBNfxb/aQDOfQSazdRs
+-----END RSA PRIVATE KEY-----" > /data/bitbucket/ec2bb
+}
+
+run_puppet_bootstrap() {
+  echo "#bootstrap.pp 
+class ec2_bootstrap {
+  package { 'mercurial':
+    ensure => installed,
+  }
+
+  file { '/data':
+    ensure => directory,
+    owner => 'root',
+    group => 'root',
+    mode => 0755,
+  }
+
+  file { '/data/bitbucket':
+    ensure => directory,
+    owner => 'ec2-user',
+    group => 'ec2-user',
+    mode => 0755,
+  }
+
+  file { '/data/bitbucket/ec2bb':
+     ensure => present,
+     owner => 'ec2-user',
+     group => 'ec2-user',
+     mode => 0600,
+  }
+    
+}
+
+node 'default' {
+  include ec2_bootstrap
+}
+" | sudo tee $BOOTSTRAP > /dev/null
+  sudo puppet apply $BOOTSTRAP
+}
+
+clone_puppettree() {
+    /usr/bin/hg --config ui.ssh="ssh -i /data/bitbucket/ec2bb -o 'StrictHostkeyChecking no'" clone ssh://hg@bitbucket.org/hostedops/puppet /data/bitbucket/puppet
+    /usr/bin/hg --config ui.ssh="ssh -i /data/bitbucket/ec2bb -o 'StrictHostkeyChecking no'" clone ssh://hg@bitbucket.org/hostedops/puppet-module-nagios /data/bitbucket/puppet/modules/nagios
+}
+
+#Main
+while getopts :hyB:C:F:P: OPTIONS
+do
+  case ${OPTIONS} in
+    h) usage
+       exit 0
+       ;;
+    y) YES=1
+    ;;
+    B) BOOTSTRAP=$OPTARG
+       ;;
+    C) CONF_DIR=$OPTARG
+       ;;
+    P) PUPPETVERSION=" --version $OPTARG"
+       ;;
+    F) FACTERVERSION=" --version $OPTARG"
+       ;;
+    *) echo "Unknown option"
+       usage
+       exit 1
+       ;;
+  esac
+done
+
+#vars
+CONF_DIR=${CONF_DIR:-"/etc/puppet"}
+PUPPETVERSION=${PUPPETVERSION:-""}
+FACTERVERSION=${FACTERVERSION:-""}
+BOOTSTRAP=${BOOTSTRAP:-"/tmp/bootstrap.pp"}
+
+#set packagelist list command
+which 'rpm' &> /dev/null && pkgadd='yum -y install'
+which 'dpkg' &> /dev/null && pkgadd='apt-get -y install'
+
+#Tasks
+install_rubygems; #check if rubygems is installed install if not.
+install_facter;   #check if facter is installed install if not.
+install_puppet;   #check if puppet is installed install if not.
+create_privkey;
+run_puppet_bootstrap; #Run bootstrap.pp
+clone_puppettree
+#run_puppet
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.