You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.0 KiB

  1. ---
  2. - name: Check if Redis is installed
  3. stat:
  4. path: /usr/local/bin/redis-server
  5. register: redis_server
  6. - name: Download and install Redis
  7. when: not redis_server.stat.exists
  8. block:
  9. - name: Download Redis from GitHub
  10. get_url:
  11. dest: /tmp/redis-{{ redis_version }}.tar.gz
  12. url: https://github.com/redis/redis/archive/{{ redis_version }}.tar.gz
  13. checksum: sha256:d53bb1f3e31c8893cbeda20195fa64132e35354d633231939c47b640fd401098
  14. - name: Create temp directory to extract Redis to
  15. file:
  16. path: /tmp/redis-{{ redis_version }}
  17. state: directory
  18. - name: Extract Redis
  19. unarchive:
  20. remote_src: true
  21. src: /tmp/redis-{{ redis_version }}.tar.gz
  22. dest: /tmp/redis-{{ redis_version }}
  23. extra_opts:
  24. - --strip-components=1
  25. - name: Install build dependencies for Redis
  26. apt:
  27. name: build-essential
  28. - name: Install Redis
  29. shell:
  30. chdir: /tmp/redis-{{ redis_version }}
  31. cmd: |
  32. make
  33. make install
  34. - name: Create group for redis user
  35. group:
  36. name: redis
  37. - name: Create redis user
  38. user:
  39. name: redis
  40. group: redis
  41. create_home: false
  42. - name: Create /run/redis
  43. file:
  44. path: /run/redis
  45. state: directory
  46. owner: redis
  47. group: redis
  48. mode: 0755
  49. - name: Create /var/lib/redis
  50. file:
  51. path: /var/lib/redis
  52. state: directory
  53. owner: redis
  54. group: redis
  55. mode: 0700
  56. - name: Create /var/log/redis
  57. file:
  58. path: /var/log/redis
  59. state: directory
  60. owner: redis
  61. group: redis
  62. mode: 0744
  63. - name: Create Redis configuration file
  64. template:
  65. src: redis.conf.jinja2
  66. dest: /etc/redis.conf
  67. owner: redis
  68. group: redis
  69. mode: 0600
  70. - name: Create Redis service file
  71. copy:
  72. src: redis.service
  73. dest: /etc/systemd/system/redis.service
  74. owner: root
  75. group: root
  76. mode: 0644
  77. - name: Add service file for disabling transparent hugepage
  78. copy:
  79. src: transparent_hugepage.service
  80. dest: /etc/systemd/system/transparent_hugepage.service
  81. owner: root
  82. group: root
  83. mode: 0644
  84. - name: Check if transparent hugepage is currently enabled
  85. command:
  86. cmd: cat /sys/kernel/mm/transparent_hugepage/enabled
  87. register: transparent_hugepage
  88. changed_when: false
  89. - name: Start and enable "disable transparent hugepage" service
  90. service:
  91. name: transparent_hugepage.service
  92. state: started
  93. enabled: true
  94. when: "'[never]' not in transparent_hugepage.stdout"
  95. - name: Check if kernel overcommit mode is already set
  96. command:
  97. cmd: sysctl -n vm.overcommit_memory
  98. register: overcommit_memory
  99. changed_when: false
  100. - name: Set kernel overcommit mode temporarily (recommended by Redis)
  101. command:
  102. cmd: sysctl vm.overcommit_memory=1
  103. when: overcommit_memory.stdout == "0"
  104. - name: Make kernel overcommit mode permanent (recommended by Redis, requires restart)
  105. lineinfile:
  106. path: /etc/sysctl.conf
  107. line: vm.overcommit_memory = 1
  108. - name: Start and enable redis service
  109. service:
  110. name: redis
  111. state: started
  112. enabled: true