Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redis: Create cluster with redis-cli non interactively

When trying to create a cluster with redis-cli as follows

redis-cli --cluster create

a prompt comes up asking for configuration confirmation?

Is there a way to script this (preferably in ansible) and run it non-interactively?

I am aware of this topic however it addresses data manipulation which is not the scope of this question.

like image 454
pkaramol Avatar asked Apr 15 '26 09:04

pkaramol


2 Answers

--cluster-yes is the correct option!

like image 114
Leonardo Oliveira Avatar answered Apr 21 '26 01:04

Leonardo Oliveira


EDIT: The answer of Leonardo Oliveira rightfully points out that the option --cluster-yes will avoid the prompt. For example:

redis-cli --cluster create host1:6379 host2:6379 host3:6379 --cluster-yes

As of the current Redis version (5.0.5) there doesn't seem to be a flag under --cluster that can silence or auto-answer the interactive question:

$ redis-cli --cluster help
Cluster Manager Commands:
  create         host1:port1 ... hostN:portN
                 --cluster-replicas <arg>
  check          host:port
                 --cluster-search-multiple-owners
  info           host:port
  fix            host:port
                 --cluster-search-multiple-owners
  reshard        host:port
                 --cluster-from <arg>
                 --cluster-to <arg>
                 --cluster-slots <arg>
                 --cluster-yes
                 --cluster-timeout <arg>
                 --cluster-pipeline <arg>
                 --cluster-replace
  rebalance      host:port
                 --cluster-weight <node1=w1...nodeN=wN>
                 --cluster-use-empty-masters
                 --cluster-timeout <arg>
                 --cluster-simulate
                 --cluster-pipeline <arg>
                 --cluster-threshold <arg>
                 --cluster-replace
  add-node       new_host:new_port existing_host:existing_port
                 --cluster-slave
                 --cluster-master-id <arg>
  del-node       host:port node_id
  call           host:port command arg arg .. arg
  set-timeout    host:port milliseconds
  import         host:port
                 --cluster-from <arg>
                 --cluster-copy
                 --cluster-replace
  help

By using echo you can execute the command and auto-answer the prompt:

echo "yes" | redis-cli --cluster create host1:6379 host2:6379 host3:6379

The default Ansible Redis module only supports a few commands and not --cluster so you would have to create your own logic with command/shell tasks:

- name: Create cluster
  shell: echo "yes" | redis-cli --cluster create host1:6379 host2:6379 host3:6379
  run_once: true
  when: not cluster_setup_done
like image 27
Jona Koudijs Avatar answered Apr 20 '26 23:04

Jona Koudijs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!