Skip to content

Instantly share code, notes, and snippets.

@logicminds
Created October 30, 2014 16:47
Show Gist options
  • Save logicminds/41550c3fafefecc9dc48 to your computer and use it in GitHub Desktop.
Save logicminds/41550c3fafefecc9dc48 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Author: Corey Osman
# Date: 10/29/14
# Purpose: converts the puppetfile to a .fixtures file yaml format
#
# State: works on my machine, but needs further development to support the full Puppetfile DSL and .fixtures DSL
# Usage: from the module directory ensure you have a Puppetfile.
# because destruction of any .fixtures file could be deadly you must set the WIPE_FIXTURES env varialble to true.
# $ WIPE_FIXTURES=true ruby puppetfile_to_fixtures.rb
require 'yaml'
def repos
@repos ||= {}
end
def mod(name, properties)
return if name.nil?
repos[name] = {}
if ! properties.nil?
# This will only consume lines with repo and ref. Support for all the other types like symlinks, forge modules
# would need to be added
repos[name]['repo'] = "#{properties[:git]}"
repos[name]['ref'] = properties[:ref] if ! properties[:ref].nil?
end
end
File.open('Puppetfile', 'r') do |file|
data = file.read
eval data
end
if repos.length > 0 and ENV['WIPE_FIXTURES'] =~ /true/i
File.open('.fixtures.yml', 'w') do |file|
fixtures = {}
fixtures['fixtures'] = {}
fixtures['fixtures']['symlinks'] = {'directory_name' => 'source_dir'}
fixtures['fixtures']['repositories'] = repos
file.write(fixtures.to_yaml)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment