From b79335cdb34f11a0f745de4961bd081af057981a Mon Sep 17 00:00:00 2001 From: Igor Duarte Date: Mon, 11 Mar 2024 13:09:35 -0300 Subject: [PATCH] ansible-scylla-node: Get addresses for nodes that are not in play_hosts In order to run the token_distributor script in the generate_tokens task, we need to have broadcast_address and rpc_address defined for all the already bootstrapped nodes, including the ones that are not in the 'play_hosts' variable. So far we've been assuming that the variables scylla_broadcast_address and scylla_rpc_address would always be defined for all the nodes, but the user has no obligation of passing variables for nodes that are not in 'play_hosts', i.e.: hosts that were excluded from the playbook execution by the usage of --limit option. Having that in mind, this patch is defining these variables for bootstrapped nodes that are not in 'play_hosts' by using the values defined in their 'scylla.yaml' files. This patch assumes that any already bootstrapped node will have a scylla.yaml in /etc/scylla with rpc_address and broadcast_address defined. --- ansible-scylla-node/tasks/generate_tokens.yml | 52 +++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/ansible-scylla-node/tasks/generate_tokens.yml b/ansible-scylla-node/tasks/generate_tokens.yml index 8d417ab3..41bebadb 100644 --- a/ansible-scylla-node/tasks/generate_tokens.yml +++ b/ansible-scylla-node/tasks/generate_tokens.yml @@ -1,4 +1,48 @@ --- +- name: Get relevant addresses for nodes that are not in 'play_hosts' + block: + - name: check if scylla.yaml exists + stat: + path: /etc/scylla/scylla.yaml + register: _scylla_yaml_stat + delegate_to: "{{ item }}" + delegate_facts: true + when: item not in play_hosts + loop: "{{ groups['scylla'] }}" + + - name: Set _scylla_yaml_exists as a fact + set_fact: + _scylla_yaml_exists: "{{ item.stat.exists }}" + when: item.item not in play_hosts + delegate_to: "{{ item.item }}" + delegate_facts: true + loop: "{{ _scylla_yaml_stat.results }}" + + # Let's assume that a node can only be started if it has a scylla yaml + - name: Register scylla.yaml + command: cat /etc/scylla/scylla.yaml + register: _scylla_yaml_out + delegate_to: "{{ item }}" + when: "item not in play_hosts and hostvars[item]['_scylla_yaml_exists']|bool" + loop: "{{ groups['scylla'] }}" + + - name: Set _scylla_yaml_map as a fact + set_fact: + _scylla_yaml_map: "{{ item.stdout | from_yaml }}" + delegate_to: "{{ item.item }}" + delegate_facts: true + when: item.stdout is defined + loop: "{{ _scylla_yaml_out.results }}" + + - name: Set addresses as facts + set_fact: + rpc_address: "{{ hostvars[item]['_scylla_yaml_map'].rpc_address }}" + broadcast_address: "{{ hostvars[item]['_scylla_yaml_map'].broadcast_address }}" + delegate_to: "{{ item }}" + delegate_facts: true + when: item not in play_hosts and hostvars[item]['_scylla_yaml_exists']|bool + loop: "{{ groups['scylla'] }}" + - name: Find the first node which is already bootstrapped, if any wait_for: port: 9042 @@ -7,7 +51,7 @@ register: wait_for_cql_port_output ignore_errors: true delegate_to: "{{ item }}" - loop: "{{ groups['scylla'] }}" + loop: "{{ scylla_seeds }}" when: wait_for_cql_port_output is not defined or wait_for_cql_port_output.failed == True - name: Set the already bootstrapped node as a fact, if any @@ -21,6 +65,7 @@ node_list: "{{ node_list | default([]) + [hostvars[item]['broadcast_address']] }}" rack_list: "{{ rack_list | default([]) + [hostvars[item]['rack']] }}" dc_list: "{{ dc_list | default([]) + [hostvars[item]['dc'] + hostvars[item]['dc_suffix'] | default('')] }}" + when: hostvars[item]['broadcast_address'] is defined loop: "{{ groups['scylla'] }}" - name: Create a temporary tokens file @@ -40,6 +85,7 @@ retries: 5 delay: 1 delegate_to: "{{ bootstrapped_node }}" + when: hostvars[item]['broadcast_address'] is defined loop: "{{ groups['scylla'] }}" - name: Copy tokens to tmp file @@ -47,7 +93,7 @@ path: "{{ tokens_file.path }}" line: "{{ hostvars[item.item]['broadcast_address'] }}={{ item.json | map('int') | join(',') }}" create: yes - when: item.json|length > 0 + when: hostvars[item.item]['broadcast_address'] is defined and item.json|length > 0 delegate_to: localhost loop: "{{ _existing_tokens.results }}" when: bootstrapped_node is defined @@ -77,4 +123,4 @@ when: item[0].split('=')[0] == hostvars[item[1]]['broadcast_address'] with_nested: - "{{ _new_tokens.stdout_lines }}" - - "{{ groups['scylla'] }}" + - "{{ play_hosts }}"