filmov
tv
3 | Ansible Hands-On Demo Project | Step by Step for Beginners
![preview_player](https://i.ytimg.com/vi/Ops94dNqZ-0/maxresdefault.jpg)
Показать описание
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
—
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
—
Комментарии