Skip to content

Commit

Permalink
Reworked tasks using YAML syntax. Added FIXME.
Browse files Browse the repository at this point in the history
  • Loading branch information
ypid committed Jun 28, 2016
1 parent 6546414 commit 7ba4302
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 31 deletions.
20 changes: 17 additions & 3 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
---

- name: Install Redis server
apt: pkg=redis-server state=present install_recommends=False
apt:
pkg: '{{ item }}'
state: 'present'
install_recommends: False
with_flattened:
- 'redis-server'

- name: Detect Redis version
shell: redis-server -v | awk '{print $3}'
changed_when: False
register: register_redis_version

- name: Create Redis paths
file: path={{ item }} state=directory owner=redis group=redis mode=0755
file:
path: '{{ item }}'
state: 'directory'
owner: 'redis'
group: 'redis'
mode: '0755'
with_items:
- '{{ redis_dir }}'
- '{{ redis_run_state }}'
Expand All @@ -25,11 +35,15 @@
# Always install Redis server unless the host exists in the sentinel group
# and it's not standalone.
- include: server.yml
# FIXME: Evaluates always to True!
when: (not redis_sentinel_standalone and
redis_sentinel_hosts_group in group_names) or True

- name: Stop Redis Server
service: name=redis-server state=stopped enabled=no
service:
name: 'redis-server'
state: 'stopped'
enabled: 'no'
when: redis_sentinel_standalone and
redis_hosts_group in group_names and
redis_sentinel_hosts_group in group_names
45 changes: 31 additions & 14 deletions tasks/sentinel.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
---

- name: Change ownership to 'redis' for the main Sentinel config
file: path=/etc/redis/sentinel.conf
owner=redis group=redis mode=0644
file:
path: '/etc/redis/sentinel.conf'
owner: 'redis'
group: 'redis'
mode: '0644'

- name: Detect if this is the first time the role has been ran
stat: path={{ redis_custom_sentinel_config }}
stat:
path: '{{ redis_custom_sentinel_config }}'
register: redis_register_custom_sentinel_config

- name: Detect if maxmemory is in the main Sentinel config
Expand Down Expand Up @@ -97,28 +101,41 @@
changed_when: False

- name: Configure Redis Sentinel
template: src=etc/redis/sentinel-ansible.conf.j2
dest={{ redis_custom_sentinel_config }}
owner=root group=root mode=0644
template:
src: 'etc/redis/sentinel-ansible.conf.j2'
dest: '{{ redis_custom_sentinel_config }}'
owner: 'root'
group: 'root'
mode: '0644'
notify: ['Restart Redis Sentinel']

- name: Configure Redis Sentinel scripts
template: src=usr/local/lib/redis/trigger.sh.j2
dest={{ redis_dir }}/{{ item.1 }}.sh
owner=redis group=redis mode=0755
template:
src: 'usr/local/lib/redis/trigger.sh.j2'
dest: '{{ redis_dir }}/{{ item.1 }}.sh'
owner: 'redis'
group: 'redis'
mode: '0755'
register: redis_register_trigger_scripts
with_nested:
- '{{ redis_sentinel_group_list }}'
- ['notification', 'client_reconfig']
notify: ['Restart Redis Sentinel']

- name: Configure Redis Sentinel service
template: src=etc/init.d/service.j2
dest=/etc/init.d/redis-{{ item.name }}
owner=redis group=redis mode=0755
template:
src: 'etc/init.d/service.j2'
dest: '/etc/init.d/redis-{{ item.name }}'
owner: 'redis'
group: 'redis'
mode: '0755'
with_items:
- { name: 'sentinel', config: '{{ redis_sentinel_config }}' }
- name: 'sentinel'
config: '{{ redis_sentinel_config }}'
notify: ['Restart Redis Sentinel']

- name: Start Redis Sentinel
service: name=redis-sentinel state=started enabled=yes
service:
name: 'redis-sentinel'
state: 'started'
enabled: 'yes'
45 changes: 31 additions & 14 deletions tasks/server.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
---

- name: Change ownership to 'redis' for the main Redis server config
file: path=/etc/redis/redis.conf
owner=redis group=redis mode=0644
file:
path: '/etc/redis/redis.conf'
owner: 'redis'
group: 'redis'
mode: '0644'

- name: Detect if this is the first time the role has been ran
stat: path={{ redis_custom_config }}
stat:
path: '{{ redis_custom_config }}'
register: redis_register_custom_config

- name: Detect if a slaveof line already exists in the main Redis config
Expand Down Expand Up @@ -100,27 +104,40 @@
notify: ['Restart Redis Server']

- name: Configure Redis Server
template: src=etc/redis/redis-ansible.conf.j2
dest=/etc/redis/redis-ansible.conf
owner=root group=root mode=0644
template:
src: 'etc/redis/redis-ansible.conf.j2'
dest: '/etc/redis/redis-ansible.conf'
owner: 'root'
group: 'root'
mode: '0644'
notify: ['Restart Redis Server']

- name: Configure Redis Server defaults
template: src=etc/default/redis-server.j2
dest=/etc/default/redis-server
owner=redis group=redis mode=0644
template:
src: 'etc/default/redis-server.j2'
dest: '/etc/default/redis-server'
owner: 'redis'
group: 'redis'
mode: '0644'
notify: ['Restart Redis Server']

- name: Configure Redis Server service
template: src=etc/init.d/service.j2
dest=/etc/init.d/redis-{{ item.name }}
owner=redis group=redis mode=0755
template:
src: 'etc/init.d/service.j2'
dest: '/etc/init.d/redis-{{ item.name }}'
owner: 'redis'
group: 'redis'
mode: '0755'
with_items:
- { name: 'server', config: '{{ redis_config }}' }
- name: 'server'
config: '{{ redis_config }}'
notify: ['Restart Redis Server']

- name: Start Redis Server
service: name=redis-server state=started enabled=yes
service:
name: 'redis-server'
state: 'started'
enabled: 'yes'
when: not redis_hosts_group in group_names or
(redis_hosts_group in group_names and
(not redis_sentinel_standalone and
Expand Down

0 comments on commit 7ba4302

Please sign in to comment.