Skip to content

Instantly share code, notes, and snippets.

@Gurpartap
Created March 11, 2020 16:50
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 Gurpartap/ed37616f47af6c1c08ee73f01b7fb284 to your computer and use it in GitHub Desktop.
Save Gurpartap/ed37616f47af6c1c08ee73f01b7fb284 to your computer and use it in GitHub Desktop.
derive a list of dicts from ansible groups and hostvars
vars:
zookeeper_nodes: "\
{% set _zookeeper_servers = [] %}\
{% for host in groups.zookeeper %}\
{% set _zookeeper_client_port_address = hostvars[host]['zookeeper_client_port_address'] | default('0.0.0.0', true) %}\
{% set _zookeeper_client_port = hostvars[host]['zookeeper_client_port'] | default(2181, true) %}\
{% if _zookeeper_servers.append(dict(['host', 'port'] | zip([_zookeeper_client_port_address, _zookeeper_client_port]))) %}{% endif %}\
{% endfor %}\
{{ _zookeeper_servers }}"
# debug:
#
# "zookeeper_nodes": [
# {
# "host": "192.168.1.27",
# "port": 2181
# },
# {
# "host": "192.168.1.115",
# "port": 2181
# },
# {
# "host": "192.168.1.13",
# "port": 2181
# }
# ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment