Skip to content

Commit

Permalink
implements multiple puppet directories
Browse files Browse the repository at this point in the history
added test box for multidir, .gitkeep for modules dirs
  • Loading branch information
endyman committed Jan 13, 2015
1 parent 3eee3b3 commit 0f3f2dd
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 21 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -24,6 +24,11 @@ using the `librarian_puppet.puppetfile_dir` config key. Please keep in mind
that you will need to explicitly set the `modules` path in the
`:puppet` provisioner and this path must exist before running vagrant commands.

Like the `puppet.module_path`, `librarian_puppet.puppetfile_dir` supports both,
a simple String or an Array of Strings. Librarian Puppet will look for Puppetfiles
in each Directory and manage each modules directory.


**NOTE:** Since the puppet provisioner will fail if the path provided to
"puppet.modules" doesn't exist and librarian-puppet will destroy and recreate
the modules directory on each run, this plugin supports a placeholder file
Expand Down
26 changes: 20 additions & 6 deletions Vagrantfile
Expand Up @@ -6,13 +6,27 @@ Vagrant.configure('2') do |config|
config.vm.box = 'precise64'
config.vm.box_url = 'http://files.vagrantup.com/precise64.box'

config.librarian_puppet.puppetfile_dir = 'puppet'
config.librarian_puppet.resolve_options = { :force => true }
config.vm.define "default" do |default|
default.librarian_puppet.puppetfile_dir = 'puppet'
default.librarian_puppet.placeholder_filename = ".gitkeep"
default.librarian_puppet.resolve_options = { :force => true }

config.vm.provision :puppet do |puppet|
puppet.manifests_path = 'manifests'
puppet.manifest_file = 'init.pp'
puppet.module_path = 'puppet/modules'
default.vm.provision :puppet do |puppet|
puppet.manifests_path = 'manifests'
puppet.manifest_file = 'init.pp'
puppet.module_path = 'puppet/modules'
end
end

config.vm.define "multidir" do |multidir|
multidir.librarian_puppet.puppetfile_dir = ['puppet', 'puppet_custom']
multidir.librarian_puppet.placeholder_filename = ".gitkeep"
multidir.librarian_puppet.resolve_options = { :force => true }

multidir.vm.provision :puppet do |puppet|
puppet.manifests_path = 'manifests'
puppet.manifest_file = 'multidir.pp'
puppet.module_path = ['puppet_custom/modules', 'puppet/modules']
end
end
end
33 changes: 20 additions & 13 deletions lib/vagrant-librarian-puppet/action/librarian_puppet.rb
Expand Up @@ -15,23 +15,35 @@ def initialize(app, env)

def call(env)
config = env[:machine].config.librarian_puppet
if
provisioned? and
File.exist? File.join(env[:root_path], config.puppetfile_path)

env[:ui].info "Installing Puppet modules with Librarian-Puppet..."

if provisioned?
# NB: Librarian::Puppet::Environment calls `which puppet` so we
# need to make sure VAGRANT_HOME/gems/bin has been added to the
# path.
original_path = ENV['PATH']
bin_path = env[:gems_path].join('bin')
ENV['PATH'] = "#{bin_path}#{::File::PATH_SEPARATOR}#{ENV['PATH']}"

puppetfile_dirs = config.puppetfile_dir.kind_of?(Array) ? config.puppetfile_dir : [config.puppetfile_dir]

puppetfile_dirs.each do |puppetfile_dir|
provision(puppetfile_dir, env, config)
end

# Restore the original path
ENV['PATH'] = original_path
end
@app.call(env)
end

def provision(puppetfile_dir, env, config)
if File.exist? File.join(env[:root_path], config.puppetfile_path(puppetfile_dir))

env[:ui].info "Installing Puppet modules in \"#{puppetfile_dir}\" with Librarian-Puppet..."

# Determine if we need to persist placeholder file
placeholder_file = File.join(
env[:root_path],
config.puppetfile_dir,
puppetfile_dir,
'modules',
config.placeholder_filename
)
Expand All @@ -42,7 +54,7 @@ def call(env)
end

environment = Librarian::Puppet::Environment.new({
:project_path => File.join(env[:root_path], config.puppetfile_dir)
:project_path => File.join(env[:root_path], puppetfile_dir)
})
environment.config_db.local['destructive'] = config.destructive.to_s
environment.config_db.local['use-v1-api'] = config.use_v1_api
Expand All @@ -51,18 +63,13 @@ def call(env)
Librarian::Action::Resolve.new(environment, config.resolve_options).run
Librarian::Puppet::Action::Install.new(environment).run

# Restore the original path
ENV['PATH'] = original_path

# Persist placeholder if necessary
if placeholder_contents != nil
File.open(placeholder_file, 'w') { |file|
file.write(placeholder_contents)
}
end

end
@app.call(env)
end

def provisioned?
Expand Down
4 changes: 2 additions & 2 deletions lib/vagrant-librarian-puppet/config.rb
Expand Up @@ -31,8 +31,8 @@ def validate(machine)
return { 'vagrant-librarian-puppet' => errors }
end

def puppetfile_path
@puppetfile_path ||= @puppetfile_dir ? File.join(@puppetfile_dir, 'Puppetfile') : 'Puppetfile'
def puppetfile_path(puppetfile_dir)
@puppetfile_path ||= puppetfile_dir ? File.join(puppetfile_dir, 'Puppetfile') : 'Puppetfile'
end

def use_v1_api
Expand Down
9 changes: 9 additions & 0 deletions manifests/multidir.pp
@@ -0,0 +1,9 @@
class dev {

include git
include supervisor
include ntp

}

include dev
Empty file added puppet/modules/.gitkeep
Empty file.
5 changes: 5 additions & 0 deletions puppet_custom/Puppetfile
@@ -0,0 +1,5 @@
# Manage Puppet module dependencies with librarian-puppet

forge 'http://forge.puppetlabs.com'

mod 'puppetlabs/ntp'
Empty file added puppet_custom/modules/.gitkeep
Empty file.

0 comments on commit 0f3f2dd

Please sign in to comment.