Generating the xfs /etc/projects file

I want to apply xfs projects in a server-specific way and need to setup the xfs /etc/projects file before I can use the community.general.xfs_quota module.

I have on each server an xfs mountpoint with a folder structure like this:

/mountpoint/projects/$PROJECTNAME/crashdumps

I want to create 1 shared XFS quota for all these folders with e.g. id 1000.

With a shell script this is easy enough:

pushd /;
for x in /mountpoint/projects/*/crashdumps; do
 echo 1000:$x;
done|sort > /etc/projects ;
popd

But can I do this with ansible, in a way that the task is only marked changed when the /etc/projects file is actually changed?

To be clear: Ansible should look at the existing folder structure. I prefer not to maintain a per server /etc/projects file or list of folders.

I found a solution. I can run the script inside an ansible shell task with changed_when: false, and dump the generated file in a variable. Then a copy with content:“{{variable}}” will either d nothing or modify the file and mark the script as changed.

You might consider taking the md5sum of the file at the start of the script, and again at the end. If they differ, then emit a unique testable string. Register the result, and mark the shell task changed_when: that string exists in your registered stdout.

1 Like