diff --git a/README.md b/README.md index 9cc3e8f..52eca89 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # Ansible Collection - genlab.common -Documentation for the collection. +## Roles + +- [mount_device](roles/mount_device/README.md) diff --git a/roles/.keep b/roles/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/roles/mount_device/README.md b/roles/mount_device/README.md new file mode 100644 index 0000000..ff4c994 --- /dev/null +++ b/roles/mount_device/README.md @@ -0,0 +1,45 @@ +ansible-mount-device +========= + +Mount the given block device. + +This is essentially a thin wrapper about `ansible.posix.mount` created to standardize handling mounts. + +Requirements +------------ + +None + +Role Variables +-------------- + +`devices`: a list of objects, describing which device should be mounted, and how (see below for an example) + +Dependencies +------------ + +None + +Example Playbook +---------------- + +```yaml +- role: mount_device + devices: + - what: /dev/vdb + where: "/somewhere" + fstype: ext4 + opts: + - noatime + state: mounted +``` + +License +------- + +BSD + +Author Information +------------------ + +corvus-migratorius@proton.me diff --git a/roles/mount_device/defaults/main.yml b/roles/mount_device/defaults/main.yml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/roles/mount_device/defaults/main.yml @@ -0,0 +1 @@ +--- diff --git a/roles/mount_device/handlers/main.yml b/roles/mount_device/handlers/main.yml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/roles/mount_device/handlers/main.yml @@ -0,0 +1 @@ +--- diff --git a/roles/mount_device/meta/main.yml b/roles/mount_device/meta/main.yml new file mode 100644 index 0000000..5b34d77 --- /dev/null +++ b/roles/mount_device/meta/main.yml @@ -0,0 +1,17 @@ +--- +galaxy_info: + role_name: mount_device + namespace: genlab + author: "Alexander Gorelyshev" + company: "Genlab, LLC" + description: "Mount the given device" + license: "GPL-2.0-or-later" + min_ansible_version: "2.1" + + platforms: + - name: "Ubuntu" + versions: [ "focal", "jammy", "noble" ] + + galaxy_tags: [] + +dependencies: [] diff --git a/roles/mount_device/molecule/default/converge.yml b/roles/mount_device/molecule/default/converge.yml new file mode 100644 index 0000000..af31c05 --- /dev/null +++ b/roles/mount_device/molecule/default/converge.yml @@ -0,0 +1,27 @@ +--- +- name: Converge + hosts: all + + pre_tasks: + + - name: "Check if the disk file already exists" + ansible.builtin.stat: + path: /tmp/test_file + register: disk_file + + - name: "Create a file to act as a disk if it doesn't exist" + when: not disk_file.stat.exists + changed_when: false + ansible.builtin.shell: | + dd if=/dev/zero of=/tmp/test_file bs=1000000 count=100 + mkfs.ext3 /tmp/test_file + + roles: + - role: genlab.mount_device + devices: + - what: "/tmp/test_file" + where: "/test_mount" + fstype: ext3 + opts: + - noatime + state: mounted diff --git a/roles/mount_device/molecule/default/molecule.yml b/roles/mount_device/molecule/default/molecule.yml new file mode 100644 index 0000000..d82158e --- /dev/null +++ b/roles/mount_device/molecule/default/molecule.yml @@ -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 . diff --git a/roles/mount_device/molecule/default/verify.yml b/roles/mount_device/molecule/default/verify.yml new file mode 100644 index 0000000..3538604 --- /dev/null +++ b/roles/mount_device/molecule/default/verify.yml @@ -0,0 +1,18 @@ +--- +- name: Verify + hosts: all + gather_facts: false + any_errors_fatal: true + + tasks: + - name: "Check mountpoint" # noqa: command-instead-of-module + changed_when: false + register: mounts + ansible.builtin.command: + cmd: mount -l + + - name: "Ensure test_file is mounted on test_mount" + ansible.builtin.assert: + that: "'/tmp/test_file on /test_mount type ext3' in mounts.stdout" + success_msg: "/test_mount is a mounted" + fail_msg: "/test_mount is not on the list of mounts" diff --git a/roles/mount_device/requirements.yml b/roles/mount_device/requirements.yml new file mode 100644 index 0000000..3d5f1cd --- /dev/null +++ b/roles/mount_device/requirements.yml @@ -0,0 +1,3 @@ +# requirements file +--- +collections: [] diff --git a/roles/mount_device/tasks/main.yml b/roles/mount_device/tasks/main.yml new file mode 100644 index 0000000..ffd5ebf --- /dev/null +++ b/roles/mount_device/tasks/main.yml @@ -0,0 +1,9 @@ +--- +- name: "Mount devices" + with_items: "{{ devices }}" + ansible.posix.mount: + fstype: "{{ item.fstype }}" + path: "{{ item.where }}" + src: "{{ item.what }}" + opts: "{{ item.opts | join(',') }}" + state: "{{ item.state }}" diff --git a/roles/mount_device/vars/main.yml b/roles/mount_device/vars/main.yml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/roles/mount_device/vars/main.yml @@ -0,0 +1 @@ +---