##### SUMMARY
See https://github.com/ansible/ansible/blob/88d8cf8197c53edd3bcdcd21429eb4c2bfbf0f6a/lib/ansible/module_utils/basic.py#L699-L706

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
lib/ansible/module_utils/basic.py

##### ANSIBLE VERSION
```paste below
2.9
devel
```

break
            cmd.stdout.close()
            cmd.stderr.close()
            rc = cmd.returncode
        except (OSError, IOError) as e:
            self.log("Error Executing CMD:%s Exception:%s" % (self._clean_args(args), to_native(e)))
            self.fail_json(rc=e.errno, msg=to_native(e), cmd=self._clean_args(args))
        except Exception as e:
            self.log("Error Executing CMD:%s Exception:%s" % (self._clean_args(args), to_native(traceback.format_exc())))
            self.fail_json(rc=257, msg=to_native(e), exception=traceback.format_exc(), cmd=self._clean_args(args))
        
        for key, val in old_env_vals.items():
            if val is None:
                del os.environ[key]
            else:
                os.environ[key] = val
        if old_umask:
            os.umask(old_umask)
        if rc != 0 and check_rc:
            msg = heuristic_log_sanitize(stderr.rstrip(), self.no_log_values)
            self.fail_json(cmd=self._clean_args(args), rc=rc, stdout=stdout, stderr=stderr, msg=msg)
        
        os.chdir(prev_dir)
        if encoding is not None:
            return (rc, to_native(stdout, encoding=encoding, errors=errors),
                    to_native(stderr, encoding=encoding, errors=errors))
        return (rc, stdout, stderr)
    def append_to_file(self, filename, str):