Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinquinnyo/81fb02af7e305d4d37e73963fafc937c to your computer and use it in GitHub Desktop.
Save kevinquinnyo/81fb02af7e305d4d37e73963fafc937c to your computer and use it in GitHub Desktop.
utility function for multiple sls
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