Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 52 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #!/usr/bin/env ruby
  2.  
  3. require 'librarian/puppet'
  4.  
  5. lockfile = Librarian::Puppet::Lockfile.new(
  6.   Librarian::Puppet::Environment.new, 'Puppetfile.lock'
  7. )
  8.  
  9. puppet_modules = {}
  10.  
  11. lockfile.load(File.read(lockfile.path)).manifests.each do |mod|
  12.   mod_type = mod.source.class.name.split('::').last.downcase.to_sym
  13.   puppet_modules[mod_type] = {} unless puppet_modules.key?(mod_type)
  14.   puppet_modules[mod_type][mod.name.to_sym] = {}
  15.   case mod_type
  16.   when :forge
  17.     puppet_modules[mod_type][mod.name.to_sym][:version] = mod.version.to_s
  18.   when :git
  19.     puppet_modules[mod_type][mod.name.to_sym][:git] = mod.source.uri
  20.     puppet_modules[mod_type][mod.name.to_sym][:ref] = mod.source.ref
  21.   end
  22. end
  23.  
  24. puppetfile = []
  25. File.readlines('Puppetfile').each do |line|
  26.   break if line =~ /#{Regexp.escape("# Puppetfile.lock dependencies")}/
  27.   puppetfile << line
  28. end
  29. puppetfile.pop if puppetfile.last == "\n"
  30.  
  31. puppetfile << "\n# Puppetfile.lock dependencies"
  32.  
  33. puppet_modules.each do |mod_type, sources|
  34.   sources = sources.sort_by { |k, _v| k }
  35.   puppetfile << "\n# #{mod_type} modules"
  36.   sources.each do |mod, data|
  37.     case mod_type
  38.     when :forge
  39.       next if puppetfile.grep(/#{Regexp.escape(mod)}/).any?
  40.       puppetfile << "mod '#{mod}', '#{data[:version]}'"
  41.     when :git
  42.       next if puppetfile.grep(/#{Regexp.escape(data.to_h[:git])}/).any?
  43.       puppetfile << "mod '#{mod}',"
  44.       puppetfile << "    :git => '#{data[:git]}',"
  45.       puppetfile << "    :ref => '#{data[:ref]}'"
  46.     end
  47.   end
  48. end
  49.  
  50. puts puppetfile
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top