Skip to content

Instantly share code, notes, and snippets.

@UtahDave
Forked from auser/informer.py
Created March 20, 2013 01:21
Show Gist options
  • Save UtahDave/5201604 to your computer and use it in GitHub Desktop.
Save UtahDave/5201604 to your computer and use it in GitHub Desktop.
"""
This enables us to call the minions and search for a specific role
"""
import logging
import salt.utils
log = logging.getLogger(__name__)
def all_by_roles(*args, **kwards):
"""
Get all the hosts by their roles
"""
ret = {}
nodes = __salt__['publish.publish']('*', 'grains.item', 'role')
for name, found_role in nodes.items():
log.info("found {0} {1}".format(name, found_role['role']))
node = __salt__['publish.publish'](name, *args, **kwards)
if node:
for _, value in node.items():
if found_role['role'] == 'master':
role = 'saltmaster'
else:
role = found_role['role']
ip = value.pop()
log.info("Informer found: [{0}] = {1}".format(role, ip))
ret[role] = ip
return ret
{% for name, ip in salt['informer.all_by_roles']('network.ip_addrs','eth1').items() %}
{{ name }}_host:
host.present:
- ip: {{ ip }}
- name: {{ name }}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment