- name: Extract Worker Join Token from Primary Master hosts: masters[0] # <--- Targets only the first master safely gather_facts: false tasks: - name: Generate worker join command ansible.builtin.command: kubeadm token create --print-join-command register: join_command_raw changed_when: false # Reading/generating a token text string changes no host state - name: Save join command globally ansible.builtin.set_fact: k8s_worker_join: "{{ join_command_raw.stdout }}" delegate_to: localhost delegate_facts: true - name: Join Worker Nodes to Cluster hosts: workers gather_facts: false tasks: - name: Join cluster ansible.builtin.shell: "{{ hostvars['localhost']['k8s_worker_join'] }} >> node_joined.txt" args: chdir: $HOME creates: node_joined.txt