diff --git a/cloudinit/config/cc_ansible.py b/cloudinit/config/cc_ansible.py index 4f11bf119dc..354962c476b 100644 --- a/cloudinit/config/cc_ansible.py +++ b/cloudinit/config/cc_ansible.py @@ -3,6 +3,7 @@ import os import re import sys +import sysconfig from copy import deepcopy from logging import getLogger from textwrap import dedent @@ -141,8 +142,13 @@ def install(self, pkg_name: str): "-m", "pip", "install", - "--break-system-packages", ] + if os.path.exists( + os.path.join( + sysconfig.get_path("stdlib"), "EXTERNALLY-MANAGED" + ) + ): + cmd.append("--break-system-packages") if self.run_user: cmd.append("--user") self.do_as([*cmd, "--upgrade", "pip"])