Skip to content
This repository was archived by the owner on Feb 13, 2023. It is now read-only.

PIP failing to install inside VM if Ansible local provisioner used #2138

Closed
very-random-man opened this issue Jan 26, 2021 · 9 comments
Closed

Comments

@very-random-man
Copy link

Issue Type

  • Bug Report / Support Request

Your Environment

Vagrant 2.2.14
VirtualBox 6.0.15r135660
-bash: ansible: command not found

DrupalVM version: 6.0.2
Using latest drupalvm base box 2.0.10

Your OS

  • macOS (version)

Full console output

This is the provisioning output.

==> dev: Running provisioner: drupalvm (ansible_local)...
    dev: Installing Ansible...
    dev: 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  3607k      0 --:--:-- --:--:-- --:--:-- 3600k
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/tmpnrUI4i/pip.zip/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: {exc}")
                                   ^
SyntaxError: invalid syntax

Summary

I'm not sure if this is a vagrant problem or something that needs to change on the base box. This error has only just started happening. According to something i read, it looks like a problem relating to using Python2 instead of Python3 to execute that script. Apparently Python2 has reached End Of Life.

If you run it this manually you still get errors relating to missing dependencies

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

I managed to create a workaround by adding this to my Vagrantfile.local to change the method of pip installation:

config.vm.provision 'drupalvm', type: provisioner do |ansible|
    ansible.compatibility_mode = '2.0'
    ansible.playbook = playbook
    ansible.extra_vars = {
      config_dir: config_dir,
      drupalvm_env: drupalvm_env
    }
    ansible.raw_arguments = Shellwords.shellsplit(ENV['DRUPALVM_ANSIBLE_ARGS']) if ENV['DRUPALVM_ANSIBLE_ARGS']
    ansible.tags = ENV['DRUPALVM_ANSIBLE_TAGS']

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

    # Use pip to get the latest Ansible version when using ansible_local.
    provisioner == :ansible_local && ansible.install_mode = 'pip'
end

This seems a pretty hacky but it does work in the short term.

To make this work out of the box, does something need to happen to the base box so that the default pip installation command works with python3?

If everything is working as planned is there a better way to override the ansible.pip_install_cmd? Would be nice to have that option as drupalvm config. Or should I just rework it as a SHELL provisioner in Vagrantfile.local?

@very-random-man
Copy link
Author

very-random-man commented Jan 26, 2021

For further information I joined a chat on the vagrant issue queue about this (hashicorp/vagrant#12155) and someone pointed me to the following news which confirms that something happened with PIP in the last few days. They have dropped support for Python2 and Python 3.5: https://pip.pypa.io/en/stable/news/#id1

Apparently this install command works for Python3:

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

@siliconmeadow
Copy link
Contributor

If everything is working as planned is there a better way to override the ansible.pip_install_cmd?

Another solution with an open PR is here: #2137

IMHO it's a bit more elegant, mainly because it's a two line change.

@very-random-man
Copy link
Author

very-random-man commented Jan 27, 2021

Oh cool. I'll try that out. Didn't even realise pip3 was an option.

Update
I think this will need the addition of pip3 to the base box or prefixing the install_cmd with sudo apt-get install -y python3-pip && instead.

I guess changing the base box would mean everyone having to update to the latest box? Changing the command would avoid needing a new base box but it's a bit clunky. ;-)

@cosmicdreams
Copy link

Issue has also been reported to stack exchange:
https://stackoverflow.com/questions/65896334/python-pip-broken-wiith-sys-stderr-writeferror-exc

@siliconmeadow
Copy link
Contributor

siliconmeadow commented Jan 28, 2021

I think this will need the addition of pip3 to the base box or prefixing the install_cmd with sudo apt-get install -y python3-pip && instead.

If you use the changes in #2137 , the provisioning installs pip3 for you. It doesn't need to be on the base box in advance.

@geerlingguy geerlingguy changed the title PIP failing to install PIP failing to install inside VM if Ansible local provisioner used Jan 28, 2021
@geerlingguy
Copy link
Owner

I just merged the PR and it does seem like that should solve the problem if you don't have Ansible installed on your host computer.

This fix will make it into the next Drupal VM release, but I don't have time to tag / push it currently, so please use the dev master version until then.

@alex-moreno
Copy link

if using composer this works as well if you don't want to use the master branch:

            "geerlingguy/drupal-vm": {
                "Add pip3 to fix failing provision": "https://patch-diff.githubusercontent.com/raw/geerlingguy/drupal-vm/pull/2137.patch"
            }

would be good to have a new release though, as this is breaking current vm the moment they get rebuilt

@very-random-man
Copy link
Author

very-random-man commented Feb 4, 2021

If you use the changes in #2137 , the provisioning installs pip3 for you. It doesn't need to be on the base box in advance.

@siliconmeadow Looks like i need to do less talking and more thorough testing. ;-) Awesome. Thanks for teaching me something. :-)

@geerlingguy
Copy link
Owner

This is fixed... will be in the 6.0.3 release to be out soon: #2147

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants