Ansible role for managing disks on linux hosts
Role configuration:
-
disksname[required] used to identify the disk id (eg. if disk id is 'google-disk-2' then we can use 'disk-2' as name)mount[required] mount locationstate[required] disk state. Values: [ 'present', 'absent' ]disk[optional] identify the disk to be managed by attached device instead of namename(eg. sdb, sdc, nvme1n2, nvme1n2, ... )unit[optional] default unit used by parted command ( defaults to 'KiB' )fstype[optional] file system type (defaults to 'ext4'). Values: [ 'aix', 'amiga', 'bsd', 'dvh', 'gpt', 'loop', 'mac', 'msdos', 'pc98', 'sun' ]force[optional] force creation of new filesystem on devices that already has filesystem (defaults to false)resizefs[optional] if size differ, grow the filesystem into the space (defaults to true)fsopts[optional] list of options for mkfsdisable_periodic_fsck[optional] enable periodic fsck check (defaults to false)user[optional] Owner of the mount location (defaults to 'root')group[optional] Group owner of the mount location (defaults to 'root')mount_state[optional] mount state (defaults to the same value asstate). Values: [ 'absent', 'mounted', 'present', 'unmounted' ]mount_options[optional] mount options (defaults to 'defaults,nofail')mount_mode[optional] mount mode (defaults to 'by-id'). Values: [ 'by-id', 'uuid' ]
Create requirements file requirements.yml
---
- name: disks
src: https://github.com/tinslice/ansible-role-disks.gitInstall role
ansible-galaxy install -f -r requirements.yml -p roles/Create playbook file playbook.yml
---
- hosts: "{{ target_host }}"
vars:
disks:
- name: mydisk
mount: /mnt/diskmount
state: present
fstype: ext4
resizefs: true
mount_state: mounted
mount_options: defaults,nofail
become: yes
roles:
- disksRun playbook
ansible-playbook playbook.yml -i <inventory> -e target_host=<target-host>Resources: