Last active
June 21, 2018 13:32
-
-
Save timbirk/b8ec23934b4d5c6c4943d0f3c4105947 to your computer and use it in GitHub Desktop.
Generate repo / forge modules for itv.yaml file from existing Puppetfile.lock (captures all deps)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'librarian/puppet' | |
lockfile = Librarian::Puppet::Lockfile.new( | |
Librarian::Puppet::Environment.new, 'Puppetfile.lock' | |
) | |
puppet_modules = {} | |
lockfile.load(File.read(lockfile.path)).manifests.each do |mod| | |
mod_type = mod.source.class.name.split('::').last.downcase.to_sym | |
puppet_modules[mod_type] = {} unless puppet_modules.key?(mod_type) | |
puppet_modules[mod_type][mod.name.to_sym] = {} | |
case mod_type | |
when :forge | |
puppet_modules[mod_type][mod.name.to_sym][:version] = mod.version.to_s | |
when :git | |
puppet_modules[mod_type][mod.name.to_sym][:git] = mod.source.uri | |
puppet_modules[mod_type][mod.name.to_sym][:ref] = mod.source.ref | |
end | |
end | |
itvout = [] | |
itvout << "\n# Generated by lp2itv.rb\n# https://gist.github.com/timbirk/b8ec23934b4d5c6c4943d0f3c4105947" | |
puppet_modules.each do |mod_type, sources| | |
sources = sources.sort_by { |k, _v| k } | |
itvout << if mod_type == :git | |
"\n repo_modules:" | |
else | |
"\n #{mod_type}_modules:" | |
end | |
sources.each do |mod, data| | |
case mod_type | |
when :forge | |
next if itvout.grep(/#{Regexp.escape(mod)}/).any? | |
itvout << " #{mod}:" | |
itvout << " repo: '#{mod}'" | |
itvout << " ref: '#{data[:version]}'" | |
when :git | |
next if itvout.grep(/#{Regexp.escape(data.to_h[:git])}/).any? | |
itvout << " #{mod}:" | |
itvout << " repo: '#{data[:git]}'" | |
itvout << " ref: '#{data[:ref]}'" | |
end | |
end | |
end | |
puts itvout |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You will almost certainly find issues with your modules and the dependencies for our Puppet profiles.