Skip to content

Instantly share code, notes, and snippets.

@andygrunwald
Created February 24, 2015 10:16
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 andygrunwald/8b43429b66fbff8f7863 to your computer and use it in GitHub Desktop.
Save andygrunwald/8b43429b66fbff8f7863 to your computer and use it in GitHub Desktop.
Custom saltstack grain to identify the redis version
# -*- 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