diff --git a/README.md b/README.md index 6182da8..77162c2 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/Vagrantfile b/Vagrantfile index 2f0dbe4..590f4de 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -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 diff --git a/lib/vagrant-librarian-puppet/action/librarian_puppet.rb b/lib/vagrant-librarian-puppet/action/librarian_puppet.rb index 1cebd50..26eda6e 100644 --- a/lib/vagrant-librarian-puppet/action/librarian_puppet.rb +++ b/lib/vagrant-librarian-puppet/action/librarian_puppet.rb @@ -15,12 +15,7 @@ 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. @@ -28,10 +23,27 @@ def call(env) 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 ) @@ -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 @@ -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? diff --git a/lib/vagrant-librarian-puppet/config.rb b/lib/vagrant-librarian-puppet/config.rb index 6d5c551..e7504ab 100644 --- a/lib/vagrant-librarian-puppet/config.rb +++ b/lib/vagrant-librarian-puppet/config.rb @@ -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 diff --git a/manifests/multidir.pp b/manifests/multidir.pp new file mode 100644 index 0000000..71085e7 --- /dev/null +++ b/manifests/multidir.pp @@ -0,0 +1,9 @@ +class dev { + + include git + include supervisor + include ntp + +} + +include dev diff --git a/puppet/modules/.gitkeep b/puppet/modules/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/puppet_custom/Puppetfile b/puppet_custom/Puppetfile new file mode 100644 index 0000000..b4846ca --- /dev/null +++ b/puppet_custom/Puppetfile @@ -0,0 +1,5 @@ +# Manage Puppet module dependencies with librarian-puppet + +forge 'http://forge.puppetlabs.com' + +mod 'puppetlabs/ntp' diff --git a/puppet_custom/modules/.gitkeep b/puppet_custom/modules/.gitkeep new file mode 100644 index 0000000..e69de29