Ansible: The ipaddr filter requires python's netaddr be installed on the ansible controller

Question:

Docker container Alpine.3.13.1
apk add ansible succeeds however, executing playbooks that require ipaddr filter fails with:

Ansible: The ipaddr filter requires python's netaddr be installed on the ansible controller

Ansible version: 2.10.5 (can do other versions if needed)
ipaddr filter: Ansible docs

Tried installing it via ansible-galaxy collection install ansible.netcommon, pip install netaddr. Still receiving the same error.

Asked By: Elia

||

Answers:

you need to install it first with:

apk add py-netaddr
Answered By: LinPy

To anyone that’s installed the netaddr package but still facing this issue, there’s an issue that occurs when you’ve changed the default python instance over the lifecycle of the Ansible controller setup.

You have to check which python install your Ansible setup is using. On at least some installs it hard-codes the python binary it uses into /home/user/.local/bin/<ansible script> and as a result it does not remain synced to your default Python installation if you ever change it.

Solution, with script at the end to automate it all:

(from /home/user/.local/bin/ansible )

I had to change…

#!/home/user/miniconda3/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
<snip>

to:

#!/home/user/anaconda3/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
<snip>

Then it started working.

Here’s a sed command (mind that you have to add the python3 path yourself – you can find your default one with which python3) to automate all of the above for all the ansible scripts, or more accurately preview changes:

sed -s '1 s|^#!.*$|#!<new path to python3>|' ~/.local/bin/ansible*

Once you’ve ran the above and it looks OK, just add -i as a flag to sed ( like sed -i -s ) and it’ll replace them all in-place and you should be good to go.

Answered By: Samuel Anttila

I encountered this problem when running the
install_nextcloud role from Ansible Galaxy.

TASK [aalaesar.install_nextcloud : [APACHE] -  generate Nextcloud configuration for apache]
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleFilterError: 
The ipwrap filter requires python's netaddr be installed on the ansible controller

Installing the netaddr module of Python3 solved the problem.

apt install python3-netaddr
Answered By: MaxiReglisse