Skip to content

Commit

Permalink
feat: Add mount role (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
konradasb authored Jun 21, 2024
1 parent 50032a4 commit 6a6c385
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 0 deletions.
27 changes: 27 additions & 0 deletions roles/mount/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# mount

Ansible role for configuring and mounting local filesystems.

## Requirements

None.

## Dependencies

None.

## Role Variables

Refer to [defaults/main.yml](defaults/main.yml) for a list of variables along with documentation.

## Example Playbook

```yaml
- hosts: all
roles:
- role: hostinger.common.mount
```
## License
See [LICENSE](../../LICENSE)
20 changes: 20 additions & 0 deletions roles/mount/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
mount_default_mode: "0750"
mount_default_owner: root
mount_default_group: root
mount_mountpoints: []
# mount_mountpoints:
# - path: /home/example
# src: /dev/sda1
# fstype: ext4
# fsopts: ""
# opts: defaults
# boot: true
# mode: "0755"
# state: mounted
# passno: 2
# backup: true
# fstab: ""
# owner: root
# group: root
# dump: 0
19 changes: 19 additions & 0 deletions roles/mount/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
galaxy_info:
role_name: mount
author: hostinger
description: Ansible role for configuring and mounting local filesystems.
license: license (MIT)
min_ansible_version: "2.10"
platforms:
- name: Fedora
versions:
- all
- name: Debian
versions:
- all
- name: Ubuntu
versions:
- all
galaxy_tags:
- mount
7 changes: 7 additions & 0 deletions roles/mount/molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Converge
hosts:
- all

roles:
- mount
19 changes: 19 additions & 0 deletions roles/mount/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: default
image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2204}-ansible:latest
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
command: ${MOLECULE_DOCKER_COMMAND:-""}
cgroupns_mode: host
pre_build_image: true
privileged: true
platform: amd64
provisioner:
name: ansible
playbooks:
converge: ${MOLECULE_PLAYBOOK:-converge.yml}
35 changes: 35 additions & 0 deletions roles/mount/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
- name: Create mountpoints
ansible.builtin.file:
path: "{{ item.path }}"
state: directory
mode: "{{ item.mode | default(mount_default_mode) }}"
owner: "{{ item.owner | default(mount_default_owner) }}"
group: "{{ item.group | default(mount_default_group) }}"
with_items:
- "{{ mount_mountpoints }}"
when:
- item.fstype != "swap"

- name: Create file systems
community.general.filesystem:
device: "{{ item.src }}"
type: "{{ item.fstype }}"
opts: "{{ item.fsopts | default(omit) }}"
with_items:
- "{{ mount_mountpoints }}"

- name: Mount mountpoints
ansible.posix.mount:
path: "{{ item.path }}"
backup: "{{ item.backup | default(omit) }}"
boot: "{{ item.boot | default(omit) }}"
dump: "{{ item.dump | default(omit) }}"
fstab: "{{ item.fstab | default(omit) }}"
fstype: "{{ item.fstype | default(omit) }}"
opts: "{{ item.opts | default(omit) }}"
passno: "{{ item.passno | default(omit) }}"
src: "{{ item.src | default(omit) }}"
state: "{{ item.state | default('mounted') }}"
with_items:
- "{{ mount_mountpoints }}"

0 comments on commit 6a6c385

Please sign in to comment.