I try to provision my Vagrant boxes with the ansible_local provisioner. The other day I was using the pip ansible module while I was booting the box, but was getting errors while installing packages. It turns out that the pip version I had when I created the environment needed an upgrade. Sure you can run a
pip install pip --upgrade from the command line, but how do you do so within a playbook? Pretty easy it seems:
--- - hosts: all tasks: - name: create the needed virtual environment and upgrade pip pip: chdir: /home/vagrant virtualenv: work virtualenv_command: /usr/bin/python3 -mvenv name: pip extra_args: --upgrade - name: now install the requirements pip: chdir: /home/vagrant virtualenv: work virtualenv_command: /usr/bin/python3 -mvenv requirements: /vagrant/requirements.txt
(Link to pastebin here in case the YAML above does not render correctly for you.)
I hope it helps you too.