This draft comes from a small but very real blocker during an Ansible run. The failure looked deeper than it really was because it happened during package installation for an OpenShift-related dependency, but the actual problem was much simpler: the remote Python environment was missing pkg_resources.

The Problem

The Ansible task failed while trying to install Python packages into a virtual environment:

1
2
3
ImportError: No module named pkg_resources
fatal: [target-node]: FAILED! => changed=false
msg: Failed to import the required Python library (setuptools) on the remote Python interpreter

At first glance, this looks like a problem with the role, the virtual environment, or even the chosen interpreter. In practice, the remote host was missing the setuptools package that provides pkg_resources.

Why This Breaks the Run

Ansible’s pip module depends on the underlying Python runtime being able to import the pieces it needs. If pkg_resources is missing, package installation tasks can fail even when the playbook itself is otherwise correct.

That means the failure is not always in the automation logic. Sometimes the target machine is simply missing a basic Python dependency.

The Fix

Reinstall python-setuptools on the affected machine:

1
sudo apt install --reinstall python-setuptools

After that, rerun the playbook or the failed step.

What I Took From This

This is a good example of why I keep work logs. Small dependency issues like this can burn a surprising amount of time when they appear in the middle of a larger cluster or platform install.

The lesson is straightforward:

  • when Ansible reports No module named pkg_resources
  • verify the remote interpreter
  • confirm setuptools is present
  • repair the base Python package before debugging the playbook itself

It is a small fix, but it removes a hard blocker quickly.