RHCE 02 | Configuring webserver using Ad-hoc and Ansible playbook in controller and managed nodes

RHCE 02 | Configuring webserver using Ad-hoc and Ansible playbook in controller and managed nodes

ยท

3 min read

If we want to do configure management through automation then there are two ways either the Non-intelligent way or the Imperative way which is using shell scripting. But if we want to do automation using an intelligent way or a declarative way we use Ansible.

If we want to set up a webserver in various nodes then either we can do this by going on each node and configure it or we can make a server through which we can configure the webserver in these nodes ( not by ssh). Here we use Ansible to configure the webserver and this node will act as a controller or manager node.

In the master or controller node, we have to install the ansible and their we have to write the code as automation is not possible without code after that we have to execute that code. Now this code will have the capability to go from master to slave node and configure or install whatever is written in the code.

for connecting the controller node first step should be network connectivity and behind the scenes they use SSH in Linux system and winrm protocol in Windows.

In Ansible you have to provide two things first is inventory (which means all the information about target nodes like ip, username, password, protocol) and second thing is code.

inventory is a time process and code is life long process we keep on changing the code according to updates.

IPs of

ansible-master: 84

ansible-target1: 103

ansible-target2: 212

so first we have to install the ansible core in the controller node or master node

now we want to configure the server inside the target nodes for this ansible see the inventory.

The command to list all the hosts in the inventory

ansible all --list-hosts

so for this, we have to create the inventory

To create inventory, open a file โ€œ/etc/ansible/hostsโ€, here we specify only the IP Address of the managed node.

but providing only ip address to inventory is incomplete information so we also have to provide a username, password and protocol is complete information for connecting the nodes and configuring the server easily.

now configure the host by going into the configuration file of ssh (/etc/ssh/sshd_config) of each slave or target node and set permit root login to true and password authentication to yes.

now in /etc/ansible/host file set the changes

after setting the host you will able to install anything

let's configure the httpd server in the target nodes

step 1: install the package httpd

ansible all -m package -a "name=httpd state=present"

step2: webpage deployment (copy mayank.html into your target nodes /var/www/html)

ansible all -m copy -a "src=mayank.html dest=/var/www/html"

step3: now we have to start the service

ansible all -m service -a "name=httpd state=started"

but this is a somewhat manual or ad-hoc way of ansible to make full automation we have to write a code in YAML language.

ansbile playbook (mayaweb.yml)

then run ansible-playbook mayaweb.yml if all run successfully then no error came

I hope you guys enjoy the blog do share and like it

want to connect with me ๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡

My Contact Info:

๐Ÿ“ฉEmail:-

LinkedIn:- linkedin.com/in/mayank-sharma-devops

ย