I have a playbook that installs elasticsearch using a role
elasticsearch version is defined in the host file as a variable along each server name
I have a group with all the hosts needing elasticsearch
Until then, we were using elasticsearch 0.90.x (x is 2,3 or 9).
Now, I need to install BOTH the 0.90.x and the new 1.0.1 version at the same time.
While the playbook can handle that, I can’t find a way to have the role played twice, once for each version ?
The only solution so far is calling the role twice and statically setting the version on each call, which is not acceptable.
One solution would be to call the role using a with_item statement to have it run for every version is defined in a dict… but this is deprecated…
Any clue ?
You have to restructure the playbooks to loop within the role itself (perhaps have a list with versions to install in your variables), or call the role twice. I would really like to see some mechanism to loop over a role, but with that said, you should be able to find a solution.
Why is calling the role twice not acceptable? I have a playbook that calls a role in 50 different ways, depending on how it’s executed. While it’s a bit long, it is structured simply, and easily understood.
I had similar decisions to make, and looping within the role wasn’t something I was happy with, so I ended up applying the role multiple times, which really isn’t all that painful IMO. My problems with looping within the role (for my use case) was that I needed to use with_items for many tasks, which led to added complexity of the playbook - I understood perfectly what was required and being performed, but collaboration with other folks at my organization that are new to Ansible would prove difficult.
Thanks for the answer.
As I can’t loop a role execution, I would have to hard code the number of call to the role. If next week I need to deploy a third version, i’ll have to edit the playbook again to add the role one more time… and so on. Not really smart.
We ended using a with_items on almost every tasks in the playbook…
I really think there is something to thing of about this. Ansible should have a way to manage the administration of two different versions of something installed using the same playbook…