We are currently running into an issue, with Vagrant, where certain CLI commands need to be run before Ansible provisionning:
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:
ERROR: This script does not work on Python 2.7 The minimum supported Python version is 3.7. Please use https://bootstrap.pypa.io/pip/2.7/get-pip.py instead.
In our Vagrantfile we have added the following, but when we go to provision the shell block does not appear to be called before the Ansible block, so we end up having to vagrant ssh into the container and then run them manually:
config.vm.provision "shell" do |s|
s.inline = "update-alternatives --install /usr/bin/python python /usr/bin/python2 1"
s.inline = "update-alternatives --install /usr/bin/python python /usr/bin/python3 2"
s.inline = "apt install -y python3-setuptools"
end
config.vm.provision "ansible_local" do |ansible|
ansible.compatibility_mode = "2.0"
ansible.install = true
ansible.install_mode = "pip_args_only"
ansible.pip_args = "ansible==#{ANSIBLE_VERSION}"
ansible.playbook = "deploy-local.yml"
ansible.galaxy_role_file = "roles.yml"
ansible.galaxy_roles_path = "/tmp/galaxy_roles"
end
Can anyone suggest how to force sequence of provisioning block?
By default, some debian like distributions, for example Ubuntu 20.04, have a
pythonlink topython2. Although versionpython3is also present. You need to change this behavior, add a pip3 version if there isn't one and the most important thing is to useansible.install_mode = "pip3". For example provisioning block will look like this: