Skip to content

Instantly share code, notes, and snippets.

@Ruchip16
Last active July 18, 2025 07:59
Show Gist options
  • Save Ruchip16/ebb8ae43d14699de86f1245ad858764d to your computer and use it in GitHub Desktop.
Save Ruchip16/ebb8ae43d14699de86f1245ad858764d to your computer and use it in GitHub Desktop.
Steps to fix the `ModuleNotFoundError: ansible.netcommon` locally

Fixing ModuleNotFoundError: ansible.netcommon locally and Running Sanity Tests (Python 3.12)

Step 1: Create and activate Python 3.12 virtual environment

cd ~/
mkdir myenv-python312 && cd myenv-python312
pyenv local 3.12.3
python -m venv venvjuno312
source venvjuno312/bin/activate

Step 2: Clone the Juniper Ansible repo and switch to target branch

git clone https://github.com/Juniper/ansible-junos-stdlib.git -b jnpr-ansible-merger
cd ansible-junos-stdlib

Step 3: Install required Ansible collections

ansible-galaxy collection install \
  git+https://github.com/Juniper/ansible-junos-stdlib.git#/ansible_collections/juniper/device,jnpr-ansible-merger

ansible-galaxy collection install ansible.netcommon \
  -p ./ansible_collections

ansible-galaxy collection install ansible.utils \
  -p ./ansible_collections

Step 4: Clean any previous venv or cache to avoid conflict

rm -rf ~/.ansible/test/venv/
rm -rf tests/output/.tmp/

Step 5: Run sanity tests for Python 3.12 using Ansible test suite

ansible-test sanity --python 3.12 --venv --requirements

Here are the logs of a successful run for ansible-test sanity.

Result

This resolves the common ModuleNotFoundError: ansible.netcommon and allows ansible-test sanity to pass cleanly on a fresh venv with Python 3.12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment