---
- name: create redis working directory
  file: 
    path={{ redis_dir }}
    state=directory
    recurse=yes
    owner={{ redis_user }}
  tags: redis

- name: check if log file exists
  stat: 
    path={{ redis_logfile }}
  register: logfile_stat
  tags: redis

- name: ensure that log file exists and is writable by redis
  file: 
    path={{ redis_logfile }}
    owner={{ redis_user }}
    group={{ redis_user }}
    mode=0600
    state=touch
  when: logfile_stat.stat.exists == False and redis_logfile != '""'
  tags: redis

- name: create redis config file
  template: 
    src=redis.conf.j2 
    dest=/etc/redis/redis.conf
    owner={{ redis_user }}
  notify: 
    - restart redis
  tags: redis

- name: copy supervisord config
  template:
    src=redis-supervisord.conf.j2
    dest={{ supervisord_programs_dir }}/redis-supervisord.conf
    mode=0644
  notify:
    - reread supervisord
  tags: redis

---
- name: create redis working directory
  file: 
    path={{ redis_dir }}
    state=directory
    recurse=yes
    owner={{ redis_user }}
  tags: redis

- name: check if log file exists
  stat: 
    path={{ redis_logfile }}
  register: logfile_stat
  tags: redis

- name: ensure that log file exists and is writable by redis
  file: 
    path={{ redis_logfile }}
    owner={{ redis_user }}
    group={{ redis_user }}
    mode=0600
    state=touch
  when: logfile_stat.stat.exists == False and redis_logfile != '""'
  tags: redis

- name: create redis config file
  template: 
    src=redis.conf.j2 
    dest=/etc/redis/redis.conf
    owner={{ redis_user }}
  notify: 
    - restart redis
  tags: redis

- name: copy supervisord config
  template:
    src=redis-supervisord.conf.j2
    dest={{ supervisord_programs_dir }}/redis-supervisord.conf
    mode=0644
  notify:
    - reread supervisord
  tags: redis

###############################################################################
# System level configuration optimizations. Configuration recommendations taken
# from https://redis.io/topics/admin
###############################################################################
- block:
  - name: Enable vm.overcommit_memory=1
    sysctl:
      name: vm.overcommit_memory
      value: 1
      state: present

  - name: Install sysfsutils package
    apt:
      name: sysfsutils
      state: present

  - name: Disable Transparent HugePage
    lineinfile:
      dest: /etc/sysfs.conf
      line: kernel/mm/transparent_hugepage/enabled = never
      state: present

Add system level optimizations for Redis
Add system level optimizations for Redis
