cp_nodes.yml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. ---
  2. - hosts: all
  3. become: yes
  4. become_user: root
  5. become_method: sudo
  6. gather_facts: yes
  7. vars:
  8. consul_ui: true
  9. consul_server: true
  10. consul_server_nodes:
  11. - 10.161.8.1
  12. - 10.161.16.94
  13. - 10.161.13.176
  14. - 10.161.14.88
  15. - 10.161.18.146
  16. redis_ports:
  17. - 19901
  18. - 19902
  19. - 19903
  20. - 19904
  21. - 19905
  22. - 19906
  23. - 19907
  24. - 19908
  25. - 19909
  26. - 19910
  27. - 19911
  28. - 19912
  29. handlers:
  30. - name: restart_consul
  31. service:
  32. name: consul
  33. state: restarted
  34. - name: reload_redis_services
  35. command: systemctl daemon-reload
  36. - name: restart_redis_services
  37. systemd:
  38. name: "redis-{{ item }}"
  39. state: restarted
  40. with_items: "{{ redis_ports }}"
  41. pre_tasks:
  42. - name: Update Apt Cache
  43. apt: update_cache=yes cache_valid_time=86400
  44. when: ansible_os_family == "Debian"
  45. - name: Ubuntu Packages
  46. apt: >
  47. pkg={{item}}
  48. state=present
  49. with_items:
  50. - build-essential
  51. - autoconf
  52. - automake
  53. - libbsd-dev
  54. - libltdl-dev
  55. - libltdl7
  56. - libtool
  57. tasks:
  58. - name: create redis user
  59. user:
  60. name: redis
  61. uid: 4001
  62. shell: /bin/bash
  63. state: present
  64. - name: copy the redis raft library
  65. copy:
  66. src: redisraft.so
  67. dest: /usr/lib/redisraft.so
  68. owner: redis
  69. group: redis
  70. mode: '0755'
  71. notify:
  72. - restart_redis_services
  73. - name: create raft directories
  74. file:
  75. path: /redis/persistant/cpredis
  76. owner: redis
  77. group: redis
  78. mode: '0755'
  79. state: directory
  80. - name: create raft directories
  81. file:
  82. path: /var/log/cpredis
  83. owner: redis
  84. group: redis
  85. mode: '0755'
  86. state: directory
  87. - name: checkout redis git repo
  88. git:
  89. repo: 'https://github.com/antirez/redis'
  90. dest: /home/redis/redis
  91. version: 6.0
  92. - name: Build the default target
  93. make:
  94. chdir: /home/redis/redis
  95. - name: Run 'install' target as root
  96. make:
  97. chdir: /home/redis/redis
  98. target: install
  99. become: yes
  100. - name: Redis Systemd
  101. template:
  102. src: systemd_redis.j2
  103. dest: /lib/systemd/system/redis-{{item}}.service
  104. owner: root
  105. group: root
  106. mode: 0644
  107. with_items: "{{ redis_ports }}"
  108. notify:
  109. - reload_redis_services
  110. - restart_redis_services
  111. - name: Enable Redis Services
  112. systemd:
  113. name: redis-{{item}}
  114. enabled: yes
  115. state: started
  116. with_items: "{{ redis_ports }}"
  117. roles:
  118. - consul
  119. - ntp
  120. post_tasks:
  121. - name: Redis Consul Services
  122. template:
  123. src: redis.services.j2
  124. dest: /opt/consul/consul.d/redis.json
  125. owner: consul
  126. group: consul
  127. mode: 0644
  128. notify:
  129. - restart_consul