Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Better PE support, postinstall script support #15

Merged
merged 5 commits into from Nov 6, 2012
View
@@ -1 +1 @@
-**/*.swp
+*.swp
@@ -0,0 +1,29 @@
+---
+puppet_run_type: pe_agent
+master:
+ master_node:
+ master_type: pe_master
+ create:
+ options:
+ type: m1.small
+ image: ami-20800c10
+ install:
+ installer_payload: https://s3.amazonaws.com/pe-builds/released/2.6.1/puppet-enterprise-2.6.1-ubuntu-12.04-amd64.tar.gz
+ answers_payload: https://raw.github.com/gist/3299809/6b893459afc6f380bfb8231777abbfc06dc05dc5/answers
+
+nodes:
+ - ubuntu1204a: &ubuntu1204
+ create:
+ group: agent
+ options:
+ type: t1.micro
+ image: ami-20800c10
+ install:
+ installer_payload: https://s3.amazonaws.com/pe-builds/released/2.6.1/puppet-enterprise-2.6.1-ubuntu-12.04-amd64.tar.gz
+ answers_payload: https://raw.github.com/gist/3299812/9dea06dba93d218c61e5fa9d9e928a265c137239/answers
+
+ - ubuntu1204b: *ubuntu1204
+
+ - ubuntu1204c: *ubuntu1204
+
+ - ubuntu1204d: *ubuntu1204
@@ -0,0 +1,11 @@
+---
+puppet_run_type: pe_agent
+master:
+ master_node:
+ master_type: pe_master
+ create:
+ options:
+ type: m1.small
+ install:
+ installer_payload: https://s3.amazonaws.com/pe-builds/released/2.6.1/puppet-enterprise-2.6.1-ubuntu-12.04-amd64.tar.gz
+ answers_payload: https://raw.github.com/gist/3299809/6b893459afc6f380bfb8231777abbfc06dc05dc5/answers
View
@@ -274,7 +274,7 @@ def self.install_instances(nodes, dns_hash, mode, master = nil)
# each of these can be done in parallel
# except can our puppetmaster service simultaneous requests?
node.each do |name, attrs|
- if ['pe_master', 'master', 'agent', 'apply'].include?(mode)
+ if ['pe_master', 'master', 'pe_agent', 'agent', 'apply'].include?(mode)
run_type = 'install'
elsif mode == 'test'
run_type = 'test'
@@ -402,4 +402,25 @@ def self.queue
@queue ||= Queue.new
end
+ def self.heredoc_safe(string)
+ # lifted from shellquote function on 2012/10/22
+ safe = '!"a-zA-Z0-9@%_+=:,./-' # Safe unescaped
+ dangerous = '`$\\' # Unsafe without escape
+
+ if string.length != 0 and string.count(safe) == string.length
+ return string
+ elsif string.count(dangerous) == 0
+ return ('"' + string + '"')
+ elsif string.count("'") == 0
+ return ("'" + string + "'")
+ else
+ r = String.new
+ string.each_byte do |c|
+ r += "\\" if dangerous.include?(c)
+ r += c.chr
+ end
+ return r
+ end
+ end
+
end
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
Oops, something went wrong.