使用Ansible Playbook安装Redis的2.5及以上版本
尝试使用Ansible自动化安装Redis时遇到了问题。如果通过yum安装Redis,只能获取到2.4版本的Redis。
由于想要使用2.8版本,所以尽管麻烦,我决定从源代码安装Redis。需要说明的是,操作系统为CentOS6.5。
---
- hosts: hostuo
sudo: yes
tasks:
- name: libselinux-python install
yum: name=libselinux-python state=latest
- name: gcc install
yum: name=gcc state=latest
- name: redis source download
get_url: >
url=http://download.redis.io/releases/redis-2.8.19.tar.gz
dest=/tmp/redis-2.8.19.tar.gz
- name: redis unarchive
command: >
tar zxvf redis-2.8.19.tar.gz
chdir=/tmp/
- name: make
command: >
make
chdir=/tmp/redis-2.8.19
- name: make install
command: >
make install
chdir=/tmp/redis-2.8.19
- name: deamonize on
replace: >
dest=/tmp/redis-2.8.19/redis.conf
regexp='daemonize no'
replace='daemonize yes'
- name: redis.conf copy
copy: >
src=/tmp/redis-2.8.19/redis.conf
dest=/etc/redis.conf
owner=vagrant
- name: redis start
command: >
redis-server /etc/redis.conf
sudo: no
执行ansible-playbook。
$ ansible-playbook playbook.yml
PLAY [127.0.0.1] **************************************************************
~中略~
PLAY RECAP ********************************************************************
to retry, use: --limit @/home/username/playbook.retry
127.0.0.1 : ok=10 changed=10 unreachable=0 failed=0
看起来进展得很顺利。
$ redis-server -v
Redis server v=2.8.19 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=6456d4b7b0a33b29
$ redis-cli
127.0.0.1:6379>