Day 1: Ansible Installation and SSH Connection Setup

AQIB HAFEEZAQIB HAFEEZ
2 min read

Ansible Installation on Master Node:

Architecture:

Access the master node:

  1.   Copy codecd ~/.ssh
    

Generate SSH key pairs:

  1.   ssh-keygen
    

Display the public key:

  1.   cat id_rsa.pub
    
  2. Copy the displayed key (id_rsa.pub) and paste it on the child node.

Access the child node:

  1.   cd ~/.ssh
    

Edit the authorized_keys file:

  1.   vi authorized_keys
    
  2. Paste the master node's public key into the authorized_keys file.

SSH into the master node from the child node:

  1.   ssh username@child_node_ip
    

Update the child node:

  1.   sudo apt -y update
    

Install Ansible on the master node:

  1.   sudo apt install software-properties-common
      sudo apt-add-repository --yes --update ppa:ansible/ansible
      sudo apt install ansible
    

Verify the Ansible installation:

  1.   ansible --version
    

Configuring SSH Connections in Ansible:

  1. Navigate to the Ansible configuration directory:

     cd /etc/ansible
    

Edit the inventory file:

  1.   vi hosts
    

Define groups and add child nodes' IPs or hostnames:

  1.   [group_name]
      child_node_ip_or_hostname
    
  2. Save and exit the file.

Test the SSH connection to all nodes:

  1.   ansible group_name -m ping
    

  1. Display the inventory in YAML format:

     ansible-inventory --list --yaml
    

Additional Reference:

This comprehensive guide covers the installation of Ansible on both the master and child nodes, setting up SSH connections, and verifying the setup. Replace group_name, child_node, child_node_ip, and your_username with your actual details. This ensures a seamless and secure Ansible configuration for effective server management.

0
Subscribe to my newsletter

Read articles from AQIB HAFEEZ directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

AQIB HAFEEZ
AQIB HAFEEZ

DevOps Engineer, Linux, Git, GitHub, GitLab, CI/CD pipelines, Jenkins, Docker, Kubernetes, Ansible & AWS. Practical experience in these DevOps tools enhances my passion for streamlined workflows, automated processes, and holistic development solutions. Proficient in digital and Facebook marketing, aiming to merge technical acumen with marketing finesse.