AnsiblePilot — Master Ansible Automation
AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.
Popular Topics
About Luca Berton
Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.
Simplify Disk Management with Ansible Quota Module — Video Tutorial
Learn how to use the Ansible quota module to automate disk space quotas for users and groups, ensuring efficient resource management.
What You'll Learn
- What Are Disk Quotas?
- Automating Quota Management with Ansible
- 1. Enable Quotas on the Filesystem
- Playbook: Manage XFS Quotas for User and Group `devops`
- Usage Instructions
- Best Practices
- Conclusion
- Related Articles
Full Tutorial Content
Managing disk usage quotas is critical for ensuring fair resource allocation in shared environments like multi-user servers or DevOps pipelines. Although Ansible doesn't have a dedicated `quota` module, it remains a powerful tool for automating disk quota management using alternative modules and techniques. In this article, we’ll explore practical ways to manage disk quotas with Ansible.
---
What Are Disk Quotas?
Disk quotas are limits set on the amount of disk space or inodes that a user or group can use on a filesystem. They are essential for:
- **Preventing Resource Hoarding**: Ensures no single user consumes excessive disk space.
- **Maintaining System Performance**: Prevents systems from becoming sluggish due to storage overuse.
- **Enforcing Compliance**: Helps adhere to organizational storage policies.
Linux provides tools like `quota` and `xfs_quota` to manage disk quotas. While Ansible lacks a specific quota module, you can leverage its capabilities to automate quota-related tasks.
---
Automating Quota Management with Ansible
1. Enable Quotas on the Filesystem
Before managing quotas, you must enable them on the target filesystem. For ext4 filesystems:
```bash
sudo mount -o remount,usrquota /dev/sda1
```
For XFS filesystems:
```bash
sudo xfs_quota -x -c "quota enable" /
```
In Ansible, you can automate this process:
```yaml
- name: Enable quotas on ext4 filesystem
hosts: all
become: true
tasks:
- name: Remount with user quota enabled
ansible.builtin.command:
cmd: mount -o remount,usrquota /
```
---
Playbook: Manage XFS Quotas for User and Group `devops`
Here’s an example playbook where both the user and group are named `devops`. It configures quotas for the user `devops` and the group `devops`.
```yaml
---
- name: Manage XFS Quotas for User and Group "devops"
hosts: all
become: true
tasks:
- name: Ensure xfsprogs is installed
ansible.builtin.package:
name: xfsprogs
state: present
- name: Configure user quotas for "devops" on /home
community.general.xfs_quota:
type: user
name: devops
mountpoint: /home
bsoft: 5G
bhard: 10G
isoft: 10000
ihard: 20000
state: present
- name: Configure group quotas for "devops" on /var/devops
community.general.xfs_quota:
type: group
name: devops
mountpoint: /var/devops
bsoft: 20G
bhard: 50G
isoft: 50000
ihard: 100000
state: present
- name: Verify quota settings
ansible.builtin.shell: xfs_quota -x -c "report -h"
register: quota_report
changed_when: false
- name: Display quota report
ansible.builtin.debug:
var: quota_report.stdout
```
---
Usage Instructions
1. **Prepare the Filesystem**:
- Ensure the target filesystems (`/home` and `/var/devops`) are mounted with XFS and quota options enabled:
```bash
sudo mount -o remount,usrquota,grp
About This Tutorial
- Author: Luca Berton
- Difficulty: Beginner
- Read time: 4 min
- Category: installation
Read the full written article: Simplify Disk Management with Ansible Quota Module
Related Video Tutorials
- Ansible extra-vars: Pass Variables via Command Line (--extra-vars Guide) — How to pass variables to Ansible playbook via command line with --extra-vars (-e). Pass strings, JSON, files, override variables.
- Ansible 2.17.0-rc1: Elevating Automation with ‘Gallows Pole’ — Ansible 2.17.0-rc1 (\"Gallows Pole\") introduces critical updates: phasing out older Python versions and tightened security measures.
- Ansible troubleshooting - Error avoid-implicit — The avoid-implicit rule in Ansible identifies and advises against implicit behaviors, promoting explicit instructions for predictable playbook execution.
- Ansible Permission Denied (Errno 13): Fix File Access Errors — Fix Ansible Permission denied [Errno 13] errors. Resolve file permission, become/sudo, SELinux, and directory access issues with troubleshooting steps.
- Ansible 'Failure Downloading' Error: Fix get_url & uri Module Issues — Fix Ansible 'failure downloading' errors with get_url and uri modules. Covers SSL certificate issues, proxy settings, timeouts, and authentication for file.
- Ansible 'fatal: template error while templating string' Fix (Guide) — Fix Ansible template error while templating string. Resolve undefined variables, syntax errors, and Jinja2 issues in playbooks and templates with examples.