

Unfortunately, Vagrant does not support the general Containerfile and we need to name it "Dockerfile". Since I want to use the provisioner to test new images and Dockerfiles/Containerfiles, let's have a look at the "build image" feature.įirst, we need to create a simple Dockerfile. So, running a prepared image (or multiple images) is easy. nfigure("2") do |config|Ĭonfig.vm.provision "podman" do |container|Īfter starting the Vagrant machine, we can test if the server is reachable. # Create project directoryĮdit the Vagrantfile and add the Podman provisioner. Let's create the project directory and some needed files first. You can use Vagrant to run a container from an existing image. Therefore, I am using the CentOS 8 Stream Vagrant box. Hint: Unfortunately, the Podman installation on Fedora fails. If you don't know anything about Podman and Docker, I recommend reading the articles here. The examples are easy to apply to Docker, too. Since the Podman and Docker provisioner are working very similar and are having basically the same syntax, I will focus on Podman for this section. You will also be able to verify if containers can run on different platforms.
#Vagrant ansible download
This way, you don't need to define Networks, Secrets or download images, which are idling around until you clean them up. If you have an application, that must be shipped as a container, or if you just want to spin-up a third party container, Vagrant can be helpful. The development of containers can be a problem, too. You can spin up a fresh VM or re-apply the playbook with the below commands. nfigure("2") do |config|Ĭonfig.vm.provision "ansible_local" do |ansible| Just edit the Vagrantfile as described below. To get a better understanding of this sync feature, please have a look at the documentation. It will be available in the "/vagrant" directory.
#Vagrant ansible install
Vagrant will try to install Ansible in the Vagrant machine and apply the provided playbook afterwards.ĭuring this process, Vagrant will sync the working directory in the Vagrant machine. If you don't have Ansible on your machine, you can consider using the Ansible Local provisioner. $ vagrant provision Ansible Local Provisioner

Afterwards, you can test the deployment or change the playbook and run the provisioner again. Just run vagrant up to start the VM and run the provisioner. Vagrant will create an inventory automatically and run the "ansible-playbook" command, so the new inventory is used. In addition, you can see a new section "config.vm.provision", which will trigger the Ansible provisioning. nfigure("2") do |config|Ĭonfig.vm.provision "ansible" do |ansible|Īs you can see, we will spin-up a Fedora 34 machine. Edit the Vagrantfile with the editor of your choice. The last part, we need to add content for the Vagrantfile. Some content for the website may look like the below example.
#Vagrant ansible full
The module will look in the "files" directory on its own, and you don't need to specify the full path. Īs you can see, we want to copy a custom index.html, too.

Edit the "playbook.yml" file and fill in some content like below. Let's write a simple playbook, that will install a basic web server. First, we need to create a small project and some files. You can use different Ansible Version in a "virtualenv" and run everything as, if the Vagrant Box is just another remote machine (stack). The Ansible Provisioner is very useful, if you are having Ansible installed on your machine anyway. If you don't know Ansible, I strongly recommend reading some articles about it.

Same tool for production and develop is my preferred way. You can also consider Ansible, if you are using it anyway, to deploy and configure your infrastructure.
#Vagrant ansible code
Vagrant can help to spin up a machine and deploy your code on different Operating Systems and you can do much more, than in Docker or Podman containers. Much stuff can be done in containers, but sometimes you want to test virtualization, kernel parameters, certain security and firewall settings and just need some "real" machine. If you develop Ansible Playbooks, Roles or Collections, you may want to test them properly. The guide is tested on Fedora 34 with Vagrant 2.2.16.
