this post was submitted on 11 Jun 2024
4 points (83.3% liked)

Ansible

243 readers
1 users here now

# TODO

founded 2 years ago
MODERATORS
 

I have an inventory of hosts, and from them, one of the tasks should choose a leader by running a command on each until one of the machines produces an expected output (json value.)

I want some code to run on that leader to initialize it, and then I want some of the other roles to delegate some tasks to that leader.

Not sure how to do this?

Should I use dynamic inventory to analyze a group of hosts, and create a new group (can you run built_in.command in dynamic inventory? Should I write a role task that runs the identifying command on each host, capturing the result globally if it returns what I want (but then running on each host even if I have found my leader?)

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 2 points 8 months ago (6 children)

Not sure if i really get what you are trying to do but you can check for the pre_task keyword. It's seems you are overengineering something. Try to think about idempotency

[–] [email protected] 1 points 8 months ago (3 children)

Me either, but we have a role to bootstrap galara mysql and we just use the first host in a group

[–] jaxxed 1 points 8 months ago

sounds like the same idea. So you use run_once on a task?

load more comments (2 replies)
load more comments (4 replies)