-
-
Save UtahDave/5201604 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
""" | |
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 | |
This file contains hidden or 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
{% 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