9

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.

pkaramol
  • 16,451
  • 43
  • 149
  • 324

3 Answers3

14

--cluster-yes is the correct option!

mustaccio
  • 18,234
  • 16
  • 48
  • 57
Leonardo Oliveira
  • 356
  • 1
  • 3
  • 8
10

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
Jona Koudijs
  • 101
  • 1
  • 7
0

Well, I don't know about the ansible part. But Redis official site does provide a way to create cluster with script in a little interactive-mode.

Creating a Redis Cluster using the create-cluster script (Please refer docs for more details)

If you don't want to create a Redis Cluster by configuring and executing individual instances manually as explained above, there is a much simpler system (but you'll not learn the same amount of operational details).

Just check utils/create-cluster directory in the Redis distribution. There is a script called create-cluster inside (same name as the directory it is contained into), it's a simple bash script. In order to start a 6 nodes cluster with 3 masters and 3 slaves just type the following commands:

create-cluster start
create-cluster create

Reply to yes in step 2 when the redis-cli utility wants you to accept the cluster layout.

You can now interact with the cluster, the first node will start at port 30001 by default. When you are done, stop the cluster with:

create-cluster stop

Please read the README inside this directory for more information on how to run the script.

You can try implementing this if it helps you in any way!
Cheers :)

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
Ayushi Jain
  • 102
  • 6