ansible-redis icon indicating copy to clipboard operation
ansible-redis copied to clipboard

Make Install Stage Skippable and Remove Source

Open rayalan opened this issue 9 years ago • 2 comments

Great module; very nicely setup Redis on my CentOS7 system. Much easier than writing it myself. However, I found myself wanting a couple features:

  1. 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.)
  2. 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

rayalan avatar Mar 06 '15 21:03 rayalan

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.

DavidWittman avatar Mar 08 '15 19:03 DavidWittman

I like the idea of a redis_upgrade variable; that does seem like a cleaner approach.

rayalan avatar Mar 09 '15 13:03 rayalan