Created
October 28, 2015 00:24
-
-
Save cloudnull/82227ad73629e6744279 to your computer and use it in GitHub Desktop.
This file contains 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
diff --git a/playbooks/plugins/filters/osa-filters.py b/playbooks/plugins/filters/osa-filters.py | |
index 61ca112..f18f873 100644 | |
--- a/playbooks/plugins/filters/osa-filters.py | |
+++ b/playbooks/plugins/filters/osa-filters.py | |
@@ -187,6 +187,34 @@ def git_link_parse_name(repo): | |
return git_link_parse(repo)['name'] | |
+def format_haproxy_servers(servers_group, default_port, params, | |
+ connection='ansible_ssh_host'): | |
+ """Return a list of dicts from from groups. | |
+ | |
+ :param servers_group: Ansible group of names of servers. | |
+ :type servers_group: ``list`` | |
+ :param default_port: port to blance traffic on. | |
+ :type default_port: ``int`` | |
+ :param params: list of params to pass into haproxy. | |
+ :type params: ``list`` | |
+ :param connection: Network connection name. | |
+ :type connection: ``str`` | |
+ :returns: ``list`` | |
+ """ | |
+ return_list = list() | |
+ for server in servers_group: | |
+ entry = { | |
+ 'name': server, | |
+ 'ip': '{{ hostvars[%s]["%s"] }}:{{ %s }}' % ( | |
+ server, connection, default_port | |
+ ), | |
+ 'params': params | |
+ } | |
+ return_list.append(entry) | |
+ else: | |
+ return return_list | |
+ | |
+ | |
class FilterModule(object): | |
"""Ansible jinja2 filters.""" | |
@@ -202,5 +230,6 @@ class FilterModule(object): | |
'splitlines': splitlines, | |
'filtered_list': filtered_list, | |
'git_link_parse': git_link_parse, | |
- 'git_link_parse_name': git_link_parse_name | |
+ 'git_link_parse_name': git_link_parse_name, | |
+ 'format_haproxy_servers': format_haproxy_servers | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
This will return a list of servers like this