Skip to content

Instantly share code, notes, and snippets.

@panchiz
Last active March 23, 2016 19:18
Show Gist options
  • Save panchiz/b3f6cdeae77f08e6e00f to your computer and use it in GitHub Desktop.
Save panchiz/b3f6cdeae77f08e6e00f to your computer and use it in GitHub Desktop.
Generate Puppetfile from metadata.json
#!/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