Add volume role and support setting volume owner
Add volume role container: Use volume role, including support for user and group
This commit is contained in:
1
roles/volume/README.md
Normal file
1
roles/volume/README.md
Normal file
@@ -0,0 +1 @@
|
||||
Sets up podman volume with systemd unit (quadlet)
|
||||
3
roles/volume/defaults/main.yaml
Normal file
3
roles/volume/defaults/main.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
volume_uid: ""
|
||||
volume_gid: ""
|
||||
19
roles/volume/meta/argument_specs.yaml
Normal file
19
roles/volume/meta/argument_specs.yaml
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
argument_specs:
|
||||
main:
|
||||
description: Sets up podman volume with systemd unit (quadlet)
|
||||
options:
|
||||
volume_name:
|
||||
description: Name of the volume. Must be unique within a host.
|
||||
type: str
|
||||
required: true
|
||||
volume_uid:
|
||||
description: Volume uid (the volume owner)
|
||||
type: str
|
||||
required: false
|
||||
default: ""
|
||||
volume_gid:
|
||||
description: Volume gid (the volume owner)
|
||||
type: str
|
||||
required: false
|
||||
default: ""
|
||||
3
roles/volume/meta/main.yaml
Normal file
3
roles/volume/meta/main.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
dependencies:
|
||||
- role: podman
|
||||
11
roles/volume/tasks/main.yaml
Normal file
11
roles/volume/tasks/main.yaml
Normal file
@@ -0,0 +1,11 @@
|
||||
---
|
||||
- name: Validate inputs
|
||||
ansible.builtin.import_tasks: validation.yaml
|
||||
|
||||
- name: Create container volume service {{ volume_name }}
|
||||
containers.podman.podman_volume:
|
||||
name: "{{ volume_name }}"
|
||||
options: "{{ volume_options }}"
|
||||
state: quadlet
|
||||
quadlet_file_mode: "0644"
|
||||
notify: Reload systemd daemon
|
||||
7
roles/volume/tasks/validation.yaml
Normal file
7
roles/volume/tasks/validation.yaml
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
- name: Assert volume_uid and volume_gid are strings
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- volume_uid is string
|
||||
- volume_gid is string
|
||||
fail_msg: "volume_uid and volume_gid must be strings, not int."
|
||||
6
roles/volume/vars/main.yaml
Normal file
6
roles/volume/vars/main.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
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 [] }}"
|
||||
Reference in New Issue
Block a user