ipaddr filter doesn't work in virtuelenv

Hey Folks,

I’ve been forwarded to this maillist from the bug tracker. Here is the problem - https://github.com/ansible/ansible/issues/49139

The filter ipaddr doesn’t seem to work properly if installed in the same playbook:

Tasks:

`
- pip:
    state: latest
    name: netaddr

- debug:
    msg: "{{ '192.168.10.0/24' | ipaddr('-1') }}"

`

Logs:

ansible-playbook 2.5.2
  config file = /Users/jack/git/test/ansible.cfg
  configured module search path = [u'/Users/jack/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/jack/git/test/env/lib/python2.7/site-packages/ansible
  executable location = /Users/jack/git/test/env/bin/ansible-playbook
  python version = 2.7.15 (default, Jul 23 2018, 21:27:06) [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)]
Using /Users/jack/git/test/ansible.cfg as config file
setting up inventory plugins
Set default localhost to localhost
Parsed /Users/jack/git/test/inventory inventory source with ini plugin
Loading callback plugin default of type stdout, v2.0 from /Users/jack/git/test/env/lib/python2.7/site-packages/ansible/plugins/callback/default.pyc

PLAYBOOK: test.yml ******************************************************************************************************************************************************************
1 plays in test.yml

PLAY [localhost] ********************************************************************************************************************************************************************
META: ran handlers

TASK [pip] **************************************************************************************************************************************************************************
task path: /Users/jack/git/test/test.yml:6
Using module file /Users/jack/git/test/env/lib/python2.7/site-packages/ansible/modules/packaging/language/pip.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: jack
<localhost> EXEC /bin/sh -c 'echo ~ && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/jack/.ansible/tmp/ansible-tmp-1543309702.88-83569388017787 `" && echo ansible-tmp-1543309702.88-83569388017787="` echo /Users/jack/.ansible/tmp/ansible-tmp-1543309702.88-83569388017787 `" ) && sleep 0'
<localhost> PUT /Users/jack/.ansible/tmp/ansible-local-81317WNDcgg/tmpCYMmdF TO /Users/jack/.ansible/tmp/ansible-tmp-1543309702.88-83569388017787/pip.py
<localhost> EXEC /bin/sh -c 'chmod u+x /Users/jack/.ansible/tmp/ansible-tmp-1543309702.88-83569388017787/ /Users/jack/.ansible/tmp/ansible-tmp-1543309702.88-83569388017787/pip.py && sleep 0'
<localhost> EXEC /bin/sh -c '/tmp/netaddr/bin/python /Users/jack/.ansible/tmp/ansible-tmp-1543309702.88-83569388017787/pip.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /Users/jack/.ansible/tmp/ansible-tmp-1543309702.88-83569388017787/ > /dev/null 2>&1 && sleep 0'
changed: [localhost] => {
    "changed": true,
    "cmd": "/Users/jack/git/test/env/bin/pip2 install -U netaddr",
    "invocation": {
        "module_args": {
            "chdir": null,
            "editable": false,
            "executable": null,
            "extra_args": null,
            "name": [
                "netaddr"
            ],
            "requirements": null,
            "state": "latest",
            "umask": null,
            "use_mirrors": true,
            "version": null,
            "virtualenv": null,
            "virtualenv_command": "virtualenv",
            "virtualenv_python": null,
            "virtualenv_site_packages": false
        }
    },
    "name": [
        "netaddr"
    ],
    "requirements": null,
    "state": "latest",
    "stderr": "",
    "stderr_lines": [],
    "stdout": "Collecting netaddr\n  Using cached https://files.pythonhosted.org/packages/ba/97/ce14451a9fd7bdb5a397abf99b24a1a6bb7a1a440b019bebd2e9a0dbec74/netaddr-0.7.19-py2.py3-none-any.whl\nInstalling collected packages: netaddr\nSuccessfully installed netaddr-0.7.19\n",
    "stdout_lines": [
        "Collecting netaddr",
        "  Using cached https://files.pythonhosted.org/packages/ba/97/ce14451a9fd7bdb5a397abf99b24a1a6bb7a1a440b019bebd2e9a0dbec74/netaddr-0.7.19-py2.py3-none-any.whl",
        "Installing collected packages: netaddr",
        "Successfully installed netaddr-0.7.19"
    ],
    "version": null,
    "virtualenv": null
}

TASK [debug] ************************************************************************************************************************************************************************
task path: /Users/jack/git/test/test.yml:10
fatal: [localhost]: FAILED! => {
    "msg": "The ipaddr filter requires python-netaddr be installed on the ansible controller"
}
...ignoring

TASK [shell] ************************************************************************************************************************************************************************
task path: /Users/jack/git/test/test.yml:14
Using module file /Users/jack/git/test/env/lib/python2.7/site-packages/ansible/modules/commands/command.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: jack
<localhost> EXEC /bin/sh -c 'echo ~ && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/jack/.ansible/tmp/ansible-tmp-1543309704.89-167371142501930 `" && echo ansible-tmp-1543309704.89-167371142501930="` echo /Users/jack/.ansible/tmp/ansible-tmp-1543309704.89-167371142501930 `" ) && sleep 0'
<localhost> PUT /Users/jack/.ansible/tmp/ansible-local-81317WNDcgg/tmpgmUfX5 TO /Users/jack/.ansible/tmp/ansible-tmp-1543309704.89-167371142501930/command.py
<localhost> EXEC /bin/sh -c 'chmod u+x /Users/jack/.ansible/tmp/ansible-tmp-1543309704.89-167371142501930/ /Users/jack/.ansible/tmp/ansible-tmp-1543309704.89-167371142501930/command.py && sleep 0'
<localhost> EXEC /bin/sh -c '/tmp/netaddr/bin/python /Users/jack/.ansible/tmp/ansible-tmp-1543309704.89-167371142501930/command.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /Users/jack/.ansible/tmp/ansible-tmp-1543309704.89-167371142501930/ > /dev/null 2>&1 && sleep 0'
changed: [localhost] => {
    "changed": true,
    "cmd": "pip freeze",
    "delta": "0:00:00.417166",
    "end": "2018-11-27 10:08:25.510300",
    "invocation": {
        "module_args": {
            "_raw_params": "pip freeze",
            "_uses_shell": true,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "warn": true
        }
    },
    "rc": 0,
    "start": "2018-11-27 10:08:25.093134",
    "stderr": "",
    "stderr_lines": [],
    "stdout": "ansible==2.5.2\nasn1crypto==0.24.0\nbcrypt==3.1.4\ncffi==1.11.5\ncryptography==2.4.2\nenum34==1.1.6\nidna==2.7\nipaddress==1.0.22\nJinja2==2.8\nMarkupSafe==1.1.0\nnetaddr==0.7.19\nparamiko==2.4.2\npyasn1==0.4.4\npycparser==2.19\nPyNaCl==1.3.0\nPyYAML==3.13\nsix==1.11.0\nvirtualenv==16.1.0",
    "stdout_lines": [
        "ansible==2.5.2",
        "asn1crypto==0.24.0",
        "bcrypt==3.1.4",
        "cffi==1.11.5",
        "cryptography==2.4.2",
        "enum34==1.1.6",
        "idna==2.7",
        "ipaddress==1.0.22",
        "Jinja2==2.8",
        "MarkupSafe==1.1.0",
        "netaddr==0.7.19",
        "paramiko==2.4.2",
        "pyasn1==0.4.4",
        "pycparser==2.19",
        "PyNaCl==1.3.0",
        "PyYAML==3.13",
        "six==1.11.0",
        "virtualenv==16.1.0"
    ]
}
META: ran handlers
META: ran handlers

PLAY RECAP **************************************************************************************************************************************************************************
localhost                  : ok=3    changed=2    unreachable=0    failed=0

Any workaround for this?

Thanks!