Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- '''
- Adds a hiera key to pillar
- '''
- # Import python libs
- import logging
- import sys
- # Import salt libs
- import salt.utils
- from salt._compat import string_types
- # Import third party libs
- import yaml
- # Set up logging
- log = logging.getLogger(__name__)
- def __virtual__():
- '''
- Only return if hiera_lyft is installed
- '''
- return 'hiera_cached' if salt.utils.which('hiera') else False
- def ext_pillar(minion_id, pillar, conf_dir, conf_file):
- '''
- Execute hiera and return the data
- '''
- data = {}
- cmd = ('hiera {0} -c {1}')
- for func in __salt__.values():
- try:
- log.info(func.__module__)
- ext_pillars = sys.modules[func.__module__].__ext_pillars__
- for pillar in ext_pillars:
- cmd = cmd.format(pillar, conf_file)
- try:
- log.info('Running {0}'.format(cmd))
- ret = __salt__['cmd.run'](cmd)
- if ret == 'nil':
- return {}
- else:
- ret = ret.replace('=>', ':')
- ret = yaml.safe_load(ret)
- data[pillar] = ret
- except Exception:
- msg = 'Hiera YAML data failed to parse from conf {0}'
- log.critical(msg.format(conf_file))
- except AttributeError:
- pass
- return data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement