Getting hostvars when using serial

Hello Group,

I’m looking for a way to access facts for my hostnames through the hostvars and groups methods. This all works well, but I’m stuck when I try to limit the batch size with the “serial” directive.

For example: I have 10 web servers that I want to do rolling update using the “serial: 50%”.

{% for host in groups['app_servers'] %}
   {{ hostvars[host]['ansible_eth0']['ipv4']['address'] }}
{% endfor %}

Using the above example will give me all hosts in the group “app_servers” and there is no way to get only 50% of the hosts.

Is there a way to get facts information for “all hosts in the scope” and “all hosts outside of scope”?

you could use the loop.index and compare against group[‘app_servers’]|length to break the loop at the serial point.