Help how to achieve the same like in Chef

50 views
Skip to first unread message

Nicolas G

unread,
Jun 19, 2015, 12:18:57 PM6/19/15
to ansible...@googlegroups.com
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.

Brian Coca

unread,
Jun 19, 2015, 12:39:15 PM6/19/15
to ansible...@googlegroups.com
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 %}
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/31ad5a40-2da3-4804-911a-b3c17cc0e493%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca

Nicolas G

unread,
Jun 21, 2015, 7:59:09 PM6/21/15
to ansible...@googlegroups.com
Thank you , that worked very well.
Reply all
Reply to author
Forward
0 new messages