Skip to content

Role idempotency, fixed deprecations, flush_handlers warning, updated checksums #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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:
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 8 additions & 2 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tasks/check_vars.yml
Original file line number Diff line number Diff line change
@@ -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:
48 changes: 26 additions & 22 deletions tasks/dependencies.yml
Original file line number Diff line number Diff line change
@@ -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'
12 changes: 3 additions & 9 deletions tasks/install.yml
Original file line number Diff line number Diff line change
@@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a risk here of setting the shell to /bin/false of a login user, if for any reason redis_user is set to anything else but redis


- 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 }}"
36 changes: 24 additions & 12 deletions tasks/sentinel.yml
Original file line number Diff line number Diff line change
@@ -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 }}
35 changes: 23 additions & 12 deletions tasks/server.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
6 changes: 6 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -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