Browse Source

add redis services to consul

Chris Mague 5 years ago
parent
commit
7bc99df320
3 changed files with 34 additions and 0 deletions
  1. 6 0
      README.md
  2. 19 0
      ansible/cp_nodes.yml
  3. 9 0
      ansible/templates/redis.services.j2

+ 6 - 0
README.md

@@ -18,6 +18,12 @@ chmod 0600 ~/.ssh/maguec1.pem
 
 # After ansible
 
+```
+# download roles
+cd ansible && rm -rf roles/* && ansible-galaxy install --roles-path roles -r requirements.yml
+```
+
+
 ```
 ansible-playbook ansible/cp_nodes.yml --private-key ~/.ssh/maguec1.pem -i inventories/maguec1_all_nodes.ini
 ```

+ 19 - 0
ansible/cp_nodes.yml

@@ -27,6 +27,12 @@
       - 19911
       - 19912
 
+  handlers:
+    - name: restart_consul
+      service:
+        name: consul
+        state: restarted
+  
   pre_tasks:
     - name: Update Apt Cache
       apt: update_cache=yes cache_valid_time=86400
@@ -96,3 +102,16 @@
 
   roles:
     - consul
+
+  post_tasks:
+    - name: Redis Consul Services 
+      template:
+        src: redis.services.j2
+        dest: /opt/consul/consul.d/redis.json
+        owner: consul
+        group: consul
+        mode: 0644
+      notify:
+        - restart_consul
+
+

+ 9 - 0
ansible/templates/redis.services.j2

@@ -0,0 +1,9 @@
+{"services": [
+{% for port in redis_ports -%}
+  {"name": "redis-{{ port }}",
+  "port": {{ port }},
+  "checks": [{"script": "redis-cli -p {{ port }} --raw RAFT.INFO  |grep -q '^role:leader'", "interval": "0.5s"}]
+  }{% if port != redis_ports[-1] %},{% endif %}
+{% endfor -%}
+]}
+