this post was submitted on 29 Nov 2024
5 points (85.7% liked)

Ansible

240 readers
1 users here now

# TODO

founded 2 years ago
MODERATORS
 

I'm setting up an application using containers with ansible. I want to be able to set up the same application multiple times with a different set of variables. Is there a way how I could do this in parallel on a single host? I know I could deploy the same application n times on n different hosts, but what about n times on a single host? Is something like this possible? Doing it sequential obviously works, but it doesn't scale well.

top 6 comments
sorted by: hot top controversial new old
[–] DasFaultier@sh.itjust.works 2 points 3 weeks ago (1 children)

If it's only one task that takes very long, and you don't have any follow up tasks that rely on the outcome of the previous task, you might want to set async: true for that task.

[–] wasabi 1 points 3 weeks ago (1 children)

No, it's a moderately complex role. Could I include the role with async: true? There is obviously some dependencies inside the role, but not between the different role inclusions.

[–] DasFaultier@sh.itjust.works 1 points 3 weeks ago

I think you can use async on task level only, but the documentation would be wider than me on that detail.

[–] DasFaultier@sh.itjust.works 1 points 3 weeks ago (1 children)

I just had another idea: you could use the Mitogen execution strategy. It doesn't make your tasks run in parallel, but it takes away a lot of the overhead involved in running Ansible, so you might get some performance gains there. It's not running your tasks in parallel though...

For real parallel execution, you would probably need multiple hosts. I don't think what you're trying to do is even a part of Ansible on the conceptual level.

[–] wasabi 2 points 3 weeks ago* (last edited 3 weeks ago) (1 children)

Could one maybe use multiple hosts in the ansible inventory that point to the same host?

Maybe k8s ist better suited for this.

[–] DasFaultier@sh.itjust.works 1 points 3 weeks ago* (last edited 3 weeks ago)

Yes, you could setup multiple DNS aliases in your nameserver/router or in your /etc/hosts file that point to the same IP; DNS might round-robin through the IPs, but I've never tried this.

EDIT: You're right, the DNS aliases go in the Ansible inventory, no need for DNS round-robin. Short brainfart, sry. EDIT END.

I have near-zero experience with k8s (apart from a little bit of Minikube, which I hated), so I can't say anything about that option, but my impression is that it's massive overkill for almost all use cases, aka "you're not Google".