From 3048e7d182ef0a7b7a6452c9767926c30f449b68 Mon Sep 17 00:00:00 2001 From: marcobellaccini <24960638+marcobellaccini@users.noreply.github.com> Date: Mon, 14 Jan 2019 14:28:02 +0100 Subject: [PATCH 01/14] Updated checksums --- vars/main.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vars/main.yml b/vars/main.yml index f86970a9..34cea8a6 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -65,3 +65,9 @@ redis_checksums: 5.0-rc4: bfc7a27d3ba990e154e5b56484061f01962d40b7c77b520ed7a940914b267cec 4.0.11: fc53e73ae7586bcdacb4b63875d1ff04f68c5474c1ddeda78f00e5ae2eed1bbb 5.0-rc5.tar.gz: d070c8a3514e40da5cef9ec26dfd594df0468c203c36398ef2d359a32502b548 + 5.0-rc6: 5e5ffc9184021178c1d89375c5132a2b872a9f77569e8c08ccbdf322acff7ace + 5.0.0: 70c98b2d0640b2b73c9d8adb4df63bcb62bad34b788fe46d1634b6cf87dc99a4 + 5.0.1: 82a67c0eec97f9ad379384c30ec391b269e17a3e4596393c808f02db7595abcb + 5.0.2: 937dde6164001c083e87316aa20dad2f8542af089dfcb1cbb64f9c8300cd00ed + 4.0.12: 6447259d2eed426a949c9c13f8fdb2d91fb66d9dc915dd50db13b87f46d93162 + 5.0.3: e290b4ddf817b26254a74d5d564095b11f9cd20d8f165459efa53eb63cd93e02 From 570a7f30fb14de1d9291c2f08c7f082ad43e5bd1 Mon Sep 17 00:00:00 2001 From: marcobellaccini <24960638+marcobellaccini@users.noreply.github.com> Date: Mon, 14 Jan 2019 14:37:43 +0100 Subject: [PATCH 02/14] Fixed with_items deprecation warning --- tasks/check_vars.yml | 2 +- tasks/dependencies.yml | 48 +++++++++++++++++++++++------------------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/tasks/check_vars.yml b/tasks/check_vars.yml index b20e0409..6b376692 100644 --- a/tasks/check_vars.yml +++ b/tasks/check_vars.yml @@ -11,7 +11,7 @@ - name: check for checksum fail: msg: > - There is no sha1 checksum defined for version {{ redis_version }} in + There is no checksum defined for version {{ redis_version }} in vars/main.yml. Set redis_checksum manually or submit a PR to add this version. when: diff --git a/tasks/dependencies.yml b/tasks/dependencies.yml index 367d372e..558c4883 100644 --- a/tasks/dependencies.yml +++ b/tasks/dependencies.yml @@ -1,25 +1,27 @@ --- - name: install debian dependencies apt: - pkg: "{{ item }}" + name: "{{ packages }}" update_cache: yes cache_valid_time: 86400 state: present - with_items: - - gcc - - make - - libc6-dev - # This should be `else omit`, but that doesn't quite work, so duplicate gcc - - "{{ 'libc6-dev-i386' if redis_make_32bit|bool else 'gcc' }}" + vars: + packages: + - gcc + - make + - libc6-dev + # This should be `else omit`, but that doesn't quite work, so duplicate gcc + - "{{ 'libc6-dev-i386' if redis_make_32bit|bool else 'gcc' }}" when: ansible_os_family == "Debian" - name: install redhat dependencies yum: - name: "{{ item }}" + name: "{{ packages }}" state: present - with_items: - - gcc - - make + vars: + packages: + - gcc + - make when: ansible_os_family == "RedHat" # Conditionally install the i686 build of libgcc if we are building 32-bit @@ -33,21 +35,23 @@ - name: install redhat 32-bit dependencies yum: - name: "{{ item }}" + name: "{{ packages }}" state: latest - with_items: - - libgcc.i686 - - glibc-devel.i686 + vars: + packages: + - libgcc.i686 + - glibc-devel.i686 when: ansible_os_family == "RedHat" and redis_make_32bit|bool - name: install suse dependencies zypper: - name: "{{ item }}" + name: "{{ packages }}" state: present - with_items: - - gcc - - make - # These should be `else omit`, but that doesn't quite work, so duplicate gcc - - "{{ 'gcc-32bit' if redis_make_32bit|bool else 'gcc' }}" - - "{{ 'libgcc_s1-32bit' if redis_make_32bit|bool else 'gcc' }}" + vars: + packages: + - gcc + - make + # These should be `else omit`, but that doesn't quite work, so duplicate gcc + - "{{ 'gcc-32bit' if redis_make_32bit|bool else 'gcc' }}" + - "{{ 'libgcc_s1-32bit' if redis_make_32bit|bool else 'gcc' }}" when: ansible_os_family == 'Suse' From eb53cabc9986e049b0048b8d7d366643a09b41fa Mon Sep 17 00:00:00 2001 From: marcobellaccini <24960638+marcobellaccini@users.noreply.github.com> Date: Mon, 14 Jan 2019 14:51:08 +0100 Subject: [PATCH 03/14] Removed task: check if redis user exists (ignore errors) --- tasks/install.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/tasks/install.yml b/tasks/install.yml index 6c04c912..8256872f 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -24,17 +24,10 @@ path: /etc/redis state: directory -- name: check if redis user exists (ignore errors) - command: id {{ redis_user }} - ignore_errors: yes - changed_when: false - register: user_exists - - name: add redis group group: name: "{{ redis_group }}" state: present - when: user_exists|failed - name: add redis user user: @@ -44,7 +37,7 @@ home: "{{ redis_install_dir }}" shell: /bin/false system: yes - when: user_exists|failed + state: present - name: create /var/run/redis file: From 5602c9733f288b77413f9a85e0f2d557ef0f6e47 Mon Sep 17 00:00:00 2001 From: marcobellaccini <24960638+marcobellaccini@users.noreply.github.com> Date: Mon, 14 Jan 2019 14:57:30 +0100 Subject: [PATCH 04/14] Removed with_items in alternatives task --- tasks/install.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tasks/install.yml b/tasks/install.yml index 8256872f..c82d9ec2 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -58,7 +58,8 @@ - name: add redis binaries to alternatives alternatives: - name: "{{ item }}" + name: "{{ linknames }}" path: "{{ redis_install_dir }}/bin/{{ item }}" link: "/usr/bin/{{ item }}" - with_items: "{{ redis_binaries.stdout_lines }}" + vars: + linknames: "{{ redis_binaries.stdout_lines }}" From fb6508dbb057e84e82063c93cdc0a3472ffef558 Mon Sep 17 00:00:00 2001 From: marcobellaccini <24960638+marcobellaccini@users.noreply.github.com> Date: Mon, 14 Jan 2019 15:29:50 +0100 Subject: [PATCH 05/14] Removed when conditional from handlers - flush_handlers does not support it --- handlers/main.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index 8c6985bc..4e87bc03 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -3,10 +3,8 @@ service: name: "{{ redis_service_name }}" state: restarted - when: redis_as_service - name: "restart sentinel {{ redis_sentinel_port }}" service: name: sentinel_{{ redis_sentinel_port }} state: restarted - when: redis_as_service From cb8ae5110526a6127676fc2a4ebd194dbaf017cc Mon Sep 17 00:00:00 2001 From: marcobellaccini <24960638+marcobellaccini@users.noreply.github.com> Date: Mon, 14 Jan 2019 15:35:46 +0100 Subject: [PATCH 06/14] Fix deprecation warning: using tests as filters --- tasks/sentinel.yml | 2 +- tasks/server.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/sentinel.yml b/tasks/sentinel.yml index c53ebe55..d46fec41 100644 --- a/tasks/sentinel.yml +++ b/tasks/sentinel.yml @@ -50,7 +50,7 @@ when: - redis_as_service - ansible_service_mgr|default() == "systemd" - - sentinel_unit_file|changed + - sentinel_unit_file is changed - name: set sentinel to start at boot service: diff --git a/tasks/server.yml b/tasks/server.yml index 84629e94..a34b6509 100644 --- a/tasks/server.yml +++ b/tasks/server.yml @@ -50,7 +50,7 @@ when: - redis_as_service - ansible_service_mgr|default() == "systemd" - - redis_unit_file|changed + - redis_unit_file is changed - name: set redis to start at boot service: From b674528dcf05d83121301592814e39afffd2ddca Mon Sep 17 00:00:00 2001 From: marcobellaccini <24960638+marcobellaccini@users.noreply.github.com> Date: Mon, 14 Jan 2019 18:10:14 +0100 Subject: [PATCH 07/14] Idempotent implementation for log file creation tasks --- tasks/sentinel.yml | 10 ++++++---- tasks/server.yml | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tasks/sentinel.yml b/tasks/sentinel.yml index d46fec41..6758c942 100644 --- a/tasks/sentinel.yml +++ b/tasks/sentinel.yml @@ -76,10 +76,12 @@ - redis_sentinel_logfile != '""' - not sentinel_logdir.stat.exists -- name: touch the sentinel log file - file: - state: touch - path: "{{ redis_sentinel_logfile }}" +# Create an empty log file only if destination file does not exist +- name: create the sentinel log file + copy: + content: "" + dest: "{{ redis_sentinel_logfile }}" + force: no owner: "{{ redis_user }}" group: "{{ redis_group }}" when: redis_sentinel_logfile != '""' diff --git a/tasks/server.yml b/tasks/server.yml index a34b6509..99a7f40f 100644 --- a/tasks/server.yml +++ b/tasks/server.yml @@ -76,10 +76,12 @@ - redis_logfile != '""' - not logdir.stat.exists -- name: touch the log file - file: - state: touch - path: "{{ redis_logfile }}" +# Create an empty log file only if destination file does not exist +- name: create the log file + copy: + content: "" + dest: "{{ redis_logfile }}" + force: no owner: "{{ redis_user }}" group: "{{ redis_group }}" when: redis_logfile != '""' From e919cda4a833a470fef9ab9462dcd966264af2f1 Mon Sep 17 00:00:00 2001 From: marcobellaccini <24960638+marcobellaccini@users.noreply.github.com> Date: Mon, 14 Jan 2019 19:03:04 +0100 Subject: [PATCH 08/14] Idempotent implementation for config file tasks --- handlers/main.yml | 20 ++++++++++++++++++++ tasks/sentinel.yml | 11 ++++++++--- tasks/server.yml | 11 ++++++++--- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index 4e87bc03..20783309 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,4 +1,24 @@ --- +# Handler to create the "real" redis config file: this will be re-written by +# redis. +- name: enforce new redis config file + copy: + remote_src: yes + src: /etc/redis/{{ redis_port }}.refconf + dest: /etc/redis/{{ redis_port }}.conf + owner: "{{ redis_user }}" + mode: 0640 + +# Handler to create the "real" sentinel config file: this will be re-written by +# sentinel. +- name: enforce new sentinel config file + copy: + remote_src: yes + src: /etc/redis/sentinel_{{ redis_sentinel_port }}.refconf + dest: /etc/redis/sentinel_{{ redis_sentinel_port }}.conf + owner: "{{ redis_user }}" + mode: 0640 + - name: "restart redis {{ redis_port }}" service: name: "{{ redis_service_name }}" diff --git a/tasks/sentinel.yml b/tasks/sentinel.yml index 6758c942..7280cfaf 100644 --- a/tasks/sentinel.yml +++ b/tasks/sentinel.yml @@ -103,13 +103,18 @@ - redis_sentinel_pidfile != '""' - not sentinel_piddir.stat.exists -- name: create sentinel config file +# A "reference" config file is created, that will not be re-written by sentinel. +# This file is used by Ansible to check for configuration changes (and trigger +# service restart). +- name: create sentinel reference config file template: src: redis_sentinel.conf.j2 - dest: /etc/redis/sentinel_{{ redis_sentinel_port }}.conf + dest: /etc/redis/sentinel_{{ redis_sentinel_port }}.refconf owner: "{{ redis_user }}" mode: 0640 - notify: "restart sentinel {{ redis_sentinel_port }}" + notify: + - enforce new sentinel config file + - "restart sentinel {{ redis_sentinel_port }}" - name: add sentinel init config file template: diff --git a/tasks/server.yml b/tasks/server.yml index 99a7f40f..69c1037f 100644 --- a/tasks/server.yml +++ b/tasks/server.yml @@ -103,13 +103,18 @@ - redis_pidfile != '""' - not piddir.stat.exists -- name: create redis config file +# A "reference" config file is created, that will not be re-written by redis. +# This file is used by Ansible to check for configuration changes (and trigger +# service restart). +- name: create redis reference config file template: src: redis.conf.j2 - dest: /etc/redis/{{ redis_port }}.conf + dest: /etc/redis/{{ redis_port }}.refconf owner: "{{ redis_user }}" mode: 0640 - notify: "restart redis {{ redis_port }}" + notify: + - enforce new redis config file + - "restart redis {{ redis_port }}" - name: add redis init config file template: From 6a3c30274cc70311c3ca11e19f5ffcb258579f76 Mon Sep 17 00:00:00 2001 From: marcobellaccini <24960638+marcobellaccini@users.noreply.github.com> Date: Mon, 14 Jan 2019 19:22:25 +0100 Subject: [PATCH 09/14] Fixed undefined var --- tasks/install.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/install.yml b/tasks/install.yml index c82d9ec2..d8a1701d 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -59,7 +59,7 @@ - name: add redis binaries to alternatives alternatives: name: "{{ linknames }}" - path: "{{ redis_install_dir }}/bin/{{ item }}" - link: "/usr/bin/{{ item }}" + path: "{{ redis_install_dir }}/bin/{{ linknames }}" + link: "/usr/bin/{{ linknames }}" vars: linknames: "{{ redis_binaries.stdout_lines }}" From afba562b84c3da5e0456c3bc1f8e9826f730ac58 Mon Sep 17 00:00:00 2001 From: marcobellaccini <24960638+marcobellaccini@users.noreply.github.com> Date: Mon, 14 Jan 2019 19:26:35 +0100 Subject: [PATCH 10/14] Fixed loop --- tasks/install.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tasks/install.yml b/tasks/install.yml index d8a1701d..223e7926 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -58,8 +58,7 @@ - name: add redis binaries to alternatives alternatives: - name: "{{ linknames }}" - path: "{{ redis_install_dir }}/bin/{{ linknames }}" - link: "/usr/bin/{{ linknames }}" - vars: - linknames: "{{ redis_binaries.stdout_lines }}" + name: "{{ item }}" + path: "{{ redis_install_dir }}/bin/{{ item }}" + link: "/usr/bin/{{ item }}" + loop: "{{ redis_binaries.stdout_lines }}" From a6a37575259b5aa3c4ad1da45777f7f2a54605c3 Mon Sep 17 00:00:00 2001 From: marcobellaccini <24960638+marcobellaccini@users.noreply.github.com> Date: Tue, 15 Jan 2019 11:23:16 +0100 Subject: [PATCH 11/14] Removed problematic flush_handlers --- handlers/main.yml | 8 ++++++++ tasks/install.yml | 1 + tasks/server.yml | 5 ----- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index 20783309..5a8075d1 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -23,8 +23,16 @@ service: name: "{{ redis_service_name }}" state: restarted + # do not restart if redis was just installed + # this prevents redis from starting and then re-starting + # in most cases + when: redis_as_service and (not redis_installed.changed) - name: "restart sentinel {{ redis_sentinel_port }}" service: name: sentinel_{{ redis_sentinel_port }} state: restarted + # do not restart if redis was just installed + # this prevents sentinel from starting and then re-starting + # in most cases + when: redis_as_service and (not redis_installed.changed) diff --git a/tasks/install.yml b/tasks/install.yml index 223e7926..9a98ae14 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -50,6 +50,7 @@ args: chdir: /usr/local/src/redis-{{ redis_version }} creates: "{{ redis_install_dir }}/bin/redis-server" + register: redis_installed - name: list redis binaries to add to alternatives command: ls -1 {{ redis_install_dir }}/bin diff --git a/tasks/server.yml b/tasks/server.yml index 69c1037f..11faa5d1 100644 --- a/tasks/server.yml +++ b/tasks/server.yml @@ -132,11 +132,6 @@ when: ansible_os_family == "Debian" notify: "restart redis {{ redis_port }}" -# Flush handlers before ensuring the service is started to prevent -# a start and then restart -- name: flush handlers to apply config changes - meta: flush_handlers - - name: ensure redis is running service: name: "{{ redis_service_name }}" From ab9f55a8f766f5f1a7d983c5576a57fc8629bcb0 Mon Sep 17 00:00:00 2001 From: marcobellaccini <24960638+marcobellaccini@users.noreply.github.com> Date: Tue, 15 Jan 2019 11:30:45 +0100 Subject: [PATCH 12/14] Removed problematic flush_handlers for sentinel --- tasks/sentinel.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tasks/sentinel.yml b/tasks/sentinel.yml index 7280cfaf..52370a0f 100644 --- a/tasks/sentinel.yml +++ b/tasks/sentinel.yml @@ -130,11 +130,6 @@ when: ansible_os_family == "Debian" notify: "restart sentinel {{ redis_sentinel_port }}" -# Flush handlers before ensuring the service is started to prevent -# a start and then restart -- name: flush handlers to apply config changes - meta: flush_handlers - - name: ensure sentinel is running service: name: sentinel_{{ redis_sentinel_port }} From 26ef38fd7b5f7b89313009f182a9ceaaa9d71adf Mon Sep 17 00:00:00 2001 From: marcobellaccini <24960638+marcobellaccini@users.noreply.github.com> Date: Tue, 15 Jan 2019 11:58:17 +0100 Subject: [PATCH 13/14] Fix for config file tasks idempotency --- handlers/main.yml | 20 -------------------- tasks/sentinel.yml | 16 +++++++++++++--- tasks/server.yml | 15 ++++++++++++--- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index 5a8075d1..9c004af0 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,24 +1,4 @@ --- -# Handler to create the "real" redis config file: this will be re-written by -# redis. -- name: enforce new redis config file - copy: - remote_src: yes - src: /etc/redis/{{ redis_port }}.refconf - dest: /etc/redis/{{ redis_port }}.conf - owner: "{{ redis_user }}" - mode: 0640 - -# Handler to create the "real" sentinel config file: this will be re-written by -# sentinel. -- name: enforce new sentinel config file - copy: - remote_src: yes - src: /etc/redis/sentinel_{{ redis_sentinel_port }}.refconf - dest: /etc/redis/sentinel_{{ redis_sentinel_port }}.conf - owner: "{{ redis_user }}" - mode: 0640 - - name: "restart redis {{ redis_port }}" service: name: "{{ redis_service_name }}" diff --git a/tasks/sentinel.yml b/tasks/sentinel.yml index 52370a0f..3b7a71c8 100644 --- a/tasks/sentinel.yml +++ b/tasks/sentinel.yml @@ -112,9 +112,19 @@ dest: /etc/redis/sentinel_{{ redis_sentinel_port }}.refconf owner: "{{ redis_user }}" mode: 0640 - notify: - - enforce new sentinel config file - - "restart sentinel {{ redis_sentinel_port }}" + register: sentinel_refconf + notify: "restart sentinel {{ redis_sentinel_port }}" + +# Create the "real" sentinel config file: the one that will be re-written by +# sentinel. +- name: enforce new sentinel config file + copy: + remote_src: yes + src: /etc/redis/sentinel_{{ redis_sentinel_port }}.refconf + dest: /etc/redis/sentinel_{{ redis_sentinel_port }}.conf + owner: "{{ redis_user }}" + mode: 0640 + when: sentinel_refconf.changed - name: add sentinel init config file template: diff --git a/tasks/server.yml b/tasks/server.yml index 11faa5d1..0f3ffb84 100644 --- a/tasks/server.yml +++ b/tasks/server.yml @@ -112,9 +112,18 @@ dest: /etc/redis/{{ redis_port }}.refconf owner: "{{ redis_user }}" mode: 0640 - notify: - - enforce new redis config file - - "restart redis {{ redis_port }}" + register: redis_refconf + notify: "restart redis {{ redis_port }}" + +# Create the "real" redis config file: the one that will be re-written by redis. +- name: enforce new redis config file + copy: + remote_src: yes + src: /etc/redis/{{ redis_port }}.refconf + dest: /etc/redis/{{ redis_port }}.conf + owner: "{{ redis_user }}" + mode: 0640 + when: redis_refconf.changed - name: add redis init config file template: From 7c66ed872901971e8ff6b8dbf7546ad475572fc9 Mon Sep 17 00:00:00 2001 From: marcobellaccini <24960638+marcobellaccini@users.noreply.github.com> Date: Tue, 15 Jan 2019 15:11:31 +0100 Subject: [PATCH 14/14] Changed minimum Ansible version to 2.5.0 --- .travis.yml | 5 +++-- README.md | 4 ++-- meta/main.yml | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index adbfaa00..5e85e56b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,9 @@ language: python python: "2.7" env: - - ANSIBLE_VERSION=2.1.6 - - ANSIBLE_VERSION=2.3.3 + - ANSIBLE_VERSION=2.5.14 + - ANSIBLE_VERSION=2.6.11 + - ANSIBLE_VERSION=2.7.5 - ANSIBLE_VERSION=latest before_install: diff --git a/README.md b/README.md index 015ced9e..04fa71be 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ [![Build Status](https://travis-ci.org/DavidWittman/ansible-redis.svg?branch=master)](https://travis-ci.org/DavidWittman/ansible-redis) [![Ansible Galaxy](https://img.shields.io/badge/galaxy-DavidWittman.redis-blue.svg?style=flat)](https://galaxy.ansible.com/detail#/role/730) - - Ansible 2.1+ + - Ansible 2.5+ - Compatible with most versions of Ubuntu/Debian and RHEL/CentOS 6.x - + ## Contents 1. [Installation](#installation) diff --git a/meta/main.yml b/meta/main.yml index d3884b56..5f45e4c4 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -2,7 +2,7 @@ galaxy_info: author: David Wittman description: Highly configurable role to install Redis and Redis Sentinel from source - min_ansible_version: 1.9.0 + min_ansible_version: 2.5.0 license: MIT platforms: - name: Ubuntu