Files
openstack-ansible/tests/roles/bootstrap-host/tasks/prepare_nfs.yml
Dmitriy Rabotyagov 466df7ade3 [aio] Refactor loopback preparation
Current implementation of loopback preparation has quite significant
overhead, as we are calling exact same roles multiple times in order
to provision all required loopback devices. Moreover, we duplicate
code and logic needed for their provisionment, despite we have
pretty much 2 usecase - either add sparse file as LVM or format
and directly mount with systemd.

Proposed patch unifies approach by generating a variable with
required keys/parameters to create all required devices at once.

This should reduce overhead caused by multiple role imports/includes.
as each time role tries to install packages and verifies dependencies.

Change-Id: I419fdcfa2cfac5b636f817b1d6bdd82b7198e6be
Signed-off-by: Dmitriy Rabotyagov <dmitriy.rabotyagov@cleura.com>
2025-09-22 14:12:32 +00:00

75 lines
1.9 KiB
YAML

---
# Copyright 2021, City Network International AB
#
# 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: Install NFS packages
ansible.builtin.package:
name: "{{ nfs_package }}"
state: present
- name: Create the system group for nfs
ansible.builtin.group:
name: "nfs-user"
gid: "10000"
state: "present"
system: "yes"
- name: Create the system user for nfs
ansible.builtin.user:
name: "nfs-user"
uid: "10000"
group: "nfs-user"
comment: "nfs-user"
shell: "/bin/false"
system: "yes"
createhome: "yes"
home: "/srv/nfs"
- name: Create base directories
ansible.builtin.file:
path: "{{ item }}"
state: "directory"
owner: "nfs-user"
group: "nfs-user"
mode: "0755"
with_items:
- "/srv/nfs/glance"
- "/srv/nfs/cinder"
- name: Create exports file
ansible.builtin.lineinfile:
path: /etc/exports
line: '{{ item }} {{ storage_network }}(rw,sync,no_subtree_check,insecure,all_squash,anonuid=10000,anongid=10000)'
owner: root
group: root
mode: "0644"
create: true
with_items:
- "/srv/nfs/glance"
- "/srv/nfs/cinder"
register: nfs_exportfs
- name: Restart nfs-server # noqa: no-handler
ansible.builtin.systemd:
daemon_reload: true
name: "nfs-server"
enabled: true
state: "restarted"
when:
- nfs_exportfs is changed
- name: Export NFS
ansible.builtin.command: exportfs -rav
changed_when: false