1

I have an ansible invetory file with 1 group with 3 IPs listed.

[servers]
server-0 ansible_host=10.255.31.7
server-1 ansible_host=10.255.31.9
server-2 ansible_host=10.255.31.8

I want to be able to set a variable that only has the 1st 2 IPs

I've been able to set a variable with all 3 using

seeds: "{{ hostvars.values()|map(attribute='ansible_host')|join(',') }}"

which results in

10.255.31.7,10.255.31.9,10.255.31.8

But I don't want all 3 IPs, I only want the first 2 which should be

10.255.31.7,10.255.31.8

I have not been able to figure it out yet, hoping someone can help. Thanks

I've tried several things all to no avail

I'm expecting the IP list to be 10.255.31.7,10.255.31.8

RobA
  • 51
  • 3
  • 2
    `hostvars.values()|map(attribute='ansible_host')[:2]|join(',')`, using [python slicing](https://stackoverflow.com/questions/509211/understanding-slicing/509295#509295) – β.εηοιτ.βε Oct 31 '22 at 19:46

0 Answers0