Skip to content

Instantly share code, notes, and snippets.

@andy-s-clark
Created July 17, 2015 16:11
Show Gist options
  • Save andy-s-clark/7d8057c4db7d5ef8306a to your computer and use it in GitHub Desktop.
Save andy-s-clark/7d8057c4db7d5ef8306a to your computer and use it in GitHub Desktop.
Convert Foreman YAML to Puppet hiera yaml
#!/usr/bin/env python
## USAGE
# ./foreman_yaml.py < myserver.foreman.yaml > myserver.puppet.yaml
## Convert Foreman YAML:
# classes:
# build_environment_vars:
# env_vars: SERVER_ENVIRONMENT=development
# build_java:
# java_major_release: '8'
# java_minor_release: '40'
#
## To puppet hiera yaml:
# build_environment_vars::env_vars: SERVER_ENVIRONMENT=development
# build_java::java_major_release: '8'
# build_java::java_minor_release: '40'
import sys
import yaml
doc = yaml.load(sys.stdin)
try:
if hasattr(doc['classes'], 'items'):
newdoc = {}
for className, classParameters in doc['classes'].items():
if hasattr(classParameters, 'items'):
for parameterName, parameterValues in classParameters.items():
newdoc["%s::%s" % (className, parameterName)] = parameterValues
print(yaml.dump(newdoc))
except NameError:
print('No classes defined')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment