3 | Ansible Hands-On Demo Project | Step by Step for Beginners

preview_player
Показать описание
How to setup Ansible Controller machine
How to setup Ansible Host machines
Making connection between Controller and Hosts
Adding host and playbook file on Controller
Run Playbook to configure Host Machines

We will need Linux machines for this DEMO

You can use any Linux machines or setup using any cloud platforms like AWS
In this Demo I am going to use Vagrant to create Linux Virtual Machines
In any case the process and steps will remain same

Ref:

Part A
Ansible Controller Machine Setup

Step 1 - Install VirtualBox and Vagrant on your local machine.
Step 2 - Open a terminal and navigate to the directory where you want to set up your Ansible project.
Step 3 - Create a new directory for your Ansible controller VM by running the command mkdir ansible-controller
Step 4 - Navigate to the directory and create a new file called Vagrantfile by running the command vagrant init centos/7
Step 5 - Edit the Vagrantfile and add the lines to the end of the file to provision Ansible on the VM

Vagrantfile for creating VM for Ansible Controller

end
sudo yum install epel-release -y
sudo yum install ansible -y
SHELL
end

Step 6 - Save & check its a valid vagrantfile vagrant validate Then run command vagrant up to start the VM
Step 7 - Once the VM is up and running, connect to it using SSH by running the command vagrant ssh
Check ansible is installed - ansible --version
Step 8 - Create a new directory for your Ansible project on the controller VM by running the command mkdir ansible-project
Step 9 - Navigate to the ansible-project directory and create a new file called hosts by running the command touch hosts
As of now the hosts and the playbook file are empty
We will now create some host machines that will be controlled by the Ansible controller

Part B
Ansible Host Machines Setup

Step 1 - On terminal navigate to your Ansible Project folder
Step 2 - Create a new directory for your host machines by running the command mkdir host-machines
Step 3 - Navigate to host-machines directory and create a new Vagrantfile by running the command vagrant init centos/7
Step 4 - Edit the Vagrantfile and modify the following lines to set up two Vagrant machines:

Vagrantfile for creating VMs for Ansible Host


end

end
end

Step 6 - Save & check its a valid vagrantfile vagrant validate Then run command vagrant up to start the VM
Step 7 - Check the status of machines vagrant status
Once the VMs are up, connect to them using SSH vagrant ssh <machine-name> e.g vagrant ssh web
This completes the process of setting up host machines

Part C
Making connection between controller and host machines

Step 1 - Make sure all machines are up and running
Step 2 - Run command ip addr on each machine and check they have IP addresses in the same range (e.g. 192.168.33.x).
Step 3 - On Controller machine run the command ssh-keygen to generate an SSH key pair
Step 4 - Goto ~/.ssh folder and check the public and private keys generated
Step 5 - Copy the public key to the host machines by running the command ssh-copy-id <user>@<host>

Can do this manually by copying the contents of the .pub file generated by ssh-keygen and pasting it into the ~/.ssh/authorized_keys file on the host machines

Step 6 - Test the SSH connection by running the ssh command with the IP address of the host machines-

▬▬▬▬▬▬▬

You can support my mission for education by sharing this knowledge and helping as many people as you can

If my work has helped you, consider helping any animal near you, in any way you can

Never Stop Learning
Raghav Pal


Рекомендации по теме
Комментарии
Автор

Guys don't be cheap this is high value information for free the guys is doing phenomenal work please support .

ismailguendouz
Автор

I just want to say thanks for this series!!! This has been absolutely awesome! Thank you for this gift of knowledge!

jeff
Автор

The videos are awesome. I have been able to understand every bit with ease. The step by step approach Thanks for these.

meghnan
Автор

As you have showed every bit and in depth the all next tutorial should be like this only then one can understand things and can troubleshoot things easily wait for this of video only and thanks raghav sir this course in-depth

healthinsurance
Автор

Good job bro you make me understand Ansible in minutes… Thanks

proffstudios
Автор

awesome content thanks @RaghavPal, i am new to automation and I must say it is a lot of info but really really amazing thanks again for your dedication and time.

karimidres
Автор

Thank you for tutorial...Vagrant made this video a bit complex

cloudmahenderdaily
Автор

Hello Raghav, first of all thanks for sharing the knowledge... I'm looking for these kind of videos where the subject is taught on VMs rather than cloud.. once again Thank You.

amarnathvelala
Автор

hi, if we are suppose to save the servers in the hosts file then do we need to provide in the hosts of ansible-project or directly if we install ansible we will be having an inventory file which is in the /etc/ansible/hosts file? and also may i know the difference btw them, thanks in advance!!

sulochana
Автор

Hi Raghav, why is it that I cannot find any videos on ansible tutorial where they are using docker containers for controller and hosts?

I tried doing this myself, but kept facing ssh connection refused issue. I am not experienced in networks and I wasn't able to figure out why it wouldn't work.

grandselenium
Автор

Did this work with windows environment too what additional set up we need to do for setting up the same

vtravellers
Автор

This is very simple and clean l. Can you make a vedio on ansible real time project.

manjunathamanju
Автор

hi, thanks for this lesson. when I try to run the playbook task I get BSD(Bluescreen) on my windows OS, please can you advice.

Creativetouchshegss
Автор

Raghav, could you please demo using AWS EC2 instances as industries are mostly moving toward cloud ? That will be very helpful.

MrAbhishank
Автор

Detailed explanation but instead of vagrant we can create free account in AWS and create two EC2 instances to perform this project.

shahbhavan
Автор

Hello sir, I was able to follow up to the point when we did vagrant SSH but when I ran the command I got this Permission denied (public key, gssapi-keys, gssapi-with-mic), please help me.

damilolaorisadare
Автор

thank you sm for this helpful video !
I was having a problem connecting to the hosts from the controller VM but I managed to make it work but then later i couldn't enter bd from the host VM using " vagrant ssh db ", how can I fix this ?
Thanks in advance !

yasminahmede
Автор

Hello Raghav, Thank you for this easy and resourceful course. I have a question, after running the command ansible-playbook -i hosts playbook.yml my device shows me error(Sorry your device ran into trouble and needs to be restarted) and restarts. How do I rectify this ?

zubilchokra
Автор

Hi Sir, While i am doing cat /etc/ansible/hosts its coming like no such directory how can i overcame this issue..?

gowthamk
Автор

hello
Thank you for your valuable explanations.At the 36.03 minute i am facing a trouble, the host authorization key what i am getting is something very differnt it shows ssh-ed25519 and a very short key. I think something is wrong, or have i missed something.Please help

vidyapatil