Troubleshooting: Configure User Quotas on XFS File Systems Using Ansible

Learn how to resolve the common error related to user quota configuration on XFS file systems with Ansible.

---

Error Summary

When attempting to configure user quotas on an XFS file system with Ansible, you might encounter the following error:

``plaintext

TASK [Configure user quotas for "devops" on /] *

fatal: [debian.example.com]: FAILED! => {"changed": false, "msg": "Path '/' is not mounted with the uquota/usrquota/quota/uqnoenforce/qnoenforce option."}

`

This error occurs because the root file system / is not mounted with the necessary options (usrquota and grpquota) required to enable quota tracking.

---

Root Cause

The XFS file system requires specific mount options (usrquota, grpquota) for quotas to function. Without these options, the kernel cannot track or enforce disk usage limits.

---

Solution: Enable Quota Support for XFS

#### 1. Verify Current Mount Options

Use the mount command to confirm the current mount options for the root file system:

`bash

mount | grep ' / '

`

Example output:

`plaintext

/dev/nvme0n1p2 on / type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)

`

#### 2. Update /etc/fstab to Add Quota Options

Edit /etc/fstab to include the usrquota and grpquota options:

`plaintext

UUID=1f46e518-142f-4d88-ae7f-cf401c9e7dd0 / xfs defaults,usrquota,grpquota 0 0

`

#### 3. Remount the File System

Apply the updated mount options by remounting the file system:

`bash

mount -o remount /

`

#### 4. Enable Quota Management

Use the xfs_quota tool to enable quotas on the file system:

`bash

xfs_quota -x -c 'quota enable' /

`

#### 5. Set User Quotas

Set specific disk usage limits for a user (e.g., devops):

`bash

xfs_quota -x -c 'limit bsoft=2G bhard=3G devops' /

`

#### 6. Verify Quota Configuration

Check the quota status for all users:

`bash

xfs_quota -x -c 'report' /

`

---

Automating the Process with Ansible

Update your Ansible playbook to automate the configuration of quotas on XFS file systems.

#### Example Playbook:

`yaml

  • name: Configure user quotas on XFS

hosts: all

become: yes

tasks:

- name: Ensure quota package is installed

apt:

name: quota

state: present

- name: Update fstab for quota support

lineinfile:

path: /etc/fstab

regexp: '^UUID=1f46e518-142f-4d88-ae7f-cf401c9e7dd0'

line: 'UUID=1f46e518-142f-4d88-ae7f-cf401c9e7dd0 / xfs defaults,usrquota,grpquota 0 0'

backrefs: yes

- name: Remount root file system with quota options

command: mount -o remount /

- name: Enable quotas

command: xfs_quota -x -c 'quota enable' /

- name: Set quota limits for devops user

command: xfs_quota -x -c 'limit bsoft=2G bhard=3G devops' /

``

---

Testing the Playbook

Run the playbook to apply the co