Part 2 – Ansible Lab Setup

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

2017-04-03 20_59_31-MINGW64__d_Ansible

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

screenshot-from-2017-03-02-16-16-46

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.

For centos\7

#sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm
#sudo yum install ansible

screenshot-from-2017-03-02-16-38-06

For ubuntu\trusty64

#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.

screenshot-from-2017-03-03-15-28-16

screenshot-from-2017-03-03-15-29-28

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.

screenshot-from-2017-03-03-15-34-25

That’s all we need for now, more about our first command in next post.

Hope this was informative. Thanks!

 Part 1 – Introduction to Ansible

Part 2 – Ansible Lab Setup

Part 3 – Understanding our First Ansible Command

Part 4 – More about Inventory File

Part 5 – Ansible Config

Part 6 – Ansible Modules

Part 7 – Ansible Tasks, Plays, PlayBooks

Part 8 – Ansible Play Recap, vars, Notify, Handlers

Part 9 – Ansible Roles

Advertisements