bash script not writing to file with ansible, but does locally

I have a bash script ( I know, it’s a bit sloppy):

`

#!/bin/sh

df -h >> mongo-rebuild-validate.log 2>&1

/opt/mongodb/bin/mongo localhost:27017 /opt/mongodb/mongodb-create-visionnode.js >> mongo-rebuild-validate.log 2>&1

/opt/mongodb/bin/mongoimport --host 127.0.0.1 --db visionnode --collection ftpUser --file /opt/mongodb/ftpUserJSON-Linux.js >> mongo-rebuild-validate.log 2>&1

df -h >> mongo-rebuild-validate.log 2>&1

`

on remotes servers that works fine, does what I designed it to do, including writing all the stdout and stderr to the intended log.

However, when try to run this script remotely using:

`

Since your script doesn’t specify an absolute path for the output, I suspect it’s writing it to the Ansible module tempdir, which is being promptly deleted as soon as the task finished. Try adding a chdir=/some/permanent/path to the end of the command task to run the script from a non-ephemeral location.

That was it, once I set an absolute path to the log, it worked. Thanks Matt!