Created
March 26, 2015 10:55
-
-
Save munhitsu/f66fa0b4300669874664 to your computer and use it in GitHub Desktop.
salt module function to save dictionary as a json file
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
import json | |
import logging | |
log = logging.getLogger(__name__) | |
def save_dictionary(filename, # whe to output dictionary | |
**kwargs # the dictionary itself | |
): | |
""" | |
creates json file in a format: | |
{ | |
"key1":"value1", | |
... | |
} | |
discarding all keys starting from "__" as it's used internally by salt | |
saves file as salt running user with current umask | |
""" | |
data = {} | |
for k, v in kwargs.iteritems(): | |
if not k.startswith("__"): | |
data[k] = v | |
with open(filename, mode='w') as f: | |
f.write(json.dumps(data, sort_keys=True, indent=2)) | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment