Interview Prep/Ansible/Modules, Idempotency and Handlers

`file: path=/var/www state=directory owner=www-data recurse=true` takes minutes and shows `changed`

IntermediateTroubleshootingModules, Idempotency and Handlers
Answer

Likely causes → recurse: true walks every file under the directory. On large trees (uploads, node_modules) this is slow, and any file the application created with a different owner is reported as changed.

Fix → Set ownership on the top-level directory only, and let the application create files with the right user (umask, a systemd User=). If a one-off recursive fix is needed, run it once behind a flag instead of on every run.

Prevent → Avoid recurse: true in roles that run regularly. Deploy release directories that already have the correct ownership.

All Ansible questions Roadmap: Ansible

More on Modules, Idempotency and Handlers