Skip to content

Instantly share code, notes, and snippets.

@acidprime
Last active August 29, 2015 14:17
Show Gist options
  • Save acidprime/940f75d82e7acb21babc to your computer and use it in GitHub Desktop.
Save acidprime/940f75d82e7acb21babc to your computer and use it in GitHub Desktop.
This is a Puppetfile that will automatically download all supported+approved modules from the forge
#!/usr/bin/ruby
require 'puppet_forge'
# Example of a module from an internal repo co-existing with forge modules.
#mod 'splunk',
# :git => 'https://internal.git.server/example/puppet-splunk.git',
# :commit => '3ca47046a86aef9fbfdf58cc7b418d8e7254ecb9'
@dependencies = []
@approved = []
@supported = []
def populate_module_dependencies(forge_module)
forge_module.current_release.metadata['dependencies'].each do |dependency|
@dependencies << dependency['name']
end
end
def add_modules()
modules = (@dependencies << @approved << @supported).flatten
modules.compact.uniq.each do |dependency|
mod dependency.sub('-','/')
end
end
def populate_supported_modules
PuppetForge::Module.where( supported: 'true' ).unpaginated.each do |supported|
@supported << "#{supported.owner.username}/#{supported.name}"
populate_module_dependencies supported
end
end
def populate_approved_modules
PuppetForge::Module.where( endorsements: 'approved' ).unpaginated.each do |approved|
@approved << "#{approved.owner.username}/#{approved.name}"
populate_module_dependencies approved
end
end
populate_supported_modules
populate_approved_modules
add_modules
@acidprime
Copy link
Author

You can test this locally with the following:

gem install puppet_forge
gem install r10k
git clone [email protected]:/940f75d82e7acb21babc.git
cd 940f75d82e7acb21babc/
r10k puppetfile install -v debug
ls -l ./modules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment