Minion-specific etcd values

This allows you to specify something such as the following in your
master config to get minion-specific values in etcd that may override
shared values.

    local_etcd:
      host: 127.0.0.1
      port: 4001

    ext_pillar:
      - etcd: local_etcd root=/salt-shared
      - etcd: local_etcd root=/salt-private/%(minion_id)s
This commit is contained in:
Josh VanderLinden 2014-04-27 00:05:45 -06:00
parent 9c43e634b6
commit 470bce8927

View File

@ -40,7 +40,7 @@ import logging
# Import third party libs
try:
import salt.utils.etcd_util
from salt.utils import etcd_util
HAS_LIBS = True
except Exception:
HAS_LIBS = False
@ -67,10 +67,21 @@ def ext_pillar(minion_id, pillar, conf): # pylint: disable=W0613
profile = None
if comps[0]:
profile = comps[0]
client = salt.utils.etcd_util.get_conn(__opts__, profile)
client = etcd_util.get_conn(__opts__, profile)
path = '/'
if len(comps) > 1 and comps[1].startswith('root='):
path = comps[1].replace('root=', '')
return salt.utils.etcd_util.tree(client, path)
# put the minion's ID in the path if necessary
path %= {
'minion_id': minion_id
}
try:
pillar = etcd_util.tree(client, path)
except KeyError:
log.error('No such key in etcd profile %s: %s' % (profile, path))
pillar = {}
return pillar