Allow to define only overrides for mounts

In case some mounts are present for systems out of the box, it
might be still important to apply overrides for it, like custom options.

For that we add new `mount_overrides_only` key to `systemd_mounts`
mapping, alike to how it is already done for networkd and serviced.

Change-Id: Ib421508cd76147cb314a579a2b4e918604cf3652
Signed-off-by: Dmitriy Rabotyagov <dmitriy.rabotyagov@cleura.com>
This commit is contained in:
Dmitriy Rabotyagov
2025-06-05 20:08:53 +02:00
parent 1e170dfa1b
commit feb10e7629
6 changed files with 67 additions and 2 deletions

View File

@@ -70,5 +70,11 @@ systemd_default_mount_options: "defaults"
# - what: gluster-server:gluster-volume-name
# where: /mnt/shared_storage
# type: glusterfs
# - what: dev-hugepages
# mount_overrides_only: true
# type: hugetlbfs
# escape_name: false
# config_overrides:
# Mount:
# Options: pagesize=2MB
systemd_mounts: []

View File

@@ -0,0 +1,7 @@
---
features:
- |
For ``systemd_mount`` role added ``mount_overrides_only`` to
``systemd_mounts`` mapping. This key is desinged to apply systemd
overrides for already existing mounts, which are not managed by
the role directly.

View File

@@ -66,9 +66,35 @@
config_type: "ini"
when:
- item.state | default('unknown') != 'absent'
- (item.mount_overrides_only is not defined) or (item.mount_overrides_only is defined and not item.mount_overrides_only)
tags:
- systemd-mount
- name: Provision mount overrides file
when:
- item.mount_overrides_only is defined
- item.mount_overrides_only | bool
- item.config_overrides | length > 0
tags:
- systemd-mount
block:
- name: Create overrides folder for mount
ansible.builtin.file:
path: "/etc/systemd/system/{{ mount_service_name }}.d"
owner: "root"
group: "root"
mode: "0755"
state: directory
- name: Create overrides file
openstack.config_template.config_template:
dest: "/etc/systemd/system/{{ mount_service_name }}.d/overrides.conf"
owner: "root"
group: "root"
mode: "0644"
config_overrides: "{{ item.config_overrides | default({}) }}"
config_type: "ini"
- name: Load or Unload mount(s)
ansible.builtin.systemd:
daemon_reload: true

View File

@@ -21,3 +21,11 @@
- name: Importing test-create-ext4-dev
ansible.builtin.import_playbook: test-create-ext4-dev.yml
- name: Unmask dev-hugepages mount
hosts: mount_hosts
tasks:
- name: Unmask hugepages
ansible.builtin.systemd:
name: dev-hugepages.mount
masked: false

View File

@@ -51,3 +51,11 @@
? network.target
? network-online.target
Wants: network-online.target
- what: dev-hugepages
mount_overrides_only: true
type: hugetlbfs
escape_name: false
config_overrides:
Mount:
Options: pagesize=2MB

View File

@@ -17,7 +17,7 @@
hosts: mount_hosts
tasks:
- name: Ensure mount are mounted
command: grep -w '{{ item }}' /proc/mounts
ansible.builtin.command: grep -w '{{ item }}' /proc/mounts
changed_when: false
with_items:
- /var/lib/sparse-file
@@ -29,3 +29,13 @@
# shell: swapon | grep -w '/var/lib/test-swap.img'
# tags:
# - skip_ansible_lint
- name: Fetch override files for hugepages
ansible.builtin.slurp:
src: /etc/systemd/system/dev-hugepages.mount.d/overrides.conf
register: hugepages_overrides
- name: Verify hugepages overrides
ansible.builtin.assert:
that:
- "'pagesize=2MB' in hugepages_overrides.content | b64decode"