Created
April 10, 2016 18:54
-
-
Save kevinquinnyo/81fb02af7e305d4d37e73963fafc937c to your computer and use it in GitHub Desktop.
utility function for multiple sls
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
def get_role_ips(role, interface='eth1'): | |
billing_id = __pillar__['cluster']['client']['billing_id'] | |
cluster_name = __pillar__['cluster']['name'] | |
ips = [] | |
interfaces = __salt__['mine.get']('{0}*{1}-{2}.my-platform-domain.com'.format(role, billing_id, cluster_name), 'network.interfaces') | |
for minion, interface in interfaces.iteritems(): | |
for name, data in interface.iteritems(): | |
if name == interface: | |
ips.append(data['inet'][0]['address']) | |
return ips | |
# usage: | |
web_public_ips = get_role_ips('web', interface='eth0') | |
db_private_ips = get_role_ips('db') | |
# Question: How can i re-use this function in multiple states accross my codebase in saltstack? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment