Merge pull request #12 from corvus-migratorius/role-mkfs

Migrate the `genlab.mkfs` role
This commit is contained in:
Fogucoco
2025-12-18 10:45:15 +03:00
committed by GitHub
12 changed files with 148 additions and 4 deletions

View File

@@ -13,6 +13,7 @@
- [ipmi_exporter](roles/ipmi_exporter/README.md)
- [karma](roles/karma/README.md)
- [loki](roles/loki/README.md)
- [mkfs](roles/mkfs/README.md)
- [mount_device](roles/mount_device/README.md)
- [nginx](roles/nginx/README.md)
- [node_exporter](roles/node_exporter/README.md)

View File

@@ -1,7 +1,7 @@
---
namespace: genlab
name: common
version: 0.20.0
version: 0.21.0
readme: README.md
authors:
- Alexander Gorelyshev (corvus-migratorius@proton.me)

40
roles/mkfs/README.md Normal file
View File

@@ -0,0 +1,40 @@
Role Name
=========
Create a filesystem on the target device (thinly wraps `community.general.filesystem` module).
Requirements
------------
Uses specific tools related to the fstype for creating or resizing a filesystem (`e2fsprogs`, `xfsprogs`, etc.).
Uses generic tools mostly related to the OS, like `blkid`.
Role Variables
--------------
- `mkfs_device`: (string) device that the filesystem should be created on
- `mkfs_type`: (string) type of the filesystem to be created
- `mkfs_opts`: (string) a list of options to be passed to `mkfs` (*not* a YAML array)
- `mkfs_state`: (string) `absent` or `present`
- `mkfs_force`: (boolean) overwrite an existing fs if there is one (default: `false`)
Dependencies
------------
None
Example Playbook
----------------
See: [converge.yml](molecule/default/converge.yml)
License
-------
BSD
Author Information
------------------
corvus-migratorius@proton.me

View File

@@ -0,0 +1,5 @@
---
# defaults file for mkfs
mkfs_opts: ""
mkfs_state: present
mkfs_force: false

View File

@@ -0,0 +1 @@
---

17
roles/mkfs/meta/main.yml Normal file
View File

@@ -0,0 +1,17 @@
---
galaxy_info:
role_name: "mkfs"
author: "Alexander Gorelyshev"
company: "Genlab, LLC"
namespace: genlab
description: "Create a filesystem on a target device"
license: "GPL-2.0-or-later"
min_ansible_version: "2.1"
platforms:
- name: "Ubuntu"
versions: ["jammy", "noble"]
galaxy_tags: []
dependencies: []

View File

@@ -0,0 +1,22 @@
---
- name: Converge
hosts: all
pre_tasks:
- name: "Check if the disk file already exists"
ansible.builtin.stat:
path: /tmp/test_file
register: mkfs_disk_file
- name: "Create a file to act as a disk if it doesn't exist"
ansible.builtin.command: dd if=/dev/zero of=/tmp/test_file bs=1000000 count=100
when: not mkfs_disk_file.stat.exists
register: mkfs_dd_output
changed_when: mkfs_dd_output.rc != 0
roles:
- role: genlab.common.mkfs
mkfs_device: "/tmp/test_file"
mkfs_type: ext3
mkfs_state: present

View File

@@ -0,0 +1,27 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: ubuntu
image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2404}-ansible:latest
pre_build_image: true
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
provisioner:
name: ansible
verifier:
name: ansible
lint: |
set -e
yamllint .
ansible-lint .

View File

@@ -0,0 +1,25 @@
---
- name: Verify
hosts: all
gather_facts: false
any_errors_fatal: true
tasks:
- name: "Attach the file to a loop device"
ansible.builtin.command: losetup /dev/loop3 /tmp/test_file
register: mkfs_loop_device
changed_when: mkfs_loop_device.rc != 0
- name: "Verify the filesystem type"
ansible.builtin.command: blkid /dev/loop3
register: mkfs_blkid_output
changed_when: mkfs_blkid_output.rc != 0
- name: "Ensure filesystem is ext3"
ansible.builtin.assert:
that:
- "'TYPE=\"ext3\"' in mkfs_blkid_output.stdout"
- name: "Explore stdout"
ansible.builtin.debug:
var: mkfs_blkid_output.stdout

View File

@@ -0,0 +1,8 @@
---
- name: "Create a filesystem on the given device"
community.general.filesystem:
fstype: "{{ mkfs_type }}"
dev: "{{ mkfs_device }}"
state: "{{ mkfs_state }}"
opts: "{{ mkfs_opts }}"
force: "{{ mkfs_force }}"

1
roles/mkfs/vars/main.yml Normal file
View File

@@ -0,0 +1 @@
---

View File

@@ -1,3 +0,0 @@
# requirements file
---
collections: []