Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python
import json
import argparse
import sys
import os
import subprocess
parser = argparse.ArgumentParser(description='Add puppet module to metadata.json')
parser.add_argument('--version', nargs="?", default="latest")
parser.add_argument('action', nargs="*")
args = parser.parse_args()
if len(sys.argv) == 1:
if not args.action[0] in ['install']:
version = args.version
actionName = args.action[0]
module = None if len(args.action) < 2 else args.action[1]
if module != None:
with open('composer/metadata.json') as json_data:
data = json.load(json_data)
for item in data['dependencies']:
if item['name'] == module:
print "Module %s is already declared in metadata.json" % (module)
data['dependencies'].extend([{'version_requirement': version, 'name': module}])
print "Writing metadata.json"
with open('composer/metadata.json', 'w') as outfile:
json.dump(data, outfile, indent=4)
if actionName == 'install':
cwd = os.path.dirname(os.path.realpath(__file__))
os.chdir( cwd )
print "Updating modules"["rm", "-rf", "./modules/composer"])["tar", "-zcf", "composer.tar.gz", "composer"])
print subprocess.check_output(["puppet", "module", "install", "composer.tar.gz", "--modulepath=./modules"])["rm", "-f", "composer.tar.gz"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.