Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ansible: filter one element of the list to string

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?

like image 651
Alexander Lanin Avatar asked Nov 25 '25 10:11

Alexander Lanin


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 }}
like image 118
Vladimir Botka Avatar answered Nov 28 '25 17:11

Vladimir Botka