我正在尝试解析elasticache_factsansible 模块的输出,以“addr1: port1 addr2:port2 ...”形式的字符串提取 IPS 和 memcached 节点的端口(我想将此字符串存储在 configmap 中在应用程序中使用)。
基本上我想从这样的字典列表中获取两个字段“地址”和“端口”:
list1:
- endpoint:
address: "addr1"
port: "port1"
- endpoint:
address: "addr2"
port: "port2"
Run Code Online (Sandbox Code Playgroud)
并像上面一样连接它们。
我有一个丑陋的解决方案,如下所示:
# register the output of the facts to something I know
elasticache_facts:
region: "{{ terraform.region }}"
name: "{{ cluster }}-{{ env }}"
register: elasticache
#declare an empty var in vars file to be used as accumulator
memcache_hosts: ""
# iterate through the list of nodes and append the fields to my …Run Code Online (Sandbox Code Playgroud) ansible ×1