Building the Sandbox
Following on from our introduction to Ansible post, here we will start to take a practical look at using Ansible. Our first step and the purpose of this post will be to build a basic sandbox environment.
A video walkthrough has been included at the end of this post
As with most of our hands-on labs we will be utilizing Vagrant and Virtualbox. If you’ve never used Vagrant please feel free to check out our youtube videos or posts below to bring you up to speed:
in order to save you time and so we can focus purely on Ansible, a pre-configured file can be pulled from the following GitHub repository:
As always the best place to start is with a design, so let’s start with a lab that’s fairly simple just to get our feet wet. The ‘Vagrantfile’ you have downloaded is based on the following topology:
As you can see we only have 3 servers and they connect to each other through the ‘Server LAN’, each system will also have Internet access via the Vagrant host. I’ve not filled in the network details for the transit or Internet as they will be based on DHCP and alter based on your system.
The three servers are:
- Ansible [10.1.1.5] – this will be the server running Ansible software
- Web01 [10.1.1.11] – this will be a blank server that will become a web server
- db01 [10.1.1.21] – this will be a blank server that will become a database server
The first step is to spin up vagrant lab by issuing the ‘vagrant up’ command.
After the servers have booted you should then be in a position to ssh into the machines. Lets start by accessing the ‘ansible’ server
vagrant ssh ansible
Note: it’s often worth checking to see if Python in installed, most Linux distros come with python pre-installed, but if in doubt check.
From the command line you can now install the application as follows:
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install Ansible
You can verify the installation using the command:
You should now have a fully operational Ansible controller.
The last thing we’ll do to make sure the future labs work without error is verify ssh connectivity to ‘web01’ and ‘db01’ from Ansible.
to keep things clean lets create a hosts file and add all three servers
and alter the contents to look like the following:
then from the Ansible server lets ssh to each of the servers and add the relevant keys.
The reason we need to do this is that Ansible uses SSH to manage the clients and without the SSH keys you will be presented with an error.
With that, we have a lab built and ready for exploring Ansible.