Skip to content

Commit

Permalink
Fix pip-managed ansible
Browse files Browse the repository at this point in the history
PEP 668 disallows installing packages via pip outside of virtual
environments, to avoid breaking due to conflicting system packages.

Ansible is unlikely to be installed in the base system, and if it is and
the user still chooses to use `install_method: pip`, that would be an
invalid configuration.

This flag exists to allow users to bootstrap ansible to run as a
controller. The alternative solution would be to require virtual
environments, however this is often packaged as a separate dependency,
which further complicates bootstrap. Allow installing ansible outside of
virtual environments via pip's --break-system-packages.

Fixes GH-4244
  • Loading branch information
holmanb authored Aug 24, 2023
1 parent f7a2c48 commit b417b21
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cloudinit/config/cc_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,13 @@ def install(self, pkg_name: str):
import pip # noqa: F401
except ImportError:
self.distro.install_packages(self.distro.pip_package_name)
cmd = [sys.executable, "-m", "pip", "install"]
cmd = [
sys.executable,
"-m",
"pip",
"install",
"--break-system-packages",
]
if self.run_user:
cmd.append("--user")
self.do_as([*cmd, "--upgrade", "pip"])
Expand Down

3 comments on commit b417b21

@jjo93sa
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've been using cloud-init's Ansible module for some time. This change appears to have broken the module, at least for us. Using Ubuntu's standard cloud images, we have:

Ubuntu 20.04 - Python 3.8
Ubuntu 22.04 - Python 3.10.12 (pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10))

In neither case is the switch --break-system-packages available.

I suspect that the version of pip should be checked?

@holmanb
Copy link
Member Author

@holmanb holmanb commented on b417b21 Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've been using cloud-init's Ansible module for some time. This change appears to have broken the module, at least for us. Using Ubuntu's standard cloud images, we have:

Glad to hear it. I hope it has been working well for you other than this bug?

Ubuntu 20.04 - Python 3.8 Ubuntu 22.04 - Python 3.10.12 (pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10))

Which version of cloud-init?

In neither case is the switch --break-system-packages available.

I suspect that the version of pip should be checked?

Correct, this was fixed in 13938f7.

In any case, if you have a bug to report, please report it.

@jjo93sa
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for my earlier terseness, it had been a long day.

Glad to hear it. I hope it has been working well for you other than this bug?

Yes, it works well indeed. The only gripe we have is that we already have Ansible installed in our image, so alongside pip and distro it would be nice to see a third option install_method extant. I don't think it is possible to not specify this parameter?

These are the versions of cloud-init, python and pip we have installed (after a full apt-upgrade):

$ cloud-init --version
/usr/bin/cloud-init 23.3.1-0ubuntu1~20.04.1

$ python --version
Python 3.8.10

$ pip --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

I tried updating pip, but somehow that is pinned by Canonical to the system package.

I'm currently trying an image with cloud-init 23.1.2, which I think is both available and doesn't have this change in.

Please sign in to comment.