![]() ![]() You will need the Ansible controller engine installed on your VirtualBox host machine meaning that you are limited to Linux or MacOS. The automation of your Vagrant Virtual Machine provisioning could not get any better than by using Ansible. We can now move onto the full picture: Provisioning Vagrant Virtual Machines with Ansible on Linux or MacOS. => default: Destroying VM and associated drives.Īnsible Integration with Vagrant to Provision Virtual Machines Listing 04: Deleting the VM $ vagrant destroyĭefault: Are you sure you want to destroy the 'default' VM? y We will now destroy the VM before look at Ansible integration. Using the -f option we will not be prompted to destroy the VM. The delete the Virtual Machine we can use vagrant destroy. There will be no need to clone the box again if the VM already exists so any configuration changes are maintained as you would expect with normal VM usage. This keeps the Virtual Machine and can be started again at anytime using vagrant up. To shut the VM down we can use vagrant halt. We also connect as the user vagrant using key based authentication, again this is transparent to us from the command line. This is transparent to us when making the connection via the vagrant ssh command. The default networking is using the VirtualBox NAT network so be connect to the localhost on port 2222 to be redirected to SSH on the running VM. Total used free shared buff/cache available Listing 03: Starting the VM and connecting $ cd $HOME/vagrant/ubuntu We can connect using the command vagrant ssh from the same directory: To start the Virtual Machine we use vagrant up, executed from the directory $HOME/vagrant/ubuntu. The inner block defines specific setting for VirtualBox, as an example we increase the virtual RAM assigned to the VM, the variable used in tis block we have set to vb. – config.vm.hostname defines the hostname of the new VM – config.vm.box defines the Virtual Machine image (box) that we want to download The outside block defines the configurations and uses a variable called config to configure elements: Listing 02: A Simple VagrantFile Defining a single VM $ cd $HOME/vagrant/ubuntu First we look at a simple Vagrantfile defining one Virtual Machine before moving onto defining the Ansible provisioning element. They only need to be downloaded once and future VMs can be cloned from the downloaded box. The Virtual Machines are cloned from, boxes, these boxes are downloaded from the Vagrant repository located at. The control file for Vagrant is called the Vagrantfile and this defines the Virtual Machines. ![]() Listing 01: Create directory for Vagrant project $ mkdir -p $HOME/vagrant/ubuntu Create a project directory for you Virtual Machine project, this can also be our Ansible project directory. Having downloaded and installed both products we ignore the normal usage of VirtualBox remember that Vagrant is your Virtual Machine Manager so although we need VirtualBox installed we do not need to open or use their interface. We will use VirtualBox and Vagrant on MacOS. Typically, this would be VirtualBox as it it free on all platforms. In simple terms Vagrant is a Virtual Machine Manager and requires a Virtualization Engine. We start by looking at provisioning Vagrant Virtual Machines with Ansible, but just Vagrant to start. Provisioning Virtual Machines Using Vagrant Alone Using Ansible 2.10.x installed on MacOS I will demonstrate how you can use Vagrant and Ansible in collaboration. The Ansible controller can be installed on Linux and MacOS, so if your Vagrant host is one of those operating systems, you are ready to both deploy your Virtual Machine with Vagrant and provision it with your Ansible Playbooks. The great thing with Vagrant is that you can further configure your Virtual Machine using Provisioners, one of those provisioners is Ansible. ![]() Vagrant is free to use and install on Linux, Windows and MacOS. Within you own environment you may well be used to using Vagrant from HashiCorp to deploy Virtual Machines. Provisioning Virtual Machines Using Vagrant and Ansible is a lot easier than you think especially if you already have some Ansile experience. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |