Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. list1:
  2. - { endpoint: {address: "addr1", port: "port1"}}
  3. - { endpoint: {address: "addr2", port: "port2"}}
  4.  
  5. elasticache_facts:
  6. region: "{{ terraform.region }}"
  7. name: "{{ cluster }}-{{ env }}"
  8. register: elasticache
  9.  
  10. #declare an empty var in vars file to be used as accumulator
  11. memcache_hosts: ""
  12.  
  13. # iterate through the list of nodes and append the fields to my string; I will have some extra spaces(separators) but that's ok
  14. set_fact:
  15. memcache_hosts: "{{ memcache_hosts }} {{item.endpoint.address}}:{{item.endpoint.port}}"
  16. with_items: "{{ elasticache.elasticache_clusters[0].cache_nodes}}"```
  17.  
  18. Is there some less ugly way to filter the list to the desired format?
  19. Maybe there is a magic filter I don't know about.
  20. I can also obtain two lists, one with hosts, one with ports, zip them, make a dict out of that, but I found only some ugly to_json and then regex to make it a string.
  21. I am also considering to write a custom filter in python, but seems also overdoing it.
  22.  
  23. Thanks for the help!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement