What Do You Do when an Ansible Playbook Is Not Removing a File or Directory or Unmounting a Directory when There Are No Errors?

Problem scenario
You run a playbook, and there are no errors.  But the playbook's simple logic is not working.  The file or directory is not being eliminated.  Or the unmount of the directory is not working via the mount module.  What should you do about a silently failing playbook?

Solution
1.  Verify there are no [trailing] spaces in the directory path.  If you accidentally quote a space after the last subdirectory or file, the playbook may not work but there may be no errors alerting you that it did not work.

2.  Verify the path in the playbook, i.e., that of a variable, is what you think it is.  Try to "echo" the value to a /tmp/ file to verify it is being computed and substituted consistent with what you expect.  You will have to run the playbook once purely for diagnostic purposes.

3.  Verify the playbook does not later recreate the file or mount the file/directory near the end of the playbook.  It may be that it does what you want, but near the end it independently reverts some of the deletion or unmounting.

4.  The Ansible modules are preferred to the shell commands.  If the error is difficult to troubleshoot, try the shell commands in addition to the Ansible modules.  The "ignore_errors: yes" is an attribute that can help out if the shell commands are prone to errors.  

5.  Verify the key part of the Ansible playbook is not commented out.  Maybe you need to uncomment a relevant stanza or variable assignment.

6.  It could be the root cause is purely for a Linux-related reason (if the managed node is Linux).  If you are using the mount module check the /etc/fstab or /etc/exports.  These files could be configured in a conflicting way with the playbook's operation such that there is no error, but your playbook is not doing what you want.  We do think that if the destination directory of the mount module does not work, Ansible ought to throw an error.  At the time of writing, we believe most (or all) Ansible versions will not throw an error.

7. For a guide to troubleshooting a generic Ansible playbook with no errors that is not working correctly, see this posting.

Leave a comment

Your email address will not be published. Required fields are marked *