Help how to achieve the same like in Chef

Hi,

I’m trying to migrate from Chef a recipe for HAProxy.

In the bellow config one of the pool groups are considered to be coming from slow server connections and we isolate them to use certain number of web servers and not all of them as when you have lot’s of requests with relatively higher timeouts it could cause other servers with normal latency to starve.

In order to accomplish this in Chef we assign 1 of every 5 servers to the slow_pool_members and every 4 server to the normal_pool_members :

slow_pool_members = []
normal_pool_members = []

pool_members.each_with_index do |member, i|
  if i % 5 == 4
    slow_pool_members << member
  else
    normal_pool_members << member
  end
end

The above in Chef is Ruby code, can someone help me how can I do something similar in Ansible ?

Regards,
N.

many ways to do this, I would just use a configuration template:

# in slow pool part of config
{% for host in fullpool %}
{% if loop.index % 5 == 4 %}
{{host}}
{% endif%}
{% endfor %}

# in normal pool part of config
{% for host in fullpool %}
{% if loop.index % 5 != 4 %}
{{host}}
{% endif%}
{% endfor %}

Thank you , that worked very well.