Reputation: 7558
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?
Upvotes: 2
Views: 703
Reputation: 61
By default, some debian like distributions, for example Ubuntu 20.04, have a python
link to python2
. Although version python3
is also present. You need to change this behavior, add a pip3 version if there isn't one and the most important thing is to use ansible.install_mode = "pip3"
. For example provisioning block will look like this:
# Change link to python3 and install pip3
config.vm.provision "Python version change", before: :all, type: "shell", inline: <<-SHELL
apt update
apt install -y python3-pip && echo Pip3 installation complete.
ln -f /usr/bin/python3 /usr/bin/python && echo Python default version was changed to 3.
SHELL
# Run Ansible from the Vagrant Host
config.vm.provision "ansible_install", after: :all, type: "ansible_local" do |ansible|
ansible.become = true
ansible.playbook = "./stack/ansible/playbook.yml"
ansible.install_mode = "pip3"
ansible.galaxy_role_file = "./stack/ansible/requirements.yml"
ansible.galaxy_roles_path = "/etc/ansible/roles"
ansible.galaxy_command = "sudo ansible-galaxy install --role-file=%{role_file} --roles-path=%{roles_path} --force"
end
Upvotes: 1