volume: Support device-based volumes

Also support those options in container and service roles
This commit is contained in:
uumas
2025-07-05 16:14:07 +03:00
parent faa68bfe83
commit a862606df2
9 changed files with 123 additions and 9 deletions

View File

@@ -1,3 +1,6 @@
---
volume_uid: ""
volume_gid: ""
volume_type: ""
volume_device: ""
volume_mount_options: []

View File

@@ -0,0 +1,7 @@
---
- name: "Restart volume service {{ volume_name }}"
ansible.builtin.systemd_service:
name: "{{ volume_name }}-volume.service"
state: restarted
daemon_reload: true
ignore_errors: '{{ ansible_check_mode }}'

View File

@@ -17,3 +17,19 @@ argument_specs:
type: str
required: false
default: ""
volume_device:
description: The path of a device which is mounted for the volume.
type: str
required: false
default: ""
volume_type:
description: The filesystem type of device as used by the mount commands -t option
type: str
required: false
default: ""
volume_mount_options:
description: The mount options to use for a filesystem as used by the mount command -o option
type: list
elements: str
required: false
default: []

View File

@@ -5,7 +5,8 @@
- name: Create container volume service {{ volume_name }}
containers.podman.podman_volume:
name: "{{ volume_name }}"
options: "{{ volume_options }}"
options: "{{ _volume_options }}"
state: quadlet
quadlet_file_mode: "0644"
notify: Reload systemd daemon
quadlet_options: "{{ _volume_quadlet_options }}"
notify: Restart volume service {{ volume_name }}

View File

@@ -1,6 +1,24 @@
---
volume_mount_options_incl_empty:
_volume_mount_options_incl_empty:
- "{{ 'uid=' ~ volume_uid if volume_uid | length > 0 else '' }}"
- "{{ 'gid=' ~ volume_gid if volume_gid | length > 0 else '' }}"
volume_mount_options: "{{ volume_mount_options_incl_empty | select('!=', '') | list }}"
volume_options: "{{ ['o=' ~ volume_mount_options | join(',')] if volume_mount_options | length > 0 else [] }}"
_volume_mount_options: >-
{{
_volume_mount_options_incl_empty
| select('!=', '')
+ volume_mount_options
}}
_volume_options: >-
{{
(['o=' ~ _volume_mount_options | join(',')] if _volume_mount_options | length > 0 else [])
+ (['type=' ~ volume_type] if volume_type | length > 0 else [])
+ (['device=' ~ volume_device] if volume_device | length > 0 else [])
}}
_volume_device_quadlet_options: |
[Service]
ExecStartPost=/usr/bin/podman volume mount {{ volume_name }}
ExecStop=/usr/bin/podman volume unmount {{ volume_name }}
ExecStop=/usr/bin/podman volume rm {{ volume_name }}
_volume_quadlet_options: >-
{{ [_volume_device_quadlet_options] if volume_device | length > 0 else [] }}