Getting failed to execute: ansible.legacy.setup

Running ansible version 2.10.4 with Python 3.6.8 gives the following error:

fatal: [server001.example.ca]: FAILED! => {“ansible_facts”: {}, “changed”: false, “failed_modules”: {“ansible.legacy.setup”: {“ansible_facts”: {“discovered_interpreter_python”: “/usr/bin/python”}, “failed”: true, “module_stderr”: “Shared connection to server001.example.ca closed.\r\n”, “module_stdout”: “\r\nMOTD Message\r\n\r\n\r\n”, “msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”, “rc”: 1}}, “msg”: “The following modules failed to execute: ansible.legacy.setup\n”}

The target server is RHEL 7.9 with with python 2.7.

Please help.

For anyone having this issue, here is the solution.
The reason it was throwing that error was that the target server was using dzdo instead of sudo. Changing
become_method = su to become_method = dzdo in ansible.cfg fixed the issue.