Ansible - Resolve "The ipaddr filter requires python's netaddr be installed on the ansible controller"
by
Jeremy Canfield |
Updated: November 15 2023
| Ansible articles
Let's say something like this is being returned.
fatal: [server1.example.com]: FAILED! => {"msg": "The ipaddr filter requires python's netaddr be installed on the ansible controller"}
My Ansible playbook included ansible.utils.ipaddr.
---
- hosts: all
tasks:
- name: create the empty all_ipv4_addresses_with_prefix list
set_fact:
all_ipv4_addresses_with_prefix: []
- name: append default IPv4 address/prefix to the 'all_ipv4_addresses_with_prefix' list
set_fact:
all_ipv4_addresses_with_prefix: "{{ all_ipv4_addresses_before_leapping + [(ansible_eth0.ipv4.address + '/' + ansible_eth0.ipv4.netmask) | ansible.utils.ipaddr('network/prefix')] }}"
...
I was running my Ansible playbook in a Python virtual environment that did not include the netaddr package.
~]$ python3.10.2_virtual_env/bin/python3.10 -m pip list
Package Version
------------ -------
ansible-core 2.16.0
cffi 1.16.0
cryptography 41.0.5
Jinja2 3.1.2
MarkupSafe 2.1.3
packaging 23.2
pip 23.3.1
pycparser 2.21
PyYAML 6.0.1
resolvelib 1.0.1
setuptools 58.1.0
wheel 0.41.3
I installed the netaddr package in my Python virtual environment.
~]$ python3.10.2_virtual_env/bin/python3.10 -m pip install netaddr
Installing collected packages: netaddr
Successfully installed netaddr-0.9.0
Validated my Python virtual environment contained the netaddr package, re-ran my Ansible playbook and no longer got the error.
~]$ python3.10.2_virtual_env/bin/python3.10 -m pip list
Package Version
------------ -------
ansible-core 2.16.0
cffi 1.16.0
cryptography 41.0.5
Jinja2 3.1.2
MarkupSafe 2.1.3
netaddr 0.9.0
packaging 23.2
pip 23.3.1
pycparser 2.21
PyYAML 6.0.1
resolvelib 1.0.1
setuptools 58.1.0
wheel 0.41.3
Did you find this article helpful?
If so, consider buying me a coffee over at