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/handlers/main.yml b/handlers/main.yml index 8c6985bc..9c004af0 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -3,10 +3,16 @@ service: name: "{{ redis_service_name }}" state: restarted - when: redis_as_service + # 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 - when: redis_as_service + # 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/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 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' diff --git a/tasks/install.yml b/tasks/install.yml index 6c04c912..9a98ae14 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: @@ -57,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 @@ -68,4 +62,4 @@ name: "{{ item }}" path: "{{ redis_install_dir }}/bin/{{ item }}" link: "/usr/bin/{{ item }}" - with_items: "{{ redis_binaries.stdout_lines }}" + loop: "{{ redis_binaries.stdout_lines }}" diff --git a/tasks/sentinel.yml b/tasks/sentinel.yml index c53ebe55..3b7a71c8 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: @@ -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 != '""' @@ -101,14 +103,29 @@ - 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 + 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: dest: /etc/sysconfig/sentinel_{{ redis_sentinel_port }} @@ -123,11 +140,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 }} diff --git a/tasks/server.yml b/tasks/server.yml index 84629e94..0f3ffb84 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: @@ -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 != '""' @@ -101,14 +103,28 @@ - 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 + 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: dest: /etc/sysconfig/{{ redis_service_name }} @@ -125,11 +141,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 }}" 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