Skip to content

Commit

Permalink
Merge pull request #24 from tbumke/fix/configure-loop
Browse files Browse the repository at this point in the history
Fix configure tasks loop
  • Loading branch information
afeefghannam89 authored Nov 6, 2024
2 parents bf7b0ec + 7a0a6bb commit 6b08431
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
5 changes: 0 additions & 5 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,3 @@
- name: Daemon reload
systemd:
daemon_reload: yes

- name: Restart redis
systemd:
state: restarted
name: "{{ service_name }}"
1 change: 1 addition & 0 deletions tasks/cluster.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---

- name: Set redis cluster command
set_fact:
redis_cluster_command: >-
Expand Down
41 changes: 26 additions & 15 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
---
- name: "Set redis service for {{ item.redis_instance_name }}"

- name: "Set redis service"
template:
src: redis.service.j2
dest: "{{ redis_systemd_directory }}/{{ item.redis_instance_name }}.service"
mode: '0644'
owner: root
group: root
when: "ansible_service_mgr == 'systemd'"
notify:
- Daemon reload
loop: "{{ redis_configurations | default([]) }}"
loop_control:
label: "{{ item.redis_instance_name }}"
notify: Daemon reload

- name: Flush handlers
meta: flush_handlers

- name: "Create redis config directory for {{ item.redis_instance_name }}"
- name: "Create redis config directory"
file:
path: "{{ redis_config_directory }}"
state: directory
Expand All @@ -23,25 +26,33 @@
setype: redis_conf_t
when: redis_config_directory != "/etc"

- name: "Set service name {{ item.redis_instance_name }}"
set_fact:
service_name: "{{ item.redis_instance_name }}.service"

- name: "Set redis config for {{ item.redis_instance_name }}"
- name: "Set redis config"
template:
src: redis.conf.j2
dest: "{{ redis_config_directory }}/{{ item.redis_instance_name }}.conf"
owner: "{{ redis_user_name }}"
group: "{{ redis_group_name }}"
mode: '0660'
setype: redis_conf_t
notify: Restart redis
register: redis_config
loop: "{{ redis_configurations | default([]) }}"
loop_control:
label: "{{ item.redis_instance_name }}"

- name: "Restart redis service(s) if config changed"
systemd:
state: restarted
name: "{{ item.redis_instance_name }}"
when: redis_config.changed
loop: "{{ redis_configurations | default([]) }}"
loop_control:
label: "{{ item.redis_instance_name }}"

- name: "Start redis service {{ item.redis_instance_name }}"
- name: "Start and enable redis service(s)"
systemd:
state: started
name: "{{ service_name }}"
name: "{{ item.redis_instance_name }}"
enabled: yes

- name: Flush handlers
meta: flush_handlers
loop: "{{ redis_configurations | default([]) }}"
loop_control:
label: "{{ item.redis_instance_name }}"
1 change: 0 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
apply:
tags: redis_configuration
tags: redis_configuration
loop: "{{ redis_configurations | default([]) }}"

- name: Build a cluster
import_tasks: cluster.yml
Expand Down

0 comments on commit 6b08431

Please sign in to comment.