Skip to content

Instantly share code, notes, and snippets.

@zippyz
Created October 4, 2012 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zippyz/3835263 to your computer and use it in GitHub Desktop.
Save zippyz/3835263 to your computer and use it in GitHub Desktop.
__description__ = "Salt Grain for gathering an environment variable"
import os,sys,logging
#logging.basicConfig(level=logging.DEBUG)
from pprint import pprint
def _file_get_contents(filename):
if os.path.exists(filename):
content = {}
with open(filename, "r") as _file:
for line in _file:
(key, val) = line.split()
content[str(key)] = val
_file.close()
return content
def return_grains():
grains = {}
filename = "/environment"
# grains['custom_env'] = _file_get_contents(filename)
grains = _file_get_contents(filename)
if 'env_grain':
pprint(grains)
# print(type(grains))
return grains
return_grains()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment