ansible:将列表中的一个元素过滤为字符串

ansible: filter one element of the list to string

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 值作为字符串获取。或者使用其他方法?

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

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