hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.26k stars 4.43k forks source link

Unable to use Ansible provisioner on Ubuntu 20.04 via pip install mode #12155

Closed jakobjs closed 1 year ago

jakobjs commented 3 years ago

Vagrant version

$ vagrant version
Installed Version: 2.2.14
Latest Version: 2.2.14

You're running an up-to-date version of Vagrant!
$

Host operating system

$ uname -a
Darwin mac-0 20.1.0 Darwin Kernel Version 20.1.0: Sat Oct 31 00:07:11 PDT 2020; root:xnu-7195.50.7~2/RELEASE_X86_64 x86_64

Guest operating system

$ vagrant box list
bento/ubuntu-20.04     (virtualbox, 202012.23.0)
generic/ubuntu2004     (virtualbox, 3.1.24)

Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.define :pg do |t|
  end

  config.vm.box = "generic/ubuntu2004"
  config.ssh.insert_key = false
  config.ssh.username = "vagrant"
  config.vm.hostname = "postgres1"
  config.vm.synced_folder ".", "/vagrant"
  config.vm.provider "virtualbox" do |vb|
    vb.name = "postgres1"
    vb.gui = false
    vb.default_nic_type = "virtio"
    vb.customize ["modifyvm", :id, "--vram", "8"] # ubuntu defaults to 256 MB which is a waste
    vb.linked_clone = false
  end

  config.vm.provision "ansible_local" do |ansible|
    ansible.playbook = "basic-playbook.yml"
    ansible.install_mode = "pip"
  end
end

Debug output

$ vagrant provision
==> pg: Running provisioner: ansible_local...
    pg: Installing Ansible...
    pg: Installing pip... (for Ansible installation)
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

curl https://bootstrap.pypa.io/get-pip.py | sudo python

Stdout from the command:

Stderr from the command:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1883k  100 1883k    0     0  1521k      0  0:00:01  0:00:01 --:--:-- 1521k
Traceback (most recent call last):
  File "<stdin>", line 24226, in <module>
  File "<stdin>", line 199, in main
  File "<stdin>", line 82, in bootstrap
  File "/tmp/tmpf2GbZ5/pip.zip/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: {exc}")
                                   ^
SyntaxError: invalid syntax

$

Expected behavior

ansible should run

Actual behavior

ansible does not run

Steps to reproduce

  1. vagrant up (or vagrant provision) with the Vagrantfile above. I've tried two different Ubuntu 20.04 images (generic and bento)

References

None

jakobjs commented 3 years ago

Side note: Default install also fails since it tries to use the PPA to install.

Ansible is now a system package and is included in Ubuntu 20.04+ so the PPA should not be used: https://packages.ubuntu.com/focal/ansible

jakobjs commented 3 years ago

The solution may be as simple as running python3 instead of python.

very-random-man commented 3 years ago

I've hit this too. Worked fine last week but this week I get the same error as above. I am using Ubuntu 18.04 and I have only managed to get it to build by changing the install command:

    ansible.pip_install_cmd = "sudo apt-get -y install python-pip"

This seems a bit wrong and I'm sure i should be doing it a better way.

If you change the install cmd to use python3 instead of python you get a problem relating to a missing python package dist_utils.

I'm told this is likely to do with the deprecation of Python 2.

I'm using this in the context of a drupalvm implementation with the latest geerlingguy/drupavm base box (2.0.10), in case that is useful to know.

ghost commented 3 years ago

Getting into the thread! The same error appears using my Vagrantfile

Most likely it's related with pip 21.0 (2021-01-23) changelog. (Drop support for Python 2 and Python 3.5) The syntax f'' is supported by Python 3.6+

samdbmg commented 3 years ago

Most likely it's related with pip 21.0 (2021-01-23) changelog. (Drop support for Python 2 and Python 3.5)

We've had quite a few problems this week in the same vein - that'll teach me not to get around to swapping to 3.6 for our CI systems!

As hinted at by a few others I've amended my Vagrantfile to add something like this, which is now working again.

config.vm.provision "ansible_local" do |ansible|
    ....
    ansible.pip_install_cmd = "sudo apt-get install -y python3-distutils && curl -s https://bootstrap.pypa.io/get-pip.py | sudo python3"
end

I found I needed to add python3-distutils on the bento/ubuntu-18.04 boxes, but YMMV.

jakobjs commented 3 years ago

@samdbmg your workaround works for me. Thanks! 👍

thunderysteak commented 1 year ago

A more elegant workaround for this issue is to use pip3 instead of pip as Ansible Installation method that works on Ubuntu 20.04/Focal

config.vm.provision "ansible_local" do |ansible|
    ....
  ansible.install_mode = "pip3"
end