Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix configure tasks loop #24

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Expand Up @@ -27,12 +28,12 @@
{% endif %}
tags: redis_cluster

- name: print redis command

Check warning on line 31 in tasks/cluster.yml

View workflow job for this annotation

GitHub Actions / lint_full

name[casing]

All names should start with an uppercase letter.
debug:
var: redis_cluster_command
tags: redis_cluster

- name: Get redis cluster info

Check warning on line 36 in tasks/cluster.yml

View workflow job for this annotation

GitHub Actions / lint_full

jinja[spacing]

Jinja2 spacing could be improved: redis-cli -h {{ ansible_default_ipv4.address|default(ansible_all_ipv4_addresses[0]) }} -p {% if redis_configurations[0]['redis_tls_cluster'] is defined and redis_configurations[0]['redis_tls_cluster'] == 'yes' %} {{ redis_configurations[0]['redis_tls_port'] }} {% else %} {{ redis_configurations[0]['redis_port'] }} {% endif %} {% if redis_configurations[0]['redis_tls_cluster'] is defined and redis_configurations[0]['redis_tls_cluster'] == 'yes' %} --tls --cert {{ redis_configurations[0]['redis_tls_cert_file'] }} --key {{ redis_configurations[0]['redis_tls_key_file'] }} --cacert {{ redis_configurations[0]['redis_tls_ca_cert_file'] }} {% endif %} -a {{ redis_requirepass }} CLUSTER INFO -> redis-cli -h {{ ansible_default_ipv4.address | default(ansible_all_ipv4_addresses[0]) }} -p {% if redis_configurations[0]['redis_tls_cluster'] is defined and redis_configurations[0]['redis_tls_cluster'] == 'yes' %} {{ redis_configurations[0]['redis_tls_port'] }} {% else %} {{ redis_configurations[0]['redis_port'] }} {% endif %} {% if redis_configurations[0]['redis_tls_cluster'] is defined and redis_configurations[0]['redis_tls_cluster'] == 'yes' %} --tls --cert {{ redis_configurations[0]['redis_tls_cert_file'] }} --key {{ redis_configurations[0]['redis_tls_key_file'] }} --cacert {{ redis_configurations[0]['redis_tls_ca_cert_file'] }} {% endif %} -a {{ redis_requirepass }} CLUSTER INFO
command: "redis-cli -h {{ ansible_default_ipv4.address|default(ansible_all_ipv4_addresses[0]) }} -p {% if redis_configurations[0]['redis_tls_cluster'] is defined and redis_configurations[0]['redis_tls_cluster'] == 'yes' %} {{ redis_configurations[0]['redis_tls_port'] }} {% else %} {{ redis_configurations[0]['redis_port'] }} {% endif %} {% if redis_configurations[0]['redis_tls_cluster'] is defined and redis_configurations[0]['redis_tls_cluster'] == 'yes' %} --tls --cert {{ redis_configurations[0]['redis_tls_cert_file'] }} --key {{ redis_configurations[0]['redis_tls_key_file'] }} --cacert {{ redis_configurations[0]['redis_tls_ca_cert_file'] }} {% endif %} -a {{ redis_requirepass }} CLUSTER INFO"
register: cluster_info
changed_when: false
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 }}"

afeefghannam89 marked this conversation as resolved.
Show resolved Hide resolved
- 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
Loading