Skip to content

Commit

Permalink
ansible-scylla-node: Get addresses for nodes that are not in play_hosts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
igorribeiroduarte committed Mar 18, 2024
1 parent d8ac913 commit b79335c
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions ansible-scylla-node/tasks/generate_tokens.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -40,14 +85,15 @@
retries: 5
delay: 1
delegate_to: "{{ bootstrapped_node }}"
when: hostvars[item]['broadcast_address'] is defined
loop: "{{ groups['scylla'] }}"

- name: Copy tokens to tmp file
lineinfile:
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
Expand Down Expand Up @@ -77,4 +123,4 @@
when: item[0].split('=')[0] == hostvars[item[1]]['broadcast_address']
with_nested:
- "{{ _new_tokens.stdout_lines }}"
- "{{ groups['scylla'] }}"
- "{{ play_hosts }}"

0 comments on commit b79335c

Please sign in to comment.