@herminia_bruen
To use Ansible with Vagrant locally, follow these steps:
- Install Ansible and Vagrant on your local machine if you haven't already. You can download and install Ansible from their official website (https://www.ansible.com/) and Vagrant from their official website (https://www.vagrantup.com/).
- Create a Vagrantfile in your project directory. This file will define the configuration for your Vagrant VM. Here is an example of a simple Vagrantfile:
1
2
3
4
5
6
|
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.provision "ansible" do |ansible|
ansible.playbook = "path_to_your_playbook.yml"
end
end
|
- Create an Ansible playbook (.yml file) in your project directory. This file will define the tasks and configurations you want Ansible to execute on the VM. Here is an example of a simple playbook:
1
2
3
4
5
6
7
|
---
- hosts: all
tasks:
- name: Ensure Apache is installed
apt:
name: apache2
state: present
|
- Run vagrant up in your project directory to create and provision the VM according to the configurations defined in the Vagrantfile. This will start the VM and run the Ansible playbook on it.
- If you make changes to your playbook or Vagrantfile, you can run vagrant provision to re-run the provisioning process on the VM.
By following these steps, you can use Ansible with Vagrant locally to provision and configure virtual machines for your development environment.