setup_raft_cluster.j2 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  2. #####################################################################
  3. # {{ ansible_managed }}
  4. #####################################################################
  5. {% set primary_node = cpredis_node_ips.split(',')[0]%}
  6. {% set other_nodes = cpredis_node_ips.split(',')[1:]%}
  7. #####################################################################
  8. # Data Information:
  9. #####################################################################
  10. # Primary Node: {{ primary_node }}
  11. # Other Nodes: {{ other_nodes | join(",") }}
  12. # Raft Instance Ports:
  13. {% for p in redis_ports -%}
  14. # - {{ p.port }}
  15. {% endfor %}
  16. #####################################################################
  17. # Raft Group Setups!!
  18. {% for p in redis_ports %}
  19. echo "Setting up Raft Groups - port {{ p.port }}"
  20. # /usr/local/bin/redis-cli -h {{ primary_node }} -p {{ p.port }} raft.cluster init
  21. {% for node in other_nodes %}
  22. # /usr/local/bin/redis-cli -h {{ node }} -p {{ p.port }} raft.cluster join {{ primary_node }}:{{ p.port }}
  23. {% endfor %}
  24. {% endfor %}
  25. #####################################################################
  26. # Set up Shard Clusters
  27. {% for p in redis_ports %}
  28. echo "Setting up Shard Clusters - port {{ p.port }}"
  29. SHARDGROUP_CONFIG=$(/usr/local/bin/redis-cli -h {{ primary_node }} -p {{ p.port }} --raw RAFT.SHARDGROUP GET)
  30. # echo $SHARDGROUP_CONFIG
  31. {% for t in redis_ports %}
  32. {% if t.port != p.port %}
  33. echo "/usr/local/bin/redis-cli -h {{ primary_node }} -p {{ t.port }} RAFT.SHARDGROUP ADD $SHARDGROUP_CONFIG"
  34. {% endif %}
  35. {% endfor %}
  36. {% endfor %}