ansible: filter one element of the list to string

Viewed 294

ansible 2.9.13

Need to add to the remote file string like MyIP = xxx.xxx.xxx.xxx

Here is a test template:

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

result

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

Question: What filter i need to add, to get IP value as string. or maybe use some other method?

1 Answers

Take the first element of the list if this is what you want

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