Alexander Lanin
Alexander Lanin

Reputation: 435

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?

Upvotes: 3

Views: 1614

Answers (1)

Vladimir Botka
Vladimir Botka

Reputation: 67984

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

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

Upvotes: 3

Related Questions