With some basic understanding about what Ansible can do, we can now proceed to setup our own lab environment to get a better insight on Ansible. I primarily used vagrant to setup my virtual machines needed for the lab. All you need would be a Laptop or PC with 8 to 16GB RAM capable enough of running 3 to 6 virtual machines. Coming to the software requirements, you would need Oracle Virtual Box to run the vagrant boxes; you can also use VMware Workstation but then to use Vagrant, you would need to purchase a license for the plugin. If you don’t want to use Vagrant at all, well you can always setup 3 or 4 CentOS/RHEL vm’s on the VMware Worstation and continue working on them.
If you are not very familiar with Vagrant, don’t worry, I have a series of Vagrant blog posts that will be enough for you to setup the lab environment for Ansible. Access them here.
Below is the vagrantfile i am using
I have choosen to use two centos 7 and a ubuntu machine for my test environment. It’s gonna take a little while if you are powering up the machines for the first time as vagrant downloads the images of the boxes mentioned. Once the machines are up, verify the status by either vagrant status or vboxmanage list runningvms
Now login to each vagrant machine and install ansible and verify the installation. Since i have Ubuntu and Centos machines running, i use apt-get and yum package installers respectively. Below commands will install ansible on all the vagrant VM’s.
#sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm #sudo yum install ansible
#sudo apt-get install ansible
I just figured that vagrant box centos/7 doesn’t come with ifconfig installed, to install use below.
sudo yum install net-tools
As discussed earlier, ansible controller communicates with managed nodes using SSH and for this to work, the known hosts file on controller must have the ssh info. For this, ssh to vagrant machines from ansible controller.
Now, create a inventory file with machine IPs in it on the vagrant machine you wish to make the ansible controller. In my case it is the ‘ansi’ machine running ubuntu.
If you did everything well and you were able to ssh to managed nodes from the controller node, you should be able to run the ping module just fine via ansible.
That’s all we need for now, more about our first command in next post.
Hope this was informative. Thanks!