Last active
March 23, 2016 19:18
-
-
Save panchiz/b3f6cdeae77f08e6e00f to your computer and use it in GitHub Desktop.
Generate Puppetfile from metadata.json
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
#!/bin/bash | |
# | |
# List all the Puppet modules in an environment and generates the Puppetfile rows | |
# using the "metadata.json". | |
ENVIRONMENT=${1:-production} | |
MODULES="/etc/puppetlabs/code/environments/$ENVIRONMENT/modules" | |
RUBY_BIN=/opt/puppetlabs/puppet/bin/ruby | |
for metadata in $(ls $MODULES/*/metadata.json); do | |
cat $metadata | $RUBY_BIN -r json -e " | |
begin | |
j = JSON.parse(ARGF.read, symbolize_names: true) | |
puts \"mod '#{j[:name]}', '#{j[:version]}'\" | |
puts \"# dependencies for #{j[:name]}\" | |
j[:dependencies].each do |dep| | |
puts \"# mod '#{dep[:name]}', '#{dep[:version_requirement]}'\" | |
end | |
puts \"\" | |
rescue | |
nil | |
end" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment