Ansible - Enable SSH Communication

Ansible is an agentless automation tool; means no need to install any agent on the nodes which Ansible manages. Instead, Ansible control machine communicates to the nodes via SSH. We have to enable SSH communication between control machine and nodes before executing any playbook.

There are 2 ways this ssh communication can be setup:

  1. Create a ssh key from control machine and propogate to the nodes
  2. Pass the credentials via inventory file

We will setup both ways now.

Via inventory file

In the inventory file, pass ansible_ssh_user and ansible_ssh_pass along with the node's IP address or FQDN as below.

1[node1]
210.0.0.2 ansible_ssh_user=root ansible_ssh_pass=password

Via SSH key

  1. Generate a SSH key in the control machine as below
1$ ssh-keygen -t rsa -b 4096

keygen

2. Copy the ssh key that is created to the node using the following command

1$ ssh-copy-id root@10.0.0.2

3. Verify connection once

1$ ssh root@10.0.0.2

Now that ssh connection is successfully established

Test the communication

Now we can test the communication between control machine and and the node using few ansible modules as below

  • Ping the node machine
1$ ansible -m ping node1

ping

  • Find node machine's uptime
1$ ansible -m command -a uptime node1

up

SSH Connection established successfully !!!! Now the Control machine can communicate to the node.

To Read More

Kubernetes for Nodejs developers

Do you keep hearing the word kubernetes in the tech community and you couldn't u...

TypeScript Interfaces vs Types

In this article, we will see what are interfaces and types and the difference be...

How to find project ideas to practi...

Ever wondered what how to get a real world experience on web development while w...

Building a Production-grade Nodejs,...

This article is the first part of building a production grade nodejs,graphql and...

Modern React Redux Tutorials with R...

This tutorial explain how you can build an application using modern react redux ...

Building a Piano with React Hooks

In this article, we will see how to build a piano with react hooks. Building a P...

TypeScript Basics - The Definitive ...

In this article, we will learn some basics of typescript which helps you to deve...

Here's why podman is more secured t...

In this article we will see about podman and why it is more secured way to run c...

What is gRPC ? How to implement gRP...

Everyone talks about gRPC. Have you ever wonder how it works or how to implement...