Created
February 24, 2015 10:16
-
-
Save andygrunwald/8b43429b66fbff8f7863 to your computer and use it in GitHub Desktop.
Custom saltstack grain to identify the redis version
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
# -*- coding: utf-8 -*- | |
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 | |
def redis_version(): | |
''' | |
Return version of redis-cli by `redis-cli --version`: | |
Version output: | |
--------- | |
$ redis-cli --version | |
redis-cli 2.8.14 | |
--------- | |
''' | |
# Determine redis binary | |
redis = salt.utils.which('redis-cli') | |
if not redis: | |
return {} | |
# Get the version string from redis | |
try: | |
redis_version = salt.modules.cmdmod._run_quiet('{0} --version'.format(redis)).replace('redis-cli', '').strip() | |
except OSError: | |
return {} | |
result = { | |
'redis_version': redis_version | |
} | |
return result | |
if __name__ == '__main__': | |
print redis_version() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment