Skip to content

Instantly share code, notes, and snippets.

@dnd
Last active August 29, 2015 14:13
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 dnd/f96853b6837331113929 to your computer and use it in GitHub Desktop.
Save dnd/f96853b6837331113929 to your computer and use it in GitHub Desktop.
environment custom grain
#!/usr/bin/env python
import salt.config
import salt.loader
import salt.utils
__opts__ = salt.config.minion_config('/etc/salt/minion')
envutil = salt.loader.raw_mod(__opts__, 'envutil', None)
def environment():
fqdn = salt.utils.network.get_fqhostname()
host = fqdn.partition('.')[0]
grains = {}
grains['environment'] = envutil['envutil.infer_env_from_name'](host)
grains['whydontyouexist'] = __grains__
return grains
root@dev-app1:~# salt-minion --versions-report
Salt: 2014.7.0-1077-g378639f
Python: 2.6.5 (r265:79063, Feb 27 2014, 19:43:51)
Jinja2: 2.7.3
M2Crypto: 0.20.1
msgpack-python: 0.1.9.final
msgpack-pure: Not Installed
pycrypto: 2.0.1
libnacl: Not Installed
PyYAML: 3.09
ioflo: Not Installed
PyZMQ: 13.0.0
RAET: Not Installed
ZMQ: 3.2.2
Mako: 1.0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment