All actions with the pip module (other than creating the venv) apply to the user context and not the venv on a Mac. The details below are for the pip module. Running the commands when logged into the system works as expected and using those commands with both the command and shell modules results in the same outcome as the pip module. There’s something different about the way it’s being interpreted through Ansible. The same role works fine in Linux. Have tried this on 2 different Macs, both running Catalina.
$ ansible --version
ansible [core 2.11.6] config file = None configured module search path = [‘/Users/spitzer/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’] ansible python module location = /Users/spitzer/.virtualenvs/ansible460/lib/python3.8/site-packages/ansible ansible collection location = /Users/spitzer/.ansible/collections:/usr/share/ansible/collections executable location = /Users/spitzer/.virtualenvs/ansible460/bin/ansible python version = 3.8.12 (default, Sep 1 2021, 07:26:09) [Clang 11.0.3 (clang-1103.0.32.62)] jinja version = 3.0.1 libyaml = True
So, a minimal role to duplicate this is: