简体   繁体   中英

What is the best way to check with an ansible task if my nodes are up and normal in a cluster using cassandra

I have a cluster running cassandra 3.11.4 with 5 nodes. I'm using ansible to run tasks and I have a specific task which I only want to run if all the nodes are up and normal. I tried to use nodetool status and nodetool describecluster and check its output, but is there a better solution?

Let's have the inventory below

$ cat hosts
[nodes]
192.168.50.4  node0
192.168.50.5  node1
192.168.50.6  node2
192.168.50.7  node3
192.168.50.8  node4
192.168.50.9  node5

The play below fails if any of the nodes do not respond at monitor port within timeout seconds. (Fit the variables to your needs.)

- hosts: localhost
  vars:
    monitor: 7199
    timeout: 5
  tasks:
    - wait_for:
        port: "{{ monitor }}"
        host: "{{ item }}"
        timeout: "{{ timeout }}"
        msg: "{{ item }} is not running. End of play."
      loop: "{{ groups['nodes'] }}"

To check all nodes ignore potential errors, register and review results.

      ignore_errors: yes
      register: results

(not tested)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM