Imagine I have multiple hadoop clusters, each with a master node and a varying amount of slave nodes connected to it.
I want to dynamically discover the slaves from the master, and then perform actions on them in serial mode (only impact one node at a time to minimize downtime).
What’s the right way to do this?
An almost-working approach is below, but I have a problem at “xxxxx”. If I hardcode a master node name there, everything works. But I don’t want to since that’s silly and
there are lots of clusters. But I don’t know how I can pass the master node name across the plays?
-
hosts : hadoop_master_nodes # run this on all master nodes
tasks: -
name: find targets
shell: list_all_my_hadoop_nodes.sh # show list of nodes connected to this master
register: target_nodes -
set_fact:
target_nodes: “{{ target_nodes.stdout_lines }}” # set a fact so we can call it from the next step -
hosts: “{{ hostvars[‘xxxxxxxx’][‘target_nodes’] }}” # call the list of target_nodes discovered above
serial: 1
tasks: -
name: do whatever # “do whatever” one at a time across all the target nodes
…