Skip to content

Commit

Permalink
Manage replication. Closes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilien Mantel committed Feb 27, 2016
1 parent 5eb4474 commit c2d3ff7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Redis Ansible

[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.redis-blue.svg)](https://galaxy.ansible.com/list#/roles/3989) [![Build Status](https://travis-ci.org/HanXHX/ansible-redis.svg)](https://travis-ci.org/HanXHX/ansible-redis)

Install and configure [Redis](http://redis.io/).
Install and configure [Redis](http://redis.io/). Manage replication.

Requirements
------------
Expand Down
5 changes: 4 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ redis_client_output_buffer_limit:
- 'pubsub 32mb 8mb 60'
redis_hz: '10'
redis_aof_rewrite_incremental_fsync: 'yes'
redis_masterauth: null
redis_requirepass: null

# Replication
redis_masterauth: null
redis_masterauth_masterip: null
redis_masterauth_masterport: null
4 changes: 4 additions & 0 deletions templates/etc/redis/redis.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ dir {{ redis_dir }}
# so for example it is possible to configure the slave to save the DB with a
# different interval, or to listen to another port, and so on.
#
{% if redis_masterauth_masterip is none or redis_masterauth_masterport is none %}
# slaveof <masterip> <masterport>
{% else %}
slaveof {{ redis_masterauth_masterip }} {{ redis_masterauth_masterport }}
{% endif %}

# If the master is password protected (using the "requirepass" configuration
# directive below) it is possible to tell the slave to authenticate before
Expand Down
24 changes: 21 additions & 3 deletions tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,41 @@
- ../../
vars:
redis_requirepass: 'my_unsecure_password'
redis_slaveof: '127.0.0.1:{{ redis_masterauth_masterport }}'
redis_masterauth_masterip: '127.0.0.1'
redis_masterauth_masterport: 7777

post_tasks:
- name: SET_FACT | Create vars
set_fact:
test_key: 'key_{{ 10000 | random }}'
test_val: 'value_{{ 10000 | random }}'

- name: SHELL | Start master Redis
shell: redis-server --port {{ redis_masterauth_masterport }} &
changed_when: false

- name: COMMAND | Check Auth is running (and fails auth)
command: redis-cli SET a 1
register: f
failed_when: f.stdout.find('Authentication required') == -1
changed_when: false
- name: COMMAND | Test SET
command: redis-cli -a {{ redis_requirepass }} SET {{ test_key }} {{ test_val }}

- name: COMMAND | Test SET on master
command: redis-cli -p {{ redis_masterauth_masterport }} SET {{ test_key }} {{ test_val }}
register: s
failed_when: s.stdout.find('OK') == -1
changed_when: false
- name: COMMAND | Test GET

- name: PAUSE | 1 sec
pause: seconds=1

- name: COMMAND | Test GET on slave
command: redis-cli -a {{ redis_requirepass }} GET {{ test_key }}
register: g
failed_when: g.stdout.find(test_val) == -1
changed_when: false

- name: SHELL | Kill master Redis
shell: ps aux | grep -v awk | awk '/redis-server / && /{{ redis_masterauth_masterport }}/ { print $2 }' | xargs -n1 kill
changed_when: false

0 comments on commit c2d3ff7

Please sign in to comment.