Permalink
Browse files

Add a new built-in (and configurable) Puppet livery.

This will allow for easier bootstrapping and configuration of Puppet on a
machine, e.g.:

    Blimpy.fleet do |f|
      f.add(:aws) do |s|
        s.livery = Blimpy::Livery::Puppet.configure |c|
          c.module_path = "test/modules" # This is relative to the Blimpfile's root directory
        end
      end
    end

In a way, this should fix #47
  • Loading branch information...
1 parent 0ef2733 commit 0ad9815b57d838ff25a804599ee1ad03a79fcb1c @rtyler committed Aug 25, 2012
@@ -17,7 +17,6 @@ Feature: Craft machines based on a livery
When I evaluate the Blimpfile
Then the CWD livery should be set up
- @wip
Scenario: Configuration-less liveries
Given the following Blimpfile contents:
"""
@@ -12,3 +12,8 @@
@fleet.ships.first.livery.should == Blimpy::Livery::CWD
end
+Then /^the Puppet livery should be correctly configured$/ do
+ @fleet.should_not be_nil
+ @fleet.ships.first.livery.should be_instance_of(Blimpy::Livery::Puppet)
+end
+
View
@@ -3,6 +3,7 @@
require 'archive/tar/minitar'
require 'blimpy/livery/cwd'
+require 'blimpy/livery/puppet'
module Blimpy
module Livery
View
@@ -11,10 +11,14 @@ def preflight(box)
box.scp_file(bootstrap_script, dir_name)
end
+ def use_sudo?(box)
+ box.username != 'root'
+ end
+
def flight(box)
run_sudo = 'sudo'
- if box.username == 'root'
+ if use_sudo?(box)
run_sudo = ''
end
@@ -0,0 +1,53 @@
+require 'blimpy/livery/base'
+require 'blimpy/livery/cwd'
+
+module Blimpy
+ module Livery
+ class Puppet < CWD
+ attr_accessor :module_path, :manifest_path, :options
+
+ def initialize(*args)
+ super
+ @module_path = './modules'
+ @manifest_path = 'manifests/site.pp'
+ @options = '--verbose'
+ end
+
+ def script
+ 'puppet.sh'
+ end
+
+ def flight(box)
+ # This should get our puppet.sh bootstrap script run
+ super(box)
+
+ # At this point we should be safe to actually invoke Puppet
+ command = "puppet apply --modulepath=#{module_path} #{options} #{manifest_path}"
+
+ if use_sudo?(box)
+ box.ssh_into("sudo #{command}")
+ else
+ box.ssh_into(command)
+ end
+ end
+
+ def postflight(box)
+ end
+
+ def bootstrap_script
+ File.expand_path(File.dirname(__FILE__) + "/../../scripts/#{script}")
+ end
+
+ def self.configure(&block)
+ if block.nil?
+ raise Blimpy::InvalidLiveryException, "Puppet livery must be given a block in order to configure itself"
+ end
+ instance = self.new
+ yield instance
+ instance
+ end
+
+
+ end
+ end
+end
View
@@ -40,5 +40,3 @@ else
fi
fi
-
-puppet apply --modulepath=./modules --verbose manifests/site.pp
@@ -0,0 +1,33 @@
+require 'spec_helper'
+
+require 'blimpy/livery/puppet'
+
+describe Blimpy::Livery::Puppet do
+ context 'class methods' do
+ subject { described_class }
+
+ it { should respond_to :configure }
+ describe '#configure' do
+ it 'should return an instance of the Puppet livery' do
+ result = subject.configure { |p| }
+ expect(result).to be_instance_of described_class
+ end
+
+ it 'should raise a nice error if no configuration specified' do
+ expect {
+ subject.configure
+ }.to raise_error(Blimpy::InvalidLiveryException)
+ end
+
+ it 'should yield an instance of the Puppet livery' do
+ yielded = nil
+ subject.configure { |p| yielded = p }
+ expect(yielded).to be_instance_of described_class
+ end
+ end
+ end
+
+ it { should respond_to :module_path= }
+ it { should respond_to :manifest_path= }
+ it { should respond_to :options= }
+end

0 comments on commit 0ad9815

Please sign in to comment.