Created
January 23, 2014 16:21
-
-
Save erchn/8581570 to your computer and use it in GitHub Desktop.
Custom grain based on hostname
This file contains 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
# _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