Permalink
Browse files

PE updates, Fragment/modularize erb template files

Consolidate code actions for reuse between mode scripts. Also clean up /
add additional install option shell script actions.

As part of the modularization of the shell script template fragments,
clean up the PE code for answer files, and the PE code in general.
  • Loading branch information...
1 parent 5c2d1e0 commit a1ef06f23191e835fc59ec723d5cedec7e91a892 @reidmv committed Oct 19, 2012
View
@@ -6,4 +6,6 @@
set -u
set -e
+<%= ERB.new(File.read(find_template('fragments/options')), nil, "<>", '_options').result(binding) %>
+
puppet agent --pluginsync --test --certname=<%= options['certname'] %> --server=<%= options['puppetmaster'] %> | tee /tmp/puppet_output.log
View
@@ -6,116 +6,8 @@
set -u
set -e
-function fedora_repo(){
- cat >/etc/yum.repos.d/puppet.repo <<'EOFYUMREPO'
-[puppetlabs]
-name = Puppetlabs
-baseurl = http://yum.puppetlabs.com/fedora/f$releasever/products/$basearch/
-gpgcheck = 1
-enabled = 1
-gpgkey = http://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs
-EOFYUMREPO
-}
-
-function el_repo(){
- cat >/etc/yum.repos.d/puppet.repo <<'EOFYUMREPO'
-[puppetlabs]
-name = Puppetlabs
-baseurl = http://yum.puppetlabs.com/el/$releasever/products/$basearch/
-gpgcheck = 1
-enabled = 1
-gpgkey = http://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs
-EOFYUMREPO
-}
-
-function rpm_install(){
- # Setup the yum Puppet repository
- rpm -q fedora-release && fedora_repo || el_repo
-
- # Install git
- yum install -y git
- # Install Puppet from yum.puppetlabs.com
- yum install -y puppet
-}
-
-function apt_install() {
- # Download and install the puppetlabs apt public
- apt-key adv --recv-key --keyserver pool.sks-keyservers.net 4BD6EC30
-
- # We need to grab the distro and release in order to populate
- # the apt repo details. We are assuming that the lsb_release command
- # will be available as even puppet evens has it (lsb_base) package as
- # dependancy.
-
- # Since puppet requires lsb-release I believe this is ok to use for
- # the purpose of distro and release discovery.
- apt-get update
- apt-get -y install git-core
- apt-get -y install lsb-release
- distro=$(lsb_release -i | cut -f 2 | tr "[:upper:]" "[:lower:]")
- release=$(lsb_release -c | cut -f 2)
-
- # Setup the apt Puppet repository
- cat > /etc/apt/sources.list.d/puppetlabs.list <<EOFAPTREPO
-deb http://apt.puppetlabs.com/${distro}/ ${release} main
-EOFAPTREPO
- apt-get update
- # Install Puppet from Debian repositories
- apt-get -y install puppet
- apt-get install -y git-core
- apt-get install -y rubygems
-}
-
-function install_puppet() {
- case ${breed} in
- "redhat")
- rpm_install ;;
- "debian")
- apt_install ;;
- esac
-}
-
<% if options['install_puppet'] %>
-# install puppet
-if [ -f /etc/redhat-release ]; then
- export breed='redhat'
-elif [ -f /etc/debian_version ]; then
- export breed='debian'
-else
- echo "This OS is not supported by Puppet Cloud Provisioner"
- exit 1
-fi
-
-install_puppet
-echo "Puppet installation finished!"
+<%= ERB.new(File.read(find_template('fragments/install_poss')), nil, "<>", '_install_poss').result(binding) %>
<% end %>
-
-# clone specified git repos
-module_path=${1:-'/etc/puppet/modules'}
-[ -d $module_path ] || mkdir -p $module_path
-pushd $module_path
-<% (options['git_repos'] || {}).each do |source, target| %>
-git clone <%= source %> <%= target %>
-<% end %>
-popd
-
-# checkout specified branches
-<% (options['git_checkout'] || {}).each do |dir, branch| %>
-pushd <%= dir %>
-git checkout <%= branch %>
-popd
-<% end %>
-
-<% (options['cp_files'] || {}).each do |source, target| %>
-cp <%= source %> <%= target %>
-<% end %>
-
-mkdir -p /var/lib/puppet_client
-# <%= options.inspect %>
-<% if options['manifest'] %>
-puppet apply --vardir /var/lib/puppet_client --trace --debug --verbose <%= options['manifest'] %> --certname=<%= options['certname'] %> | tee /tmp/puppet_output.log
-return=$?
-ls -lart /var/lib/puppet
-exit $?
-<% end %>
+<%= ERB.new(File.read(find_template('fragments/install_poss')), nil, "<>", '_install_poss').result(binding) %>
@@ -0,0 +1,45 @@
+<%= ERB.new(File.read(find_template('fragments/set_http_get')), nil, "<>", '_ipe_set_http_get').result(binding) %>
+
+PATH="/opt/puppet/bin:$PATH"
+export PATH
+
+install_dir="puppet-enterprise"
+if [ ! -e "${install_dir}" ]; then
+ mkdir "${install_dir}"
+fi
+
+echo "Downloading from: <%= options['installer_payload'] %>"
+
+# We assume the payload is a tar.gz file because the option handler
+# enforces this.
+# To save disk space (I'm concerned about /tmp filling) decompress on the fly.
+echo "Uncompressing the payload ..."
+$http_get '<%= options['installer_payload'] %>' | \
+ gunzip -c | \
+ { cd "${install_dir}" && tar -xvf -; } && \
+ echo "Uncompressing the payload ... Done."
+
+echo 'Downloading answers file'
+$http_get '<%= options['answers_payload'] %>' > puppet.answers.orig
+
+# Give me everything _except_ any agent certname specified in the answers
+# file, and the agent's server setting. Useless use of cat is for clarity
+# Note that this particular ERB syntax requires that the trim_mode be set
+# to <> when ERB.new is called (or some other alternative which will
+# suppress newlines) or else this shell code will not work.
+cat puppet.answers.orig | \
+ grep -v '^q_puppetmaster_certname' | \
+<% if options['puppetmaster'] %>
+ grep -v '^q_puppetagent_server' | \
+<% end %>
+ cat > puppet.answers
+
+# Append the user specified option from the command line arguments.
+echo 'q_puppetmaster_certname=<%= options['certname'] %>' >> puppet.answers
+echo 'q_puppetagent_certname=<%= options['certname'] %>' >> puppet.answers
+<% if options['puppetmaster'] %>
+echo 'q_puppetagent_server=<%= options['puppetmaster'] %>' >> puppet.answers
+<% end %>
+
+# Install Puppet Enterprise
+"${install_dir}"/*puppet*/puppet-enterprise-installer -a puppet.answers 2>&1 | tee install.log
@@ -0,0 +1,88 @@
+fedora_repo()
+{
+ cat >/etc/yum.repos.d/puppet.repo <<-EOFYUMREPO
+ [puppetlabs]
+ name = Puppetlabs
+ baseurl = http://yum.puppetlabs.com/fedora/f$releasever/products/$basearch/
+ gpgcheck = 1
+ enabled = 1
+ gpgkey = http://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs
+ EOFYUMREPO
+}
+
+el_repo()
+{
+ cat >/etc/yum.repos.d/puppet.repo <<-EOFYUMREPO
+ [puppetlabs]
+ name = Puppetlabs
+ baseurl = http://yum.puppetlabs.com/el/$releasever/products/$basearch/
+ gpgcheck = 1
+ enabled = 1
+ gpgkey = http://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs
+ EOFYUMREPO
+}
+
+rpm_install()
+{
+ # Setup the yum Puppet repository
+ rpm -q fedora-release && fedora_repo || el_repo
+
+ # Install git
+ yum install -y git
+
+ # Install Puppet from yum.puppetlabs.com
+ yum install -y puppet
+}
+
+apt_install()
+{
+ # Download and install the puppetlabs apt public
+ apt-key adv --recv-key --keyserver pool.sks-keyservers.net 4BD6EC30
+
+ # We need to grab the distro and release in order to populate
+ # the apt repo details. We are assuming that the lsb_release command
+ # will be available as even puppet evens has it (lsb_base) package as
+ # dependancy.
+
+ # Since puppet requires lsb-release I believe this is ok to use for
+ # the purpose of distro and release discovery.
+ apt-get update
+ apt-get -y install git-core
+ apt-get -y install lsb-release
+ distro=$(lsb_release -i | cut -f 2 | tr "[:upper:]" "[:lower:]")
+ release=$(lsb_release -c | cut -f 2)
+
+ # Setup the apt Puppet repository
+ cat > /etc/apt/sources.list.d/puppetlabs.list <<-EOFAPTREPO
+ deb http://apt.puppetlabs.com/${distro}/ ${release} main
+ EOFAPTREPO
+
+ # Install Puppet from Debian repositories
+ apt-get update
+ apt-get -y install puppet
+ apt-get install -y git-core
+ apt-get install -y rubygems
+}
+
+install_puppet()
+{
+ case "${osfamily}" in
+ "redhat")
+ rpm_install ;;
+ "debian")
+ apt_install ;;
+ esac
+}
+
+# install puppet
+if [ -f /etc/redhat-release ]; then
+ export osfamily='redhat'
+elif [ -f /etc/debian_version ]; then
+ export osfamily='debian'
+else
+ echo "This OS is not supported by Puppet Cloud Provisioner"
+ exit 1
+fi
+
+install_puppet
+echo "Puppet installation finished!"
@@ -0,0 +1,46 @@
+<%= ERB.new(File.read(find_template('fragments/set_http_get')), nil, "<>", '_o_set_http_get').result(binding) %>
+
+# install git and rubygems
+apt-get update || true
+apt-get install -y git-core || yum install -y git
+apt-get install -y rubygems || yum install -y rubygems
+
+# clone git repos
+<% (options['git_repos'] || {}).each do |source, target| %>
+mkdir -p <%= target %> || true
+git clone <%= source %> <%= target %>
+<% end %>
+
+# switch into specified branches
+<% (options['git_checkout'] || {}).each do |dir, branch| %>
+pushd <%= dir %>
+git checkout <%= branch %>
+popd
+<% end %>
+
+# cp files from modules to system locations
+<% (options['cp_files'] || {}).each do |source, target| %>
+cp <%= source %> <%= target %>
+<% end %>
+
+# if a manifest was specified apply it
+<% if options['manifest'] %>
+mkdir -p /var/lib/puppet_client
+# <%= options.inspect %>
+puppet apply --vardir /var/lib/puppet_client --trace --verbose <%= options['manifest'] %> --certname=<%= options['certname'] %> | tee /tmp/puppet_output.log
+return=$?
+<% end %>
+
+# upload and run postinstall scripts
+<% [options['postinstall']].flatten.compact.each do |script| %>
+POSTINSTALL=/tmp/postinstall
+<% if script.match(%r{[a-zA-Z0-9]://}) %>
+$http_get '<%= script %>' > $POSTINSTALL
+<% else %>
+cat > "$POSTINSTALL" <<-EOF_STACKBUILDER_POSTINSTALL
+<%= heredoc_safe(File.read(script)) %>
+EOF_STACKBUILDER_POSTINSTALL
+<% end %>
+chmod a+x "$POSTINSTALL"
+"$POSTINSTALL"
+<% end %>
@@ -0,0 +1,10 @@
+# Figure out if we have wget or curl
+if which wget >/dev/null; then
+ http_get="wget --output-document=- --quiet"
+elif which curl >/dev/null; then
+ http_get="curl -o -"
+else
+ echo "Error: could not find wget or curl on the remote system."
+ echo "To install Puppet Enterprise using HTTP, wget or curl are required"
+ exit 1
+fi
View
@@ -8,27 +8,5 @@ set -e
mkdir -p /etc/puppet/modules
pushd /etc/puppet/modules
-# clone all of the required modules
-apt-get install -y git-core
-apt-get install -y rubygems
-<% (options['git_repos'] || {}).each do |source, target| %>
-git clone <%= source %> <%= target %>
-<% end %>
-popd
-<% (options['git_checkout'] || {}).each do |dir, branch| %>
-pushd <%= dir %>
-git checkout <%= branch %>
-popd
-<% end %>
-<% (options['cp_files'] || {}).each do |source, target| %>
-cp <%= source %> <%= target %>
-<% end %>
-<% if options['manifest'] %>
-mkdir -p /var/lib/puppet_client
-# <%= options.inspect %>
-puppet apply --vardir /var/lib/puppet_client --trace --verbose <%= options['manifest'] %> --certname=<%= options['certname'] %> | tee /tmp/puppet_output.log
-return=$?
-ls -lart /var/lib/puppet
-exit $?
-<% end %>
+<%= ERB.new(File.read(find_template('fragments/options')), nil, "<>", '_options').result(binding) %>
Oops, something went wrong.

0 comments on commit a1ef06f

Please sign in to comment.