
If you have any ansible roles or collections that need to be installed prior to your playbook executing you can define those in the galaxy_command statement.
#VAGRANT ANSIBLE INSTALL#
If you prefer a specific version of ansible you can define the version otherwise pip will install the latest available. Once pip is installed vagrant will proceed with installing ansible. In the above example you can see I’m installing python3-disutils first and then installing pip. Within the Vagrantfile you define how pip should be installed via the pip_install_command statement. So I also needed to make sure that is installed prior to the pip installation. Ubuntu 20.04 does not come with disutils and the pip installation will fail if it’s not present. The vagrant box that I selected comes bare bones and pip is not available. Prior to installing ansible via pip I must first install pip. This is the error that I received when attempting that install method:Į: The repository ' focal Release' does not have a Release file.Īnother approach that vagrant allows is installation via pip. On Ubuntu 20.04 I had issues using that method as focal was not recognized as a valid option. The default method is installing via the operating system package manager. There’s a couple methods you can use for the installation. The ansible local provisioner will first install ansible on the vagrant box.

Once the vagrant box is online it will run the provisioner. When you perform a vagrant up vagrant will first bring the vagrant box online. The next statement goes into our ansible local provisioner. The config.vm.box statement defines the vagrant box that we’re going to use (bento/ubuntu-20.04). galaxy_command = "sudo ansible-galaxy install -r /vagrant/collections/requirements.yml" end end pip_install_cmd = "sudo apt install -y python3-distutils & curl | sudo python3" ansible. provision "ansible_local" do |ansible | ansible. Looking at the Vagrantfile in our example github repo you’ll see that it’s pretty simple. The basic gist of a Vagrantfile is it essentially defines your vagrant environment - the virtual boxes, their network connectivity, resources, etc. In this post I won’t go into much detail on the Vagrantfile aside from the provisioner section. Check out the documentation provided in the previous statement to learn more about Vagrantfiles and everything you can do within one.

Whenever you are working with vagrant boxes you are going to have a Vagrantfile defined.

Often times when I’m using a vagrant box I need to get it in a certain state before it’s ready for me to begin using. I usually use them for development environments or creating lab environments for testing various network functions (i.e. There are a lot of Ansible options you can configure in your Vagrantfile.I’ve been working with vagrant boxes for quite awhile now. Runs the provisioner once the virtual machine has booted and is ready for SSH Notice the config.vm.provision section that refers to an Ansible playbookĬalled playbook.yml in the same directory as the Vagrantfile. provision "ansible" do | ansible | ansible. box = "ubuntu/trusty64" # Disable the new default behavior introduced in Vagrant 1.7, to # ensure that all Vagrant machines will use the same SSH key pair.
#VAGRANT ANSIBLE UPGRADE#
# Although versions 1.6.x should behave very similarly, it is recommended # to upgrade instead of disabling the requirement below. # This guide is optimized for Vagrant 1.7 and above.
