ansible-redis
ansible-redis copied to clipboard
Make Install Stage Skippable and Remove Source
Great module; very nicely setup Redis on my CentOS7 system. Much easier than writing it myself. However, I found myself wanting a couple features:
- Don't rerun install if the correct version is already installed. (I realized there are pros and cons to always rerunning the install stage, but if Redis is already installed, I'd like to skip running download/make/etc.)
- Remove source after installation.
My first pass looks like this for main.yml
---
- name: Check redis-server version
command: "redis-server --version"
register: redis_sever_version
# May not be installed, or may be the wrong version
# Version format is: Redis server v<version> sha=...
# So [2][1:] is all of the second word except the leading 'v'
changed_when: redis_sever_version.rc or redis_sever_version.stdout.split(' ')[2][1:]|version_compare(redis_version, '<')
failed_when: False
always_run: yes
- include: install.yml
when: redis_sever_version.changed
- file: name=/usr/local/src/redis-{{ redis_version }} state=absent
when: redis_sever_version.changed
- file: name=/usr/local/src/redis-{{ redis_version }}.tar.gz state=absent
when: redis_sever_version.changed
- include: server.yml
when: not redis_sentinel
tags:
- config
- include: sentinel.yml
when: redis_sentinel
tags:
- config
- include: local_facts.yml
Thanks @rayalan... I like this idea. Instead of trying to be too magical, how about just a redis_upgrade
variable which, if set, will trigger the install process? This way we give more control to the user and don't go unexpectedly upgrading Redis.
It can default to no
, but will still install Redis if it doesn't already find a version in the redis_install_dir
.
I like the idea of a redis_upgrade variable; that does seem like a cleaner approach.