Installing Ansible on CentOS 7

Ansible is a configuration management tool released by Redhat which helps IT Admins and Devops engineers take and keep control of their IT platforms. I’ve never had the chance to play with Ansible before and plan to add this into my VRA home lab setup so i need to get the base install done. The below is not best practice and should not be deployed into a production environment in this manor, please review the official documentation.

To start i like to take a snaphot of my VM so i was have a place to go back to if i make a mistake and i’m to far down a hole and have to rebuild. I also have a second CentOs server that i’m going to use as my target machine, this is a clean install also.

to Start i’ll run a update on my ansible server to update all the packages for the OS

 sudo yum -y update

Then we need to install the EPEL Repo this is Extra Packages for Enterprise Linux

sudo yum install epel-release -y

you can check that this is installed by running

sudo yum repolist

we can now install Ansible

sudo yum install ansible -y

When that has installed check the version

ansible --version

create a SSL key so the the master server will be able to connect to the target servers and do a ssh copy to the target server

ssh-keygen

ssh-copy-id root@<TargetServerIP>

you should now be able to ssh to the target server using ssh root@<TargetServerIP> without getting a password prompt

Next step is to add this target server to the hosts file in Ansible

vi /etc/ansible/hosts

Uncomment a section or create a new one using [ ] as the header, i’m using [LabServers] as per below. Enter the IP address of the target server. Make sure there are no spaces in the header name otherwise it will throw an error.

when you run a ansible ping you should get a success message

ansible -m ping all

to test this is now working we will use the script module to install a web server on the target and start the web services.

vi Webserver.sh

File contents:
sudo yum update httpd -y
sudo yum install httpd -y
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo systemctl start httpd

write and close the file and then run the below command

ansible -m script -a './Webserver.sh' all

you should see a output like this

on the target server the before and after the script has been executed

To follow on from this post i will be integrating Ansible into VRA 8.x and then calling some of these configurations as part of VRA blueprints.