Skip to content

Instantly share code, notes, and snippets.

@erchn
Created January 23, 2014 16:21
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 erchn/8581570 to your computer and use it in GitHub Desktop.
Save erchn/8581570 to your computer and use it in GitHub Desktop.
Custom grain based on hostname
# _grains/myenv.py
import sys
import socket
import re
import platform
# Extend the default list of supported distros. This will be used for the
# /etc/DISTRO-release checking that is part of platform.linux_distribution()
from platform import _supported_dists
_supported_dists += ('arch', 'mageia', 'meego', 'vmware', 'bluewhite64',
'slamd64', 'enterprise', 'ovs', 'system')
import salt.utils
# Solve the Chicken and egg problem where grains need to run before any
# of the modules are loaded and are generally available for any usage.
import salt.modules.cmdmod
__salt__ = {
'cmd.run': salt.modules.cmdmod._run_quiet,
}
def myenv():
grains = {}
hostname = socket.gethohostname()
if re.match('web', hostname):
grains['myenv'] = 'production'
elif ...
...
return grains
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment