Split glusterd tasks to task files

This re-arranges existing tasks into multiple task files
for better readability and to better handle complexity of the role.

This should allow to add some more complexity if needed to handle extra
recovery scenarios.

Change-Id: I8da129ddf2bf341142db6b8569091c14a71713a4
Signed-off-by: Dmitriy Rabotyagov <dmitriy.rabotyagov@cleura.com>
This commit is contained in:
Dmitriy Rabotyagov
2025-11-04 18:20:54 +01:00
parent d5ddfcd80f
commit f97c2e0b47
5 changed files with 252 additions and 180 deletions

View File

@@ -0,0 +1,64 @@
---
# Copyright 2022, BBC R&D.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Include tasks for EL
ansible.builtin.include_tasks:
file: glusterfs_install_dnf.yml
when: ansible_facts['pkg_mgr'] == 'dnf'
- name: Install glusterfs server packages
ansible.builtin.package:
name: "{{ glusterfs_server_distro_packages }}"
state: "{{ glusterfs_package_state }}"
- name: Drop glusterfs-wait.sh script
ansible.builtin.copy:
src: glusterfs-wait.sh
dest: /usr/local/sbin
mode: "0744"
- name: Add glusterd.service overrides
ansible.builtin.import_role:
name: systemd_service
vars:
systemd_services:
- service_name: glusterd
systemd_overrides_only: true
systemd_overrides:
Service:
ExecStartPost: "/usr/local/sbin/glusterfs-wait.sh"
- name: Configure systemd-tmpfiles to create /dev/fuse at boot
ansible.builtin.copy:
content: "c /dev/fuse 0600 - - - 10:229"
dest: "/etc/tmpfiles.d/openstack-ansible-glusterfs-server.conf"
mode: "0644"
when: not (is_metal | default(False))
register: _glusterfs_server_tmpfiles
- name: Restart systemd-tmpfiles-setup-dev
ansible.builtin.service:
name: "systemd-tmpfiles-setup-dev"
enabled: true
state: restarted
when:
- not (is_metal | default(False))
- _glusterfs_server_tmpfiles is changed
- name: Start glusterfs server
ansible.builtin.service:
name: "{{ glusterfs_server_service }}"
enabled: true
state: started

View File

@@ -0,0 +1,75 @@
---
# Copyright 2022, BBC R&D.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Enable extra repositories
ansible.builtin.command: dnf config-manager --set-enabled "{{ item }}"
changed_when: false
with_items: "{{ glusterfs_server_dnf_enable }}"
- name: Install gluster repo packages
ansible.builtin.package:
name: "{{ glusterfs_server_dnf_sig_packages }}"
when:
- glusterfs_server_dnf_sig_packages | length > 0
- name: If a keyfile is provided, copy the gpg keyfile to the key location
ansible.builtin.copy:
src: "{{ item.keyfile }}"
dest: "{{ item.key }}"
mode: "0644"
with_items: "{{ glusterfs_package_repo_keys | default([]) | selectattr('keyfile', 'defined') | list }}"
- name: Install gpg keys
ansible.builtin.rpm_key:
key: "{{ key.key }}"
validate_certs: "{{ key.validate_certs | default(omit) }}"
state: "{{ key.state | default('present') }}"
with_items: "{{ glusterfs_package_repo_keys | default([]) }}"
loop_control:
loop_var: key
register: _add_yum_keys
until: _add_yum_keys is success
retries: 5
delay: 2
- name: Install required RPM repositories
ansible.builtin.yum_repository:
name: "{{ item.name }}"
baseurl: "{{ item.baseurl }}"
description: "{{ item.description }}"
gpgkey: "{{ item.gpgkey }}"
gpgcheck: "{{ item.gpgcheck }}"
enabled: "{{ item.enabled }}"
state: "{{ item.state }}"
includepkgs: "{{ item.includepkgs | default([]) }}"
loop: "{{ glusterfs_package_repos | default([]) }}"
loop_control:
label: "{{ item.name }}"
register: install_epel_repo
until: install_epel_repo is success
retries: 5
delay: 2
- name: Apply systemctl overrides
ansible.builtin.import_role:
name: systemd_service
vars:
systemd_services:
- service_name: systemd-tmpfiles-setup-dev
load: false
systemd_overrides_only: true
systemd_overrides:
Unit:
ConditionCapability: ""

View File

@@ -0,0 +1,55 @@
---
# Copyright 2022, BBC R&D.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Create gluster peers
gluster.gluster.gluster_peer:
nodes: "{{ glusterfs_server_cluster_members }}"
when: _glusterfs_is_bootstrap_host
- name: Ensure glusterfs backing directory exists
ansible.builtin.file:
path: "{{ glusterfs_server_backing_dir }}"
state: directory
mode: "0755"
register: _backing_dir_create
- name: Check brick status
throttle: 1
ansible.builtin.command: gluster volume status {{ glusterfs_server_volume_name }} {{ inventory_hostname | regex_replace('_', '-') }}:{{ glusterfs_server_bricks
}} detail
register: _brick_online_status
changed_when: false
failed_when: false
# NOTE (jrosser) run this task if we just created the data dir, the volume exists (status was available)
# and the brick on this node is offline. This covers a destroy/create of an existing host
- name: Reset brick for a replaced node
vars:
brick: "{{ inventory_hostname | regex_replace('_', '-') }}:{{ glusterfs_server_bricks }}"
ansible.builtin.command: "{{ item }}"
changed_when: false
when:
- _backing_dir_create is changed
- _brick_online_status.rc == 0
- (_brick_online_status.stdout_lines | select('contains', 'Online'))[0] | regex_search('N')
with_items:
- gluster volume reset-brick {{ glusterfs_server_volume_name }} {{ brick }} start
- gluster volume reset-brick {{ glusterfs_server_volume_name }} {{ brick }} {{ brick }} commit force
- name: Include glusterfs volume tasks
ansible.builtin.include_tasks:
file: glusterfs_post_install_brick.yml
when:
- _glusterfs_is_bootstrap_host

View File

@@ -0,0 +1,48 @@
---
# Copyright 2022, BBC R&D.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# NOTE: When first establishing a peer relationship, a reverse DNS lookup happens which can cause a
# peer's active hostname not to match the one stored on disk. Restarting the service resolves
# this and prevents failures upon calls to create volumes.
- name: Find existing peers' runtime hostnames
ansible.builtin.shell: "gluster peer status | grep Hostname: | cut -d ' ' -f 2"
changed_when: false
register: _existing_peer_hostnames
when: (glusterfs_server_cluster_members | length) > 1
- name: Restart glusterfs server
ansible.builtin.service:
name: "{{ glusterfs_server_service }}"
state: restarted
when:
- _existing_peer_hostnames is not skipped
- ((_existing_peer_hostnames.stdout_lines | intersect(glusterfs_server_cluster_members)) | length) != (_existing_peer_hostnames.stdout_lines | length)
# Retry as the service may have just restarted
- name: Create gluster volume
vars:
num_cluster_members: "{{ glusterfs_server_cluster_members | length }}"
cluster_has_replicas: "{{ (glusterfs_server_cluster_members | length) > 1 }}"
gluster.gluster.gluster_volume:
state: present
name: "{{ glusterfs_server_volume_name }}"
bricks: "{{ glusterfs_server_bricks }}"
replicas: "{{ cluster_has_replicas | ternary(num_cluster_members, omit) }}"
cluster: "{{ glusterfs_server_cluster_members | map('regex_replace', '_', '-') | list }}"
force: true
register: _volume_create
delay: 1
retries: 5
until: _volume_create is success

View File

@@ -29,184 +29,14 @@
tags:
- always
- name: Enable repos for redhat variants
when: ansible_facts['pkg_mgr'] == 'dnf'
block:
- name: Enable extra repositories
ansible.builtin.command: dnf config-manager --set-enabled "{{ item }}"
changed_when: false
with_items: "{{ glusterfs_server_dnf_enable }}"
- name: Import glusterfs install tasks
ansible.builtin.import_tasks:
file: glusterfs_install.yml
tags:
- glusterfs-install
- name: Install gluster repo packages
ansible.builtin.package:
name: "{{ glusterfs_server_dnf_sig_packages }}"
when:
- glusterfs_server_dnf_sig_packages | length > 0
- name: If a keyfile is provided, copy the gpg keyfile to the key location
ansible.builtin.copy:
src: "{{ item.keyfile }}"
dest: "{{ item.key }}"
mode: "0644"
with_items: "{{ glusterfs_package_repo_keys | default([]) | selectattr('keyfile', 'defined') | list }}"
- name: Install gpg keys
ansible.builtin.rpm_key:
key: "{{ key.key }}"
validate_certs: "{{ key.validate_certs | default(omit) }}"
state: "{{ key.state | default('present') }}"
with_items: "{{ glusterfs_package_repo_keys | default([]) }}"
loop_control:
loop_var: key
register: _add_yum_keys
until: _add_yum_keys is success
retries: 5
delay: 2
- name: Install required RPM repositories
ansible.builtin.yum_repository:
name: "{{ item.name }}"
baseurl: "{{ item.baseurl }}"
description: "{{ item.description }}"
gpgkey: "{{ item.gpgkey }}"
gpgcheck: "{{ item.gpgcheck }}"
enabled: "{{ item.enabled }}"
state: "{{ item.state }}"
includepkgs: "{{ item.includepkgs | default([]) }}"
loop: "{{ glusterfs_package_repos | default([]) }}"
loop_control:
label: "{{ item.name }}"
register: install_epel_repo
until: install_epel_repo is success
retries: 5
delay: 2
- name: Apply systemctl overrides
ansible.builtin.import_role:
name: systemd_service
vars:
systemd_services:
- service_name: systemd-tmpfiles-setup-dev
load: false
systemd_overrides_only: true
systemd_overrides:
Unit:
ConditionCapability: ""
- name: Install glusterfs server packages
ansible.builtin.package:
name: "{{ glusterfs_server_distro_packages }}"
state: "{{ glusterfs_package_state }}"
- name: Drop glusterfs-wait.sh script
ansible.builtin.copy:
src: glusterfs-wait.sh
dest: /usr/local/sbin
mode: "0744"
- name: Add glusterd.service overrides
ansible.builtin.import_role:
name: systemd_service
vars:
systemd_services:
- service_name: glusterd
systemd_overrides_only: true
systemd_overrides:
Service:
ExecStartPost: "/usr/local/sbin/glusterfs-wait.sh"
- name: Configure systemd-tmpfiles to create /dev/fuse at boot
ansible.builtin.copy:
content: "c /dev/fuse 0600 - - - 10:229"
dest: "/etc/tmpfiles.d/openstack-ansible-glusterfs-server.conf"
mode: "0644"
when: not (is_metal | default(False))
register: _glusterfs_server_tmpfiles
- name: Restart systemd-tmpfiles-setup-dev
ansible.builtin.service:
name: "systemd-tmpfiles-setup-dev"
enabled: true
state: restarted
when:
- not (is_metal | default(False))
- _glusterfs_server_tmpfiles is changed
- name: Start glusterfs server
ansible.builtin.service:
name: "{{ glusterfs_server_service }}"
enabled: true
state: started
- name: Create gluster peers
gluster.gluster.gluster_peer:
nodes: "{{ glusterfs_server_cluster_members }}"
when: _glusterfs_is_bootstrap_host
- name: Ensure glusterfs backing directory exists
ansible.builtin.file:
path: "{{ glusterfs_server_backing_dir }}"
state: directory
mode: "0755"
register: _backing_dir_create
- name: Check brick status
throttle: 1
ansible.builtin.command: gluster volume status {{ glusterfs_server_volume_name }} {{ inventory_hostname | regex_replace('_', '-') }}:{{ glusterfs_server_bricks
}} detail
register: _brick_online_status
changed_when: false
failed_when: false
# NOTE (jrosser) run this task if we just created the data dir, the volume exists (status was available)
# and the brick on this node is offline. This covers a destroy/create of an existing host
- name: Reset brick for a replaced node
vars:
brick: "{{ inventory_hostname | regex_replace('_', '-') }}:{{ glusterfs_server_bricks }}"
ansible.builtin.command: "{{ item }}"
changed_when: false
when:
- _backing_dir_create is changed
- _brick_online_status.rc == 0
- (_brick_online_status.stdout_lines | select('contains', 'Online'))[0] | regex_search('N')
with_items:
- gluster volume reset-brick {{ glusterfs_server_volume_name }} {{ brick }} start
- gluster volume reset-brick {{ glusterfs_server_volume_name }} {{ brick }} {{ brick }} commit force
- name: Handle volume creation
block:
# NOTE: When first establishing a peer relationship, a reverse DNS lookup happens which can cause a
# peer's active hostname not to match the one stored on disk. Restarting the service resolves
# this and prevents failures upon calls to create volumes.
- name: Find existing peers' runtime hostnames
ansible.builtin.shell: "gluster peer status | grep Hostname: | cut -d ' ' -f 2"
changed_when: false
register: _existing_peer_hostnames
when: (glusterfs_server_cluster_members | length) > 1
- name: Restart glusterfs server
ansible.builtin.service:
name: "{{ glusterfs_server_service }}"
state: restarted
when:
- _existing_peer_hostnames is not skipped
- ((_existing_peer_hostnames.stdout_lines | intersect(glusterfs_server_cluster_members)) | length) != (_existing_peer_hostnames.stdout_lines | length)
# Retry as the service may have just restarted
- name: Create gluster volume
vars:
num_cluster_members: "{{ glusterfs_server_cluster_members | length }}"
cluster_has_replicas: "{{ (glusterfs_server_cluster_members | length) > 1 }}"
gluster.gluster.gluster_volume:
state: present
name: "{{ glusterfs_server_volume_name }}"
bricks: "{{ glusterfs_server_bricks }}"
replicas: "{{ cluster_has_replicas | ternary(num_cluster_members, omit) }}"
cluster: "{{ glusterfs_server_cluster_members | map('regex_replace', '_', '-') | list }}"
force: true
register: _volume_create
delay: 1
retries: 5
until: _volume_create is success
when: _glusterfs_is_bootstrap_host
- name: Import glusterfs post-install tasks
ansible.builtin.import_tasks:
file: glusterfs_post_install.yml
tags:
- glusterfs-config