From bb4fb141b50d0503f88c7146b2a9683086f54bdf Mon Sep 17 00:00:00 2001 From: Jake and Amy Date: Sun, 8 Jun 2014 18:17:48 +0100 Subject: [PATCH 1/9] Intial redis-server config changes --- tasks/server.yml | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tasks/server.yml b/tasks/server.yml index 24009f2f..2de4b65b 100644 --- a/tasks/server.yml +++ b/tasks/server.yml @@ -19,11 +19,30 @@ - name: set redis to start at boot service: name=redis_{{ redis_port }} enabled=yes -- name: create redis config file - template: src=redis.conf.j2 dest=/etc/redis/{{ redis_port }}.conf +- name: create dynamic redis config file + template: src=redis.conf.j2 + dest=/etc/redis/{{ redis_port }}.dyn.conf owner={{ redis_user }} notify: restart redis +- name: check if redis config file exists + stat: path=/etc/redis/{{ redis_port }}.conf + register: p + +- name: create redis config file if it does not exist + file: path=/etc/redis/{{ redis_port }}.conf + state=touch + owner={{ redis_user }} + when: p.stat.exists == True + notify: restart redis + +- name: ensure dynamic config included in redis config + lineinfile: dest=/etc/redis/{{ redis_port }}.conf + line="include {{ redis_port }}.dynamic.conf" + insertbefore=BOF + regexp='^include' + notify: restart redis + - name: add redis init config file template: dest=/etc/sysconfig/redis_{{ redis_port }} src=redis.init.conf.j2 From 6ad7edb54eeb0e9b0c51a76a29d7917790231b17 Mon Sep 17 00:00:00 2001 From: jabclab Date: Mon, 9 Jun 2014 09:40:32 +0100 Subject: [PATCH 2/9] Config idempotence --- tasks/sentinel.yml | 17 ++++++++++++++--- tasks/server.yml | 17 +++++------------ templates/{redis.conf.j2 => redis.dyn.conf.j2} | 0 ...tinel.conf.j2 => redis_sentinel.dyn.conf.j2} | 0 4 files changed, 19 insertions(+), 15 deletions(-) rename templates/{redis.conf.j2 => redis.dyn.conf.j2} (100%) rename templates/{redis_sentinel.conf.j2 => redis_sentinel.dyn.conf.j2} (100%) diff --git a/tasks/sentinel.yml b/tasks/sentinel.yml index 45eedcbe..547661db 100644 --- a/tasks/sentinel.yml +++ b/tasks/sentinel.yml @@ -20,11 +20,22 @@ - name: set sentinel to start at boot service: name=sentinel_{{ redis_sentinel_port }} enabled=yes -- name: create sentinel config file +- name: create dynamic sentinel config file + template: src=redis_sentinel.dyn.conf.j2 + dest=/etc/redis/sentinel_{{ redis_sentinel_port }}.dyn.conf + owner={{ redis_user }} + notify: restart redis + +- name: check if sentinel config file exists + stat: path=/etc/redis/sentinel_{{ redis_sentinel_port }}.conf + register: p + +- name: create sentinel config file if it does not exist template: src=redis_sentinel.conf.j2 - dest=/etc/redis/sentinel_{{ redis_sentinel_port }}.conf + path=/etc/redis/sentinel_{{ redis_sentinel_port }}.conf owner={{ redis_user }} - notify: restart sentinel + when: p.stat.exists == False + notify: restart redis - name: add sentinel init config file template: dest=/etc/sysconfig/sentinel_{{ redis_sentinel_port }} diff --git a/tasks/server.yml b/tasks/server.yml index 2de4b65b..875d5c64 100644 --- a/tasks/server.yml +++ b/tasks/server.yml @@ -20,7 +20,7 @@ service: name=redis_{{ redis_port }} enabled=yes - name: create dynamic redis config file - template: src=redis.conf.j2 + template: src={{ redis_port }}.dyn.conf.j2 dest=/etc/redis/{{ redis_port }}.dyn.conf owner={{ redis_user }} notify: restart redis @@ -30,17 +30,10 @@ register: p - name: create redis config file if it does not exist - file: path=/etc/redis/{{ redis_port }}.conf - state=touch - owner={{ redis_user }} - when: p.stat.exists == True - notify: restart redis - -- name: ensure dynamic config included in redis config - lineinfile: dest=/etc/redis/{{ redis_port }}.conf - line="include {{ redis_port }}.dynamic.conf" - insertbefore=BOF - regexp='^include' + template: src=redis.conf.j2 + path=/etc/redis/{{ redis_port }}.conf + owner={{ redis_user }} + when: p.stat.exists == False notify: restart redis - name: add redis init config file diff --git a/templates/redis.conf.j2 b/templates/redis.dyn.conf.j2 similarity index 100% rename from templates/redis.conf.j2 rename to templates/redis.dyn.conf.j2 diff --git a/templates/redis_sentinel.conf.j2 b/templates/redis_sentinel.dyn.conf.j2 similarity index 100% rename from templates/redis_sentinel.conf.j2 rename to templates/redis_sentinel.dyn.conf.j2 From dedf0d0cdd82d4caafb611d7001956c68a3ffd6e Mon Sep 17 00:00:00 2001 From: jabclab Date: Mon, 9 Jun 2014 09:50:47 +0100 Subject: [PATCH 3/9] Adding master config template files --- templates/redis.conf.j2 | 2 ++ templates/redis_sentinel.conf.j2 | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 templates/redis.conf.j2 create mode 100644 templates/redis_sentinel.conf.j2 diff --git a/templates/redis.conf.j2 b/templates/redis.conf.j2 new file mode 100644 index 00000000..018c3bb9 --- /dev/null +++ b/templates/redis.conf.j2 @@ -0,0 +1,2 @@ +# Include ansible-controlled redis.conf +include /etc/redis/{{ redis_port }}.dyn.conf diff --git a/templates/redis_sentinel.conf.j2 b/templates/redis_sentinel.conf.j2 new file mode 100644 index 00000000..51ca4147 --- /dev/null +++ b/templates/redis_sentinel.conf.j2 @@ -0,0 +1,2 @@ +# Include ansible-controlled sentinel.conf +include /etc/redis/sentinel_{{ redis_sentinel_port }}.dyn.conf From f6d4a1dcfe1ae598cabec1b51a63883ea32d824f Mon Sep 17 00:00:00 2001 From: jabclab Date: Mon, 9 Jun 2014 10:57:58 +0100 Subject: [PATCH 4/9] Correcting issues after manual testing --- tasks/sentinel.yml | 2 +- tasks/server.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/sentinel.yml b/tasks/sentinel.yml index 547661db..9e800e8f 100644 --- a/tasks/sentinel.yml +++ b/tasks/sentinel.yml @@ -32,7 +32,7 @@ - name: create sentinel config file if it does not exist template: src=redis_sentinel.conf.j2 - path=/etc/redis/sentinel_{{ redis_sentinel_port }}.conf + dest=/etc/redis/sentinel_{{ redis_sentinel_port }}.conf owner={{ redis_user }} when: p.stat.exists == False notify: restart redis diff --git a/tasks/server.yml b/tasks/server.yml index 875d5c64..14fc7629 100644 --- a/tasks/server.yml +++ b/tasks/server.yml @@ -20,7 +20,7 @@ service: name=redis_{{ redis_port }} enabled=yes - name: create dynamic redis config file - template: src={{ redis_port }}.dyn.conf.j2 + template: src=redis.dyn.conf.j2 dest=/etc/redis/{{ redis_port }}.dyn.conf owner={{ redis_user }} notify: restart redis @@ -31,7 +31,7 @@ - name: create redis config file if it does not exist template: src=redis.conf.j2 - path=/etc/redis/{{ redis_port }}.conf + dest=/etc/redis/{{ redis_port }}.conf owner={{ redis_user }} when: p.stat.exists == False notify: restart redis From be30cb93b1ddfbd9646e695efc9472b06443e09e Mon Sep 17 00:00:00 2001 From: jabclab Date: Tue, 10 Jun 2014 09:37:40 +0100 Subject: [PATCH 5/9] Modifying config management of sentinel --- tasks/sentinel.yml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tasks/sentinel.yml b/tasks/sentinel.yml index 9e800e8f..1d09c1de 100644 --- a/tasks/sentinel.yml +++ b/tasks/sentinel.yml @@ -22,7 +22,7 @@ - name: create dynamic sentinel config file template: src=redis_sentinel.dyn.conf.j2 - dest=/etc/redis/sentinel_{{ redis_sentinel_port }}.dyn.conf + dest=/etc/redis/.sentinel_{{ redis_sentinel_port }}.dyn.conf owner={{ redis_user }} notify: restart redis @@ -31,12 +31,22 @@ register: p - name: create sentinel config file if it does not exist - template: src=redis_sentinel.conf.j2 - dest=/etc/redis/sentinel_{{ redis_sentinel_port }}.conf - owner={{ redis_user }} + file: dest=/etc/redis/sentinel_{{ redis_sentinel_port }}.conf + owner={{ redis_user }} + state=touch when: p.stat.exists == False notify: restart redis +- name: read contents of sentinel config into a variable + shell: "cat /etc/redis/.sentinel_{{ redis_sentinel_port }}.dyn.conf" + register: sentinel_conf + +- name: ensure base config is present in sentinel config file + lineinfile: dest=/etc/redis/sentinel_{{ redis_sentinel_port }}.conf + line="{{ item }}" + regexp="^{{ item }}$" + with_items: sentinel_conf.stdout_lines + - name: add sentinel init config file template: dest=/etc/sysconfig/sentinel_{{ redis_sentinel_port }} src=redis.init.conf.j2 From fe6480999c26fa8e070e237dcfbdeeeaecdc435c Mon Sep 17 00:00:00 2001 From: jabclab Date: Tue, 10 Jun 2014 10:00:42 +0100 Subject: [PATCH 6/9] Correcting merge issue --- tasks/server.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tasks/server.yml b/tasks/server.yml index 0d828bf0..efc42696 100644 --- a/tasks/server.yml +++ b/tasks/server.yml @@ -30,6 +30,8 @@ - name: create dynamic redis config file template: src=redis.dyn.conf.j2 dest=/etc/redis/{{ redis_port }}.dyn.conf + owner={{ redis_user }} + notify: restart redis - name: check if redis config file exists stat: path=/etc/redis/{{ redis_port }}.conf From f9f70abf6366bb0ff5850c37a5cea6c160227c45 Mon Sep 17 00:00:00 2001 From: jabclab Date: Tue, 10 Jun 2014 10:01:08 +0100 Subject: [PATCH 7/9] Correct notifying of redis restart for sentinel config --- tasks/sentinel.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tasks/sentinel.yml b/tasks/sentinel.yml index a2aa0ff0..8a7a8e1b 100644 --- a/tasks/sentinel.yml +++ b/tasks/sentinel.yml @@ -31,6 +31,7 @@ - name: create dynamic sentinel config file template: src=redis_sentinel.dyn.conf.j2 dest=/etc/redis/.sentinel_{{ redis_sentinel_port }}.dyn.conf + owner={{ redis_user }} - name: check if sentinel config file exists stat: path=/etc/redis/sentinel_{{ redis_sentinel_port }}.conf @@ -41,7 +42,6 @@ owner={{ redis_user }} state=touch when: p.stat.exists == False - notify: restart redis - name: read contents of sentinel config into a variable shell: "cat /etc/redis/.sentinel_{{ redis_sentinel_port }}.dyn.conf" @@ -52,6 +52,7 @@ line="{{ item }}" regexp="^{{ item }}$" with_items: sentinel_conf.stdout_lines + notify: restart redis - name: add sentinel init config file template: dest=/etc/sysconfig/sentinel_{{ redis_sentinel_port }} From eec1c17c3dcf2e90415d950f0b3b460b33242338 Mon Sep 17 00:00:00 2001 From: jabclab Date: Tue, 10 Jun 2014 10:18:43 +0100 Subject: [PATCH 8/9] Using in memory sentinel config rather than resolving into variable --- tasks/sentinel.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tasks/sentinel.yml b/tasks/sentinel.yml index 8a7a8e1b..487f8fbf 100644 --- a/tasks/sentinel.yml +++ b/tasks/sentinel.yml @@ -43,15 +43,11 @@ state=touch when: p.stat.exists == False -- name: read contents of sentinel config into a variable - shell: "cat /etc/redis/.sentinel_{{ redis_sentinel_port }}.dyn.conf" - register: sentinel_conf - - name: ensure base config is present in sentinel config file lineinfile: dest=/etc/redis/sentinel_{{ redis_sentinel_port }}.conf line="{{ item }}" regexp="^{{ item }}$" - with_items: sentinel_conf.stdout_lines + with_items: lookup('template', '../templates/redis_sentinel.dyn.conf.j2').split('\n') notify: restart redis - name: add sentinel init config file From 921c50b41e14af1226053bd2d0ddf1558b7229e6 Mon Sep 17 00:00:00 2001 From: jabclab Date: Tue, 10 Jun 2014 14:28:59 +0100 Subject: [PATCH 9/9] Ensuring that quotes in config file are preserved in sentinel.conf --- tasks/sentinel.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/sentinel.yml b/tasks/sentinel.yml index 487f8fbf..47cb5494 100644 --- a/tasks/sentinel.yml +++ b/tasks/sentinel.yml @@ -45,8 +45,8 @@ - name: ensure base config is present in sentinel config file lineinfile: dest=/etc/redis/sentinel_{{ redis_sentinel_port }}.conf - line="{{ item }}" - regexp="^{{ item }}$" + line="{{ item|replace('\"', '\\\"') }}" + regexp="^{{ item|replace('\"', '\\\"')}}$" with_items: lookup('template', '../templates/redis_sentinel.dyn.conf.j2').split('\n') notify: restart redis