【问题标题】:ansible: filter one element of the list to stringansible:将列表中的一个元素过滤为字符串
【发布时间】:2020-09-09 18:42:05
【问题描述】:

ansible 2.9.13

需要添加到远程文件字符串如 MyIP = xxx.xxx.xxx.xxx

这是一个测试模板:

MyIP = {{ ansible_all_ipv4_addresses | select('match', '^10\.0\.59') | list}}

结果

>cat testfile.txt
MyIP = ['10.0.59.100']

问题:我需要添加什么过滤器,才能将 IP 值作为字符串。或者使用其他方法?

【问题讨论】:

    标签: ansible jinja2 ansible-template ansible-filter


    【解决方案1】:

    如果这是你想要的,取列表的第一个元素

    MyIP = {{ ansible_all_ipv4_addresses | select('match', '^10\.0\.59') | first }}
    

    【讨论】:

    • MyIP = 10.0.59.100 谢谢
    猜你喜欢
    • 2019-08-03
    • 1970-01-01
    • 1970-01-01
    • 2021-06-22
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多