小编dei*_*dei的帖子

将 Ansible 对象列表减少为串联对象值的单个字符串

我正在尝试解析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

3
推荐指数
1
解决办法
5360
查看次数

标签 统计

ansible ×1