Getting Started with Ansible: Automating Server Management and Setting Up Password Less SSH Authentication

ReshmaReshma
3 min read

What is Ansible ?

Ansible is an open-source automation tool that simplifies IT management processes like configuration, deployment, and orchestration. It defines server and application management instructions through simple YAML files known as playbooks. Ansible runs agentlessly, which means it connects to servers via SSH (Linux) or WinRM (Windows) without requiring additional software on the servers.

Its declarative approach lets users to express the desired state of their systems, making automation more natural and less difficult. Ansible offers roles and inventory management, which let you structure tasks and manage numerous servers more efficiently. This application is highly regarded for its ease of use, scalability, and capacity to streamline complicated procedures, hence improving IT operations' efficiency and management.

Setting Up Password Less Authentication:

  1. Create Two Instances In Aws (Ex: ansible_server, target_server)

  2. Log In to the two server's

  3. In the ansible_server we need to generate key so enter

     ssh-keygen
    
  4. Get into the directory as

      ~/.ssh
    
  5. We have authorized_keys , private key (id_rsa) and public keys (as id_rsa.pub)

  6. View the public key

     cat id_rsa.pub
    

    and Copy the key

  7. Create a inventory file in ansible_server

     nano inventory
    
  8. Enter the following into the inventory file

    
     [all]
     Private Ip address of target_server
    
  9. Now coming to the target_server , get into the ssh folder as ~/.ssh

  10. Open the authorized_key and paste the copied key (i.e public key generated from ansible_server)

  11. We are not done yet !

  12. Make some changes into the target_server as

    chmod 700 ~/.ssh
    

    (700 - giving read, write and execute permissions to the admin only)

    chmod 600 ~/.ssh/authorized_key
    

    (600- read, write permission only to the admin)

  13. Yay !! Now we are done connecting the target_server to ansible_server

  14. Inside ansible_server enter the following

    ansible -i inventory all -m "shell" -a "touch sampleFile"
    
  15. sampleFile is created into the target_server check using ls.

  16. Not only creating files but also we can write shell commands after -a

    ansible -i inventory all -m "shell" -a "nproc"
    ansible -i inventory all -m "shell" -a "df"
    

    Conclusion :

    Ansible is a powerful yet simple tool for automating IT processes, making it easier to manage settings, deployments, and complex workflows. Ansible makes automation easier and more efficient by using simple YAML playbooks and an agentless architecture.

    Setting up password less SSH authentication between your Ansible server and target servers is a critical step toward easy and secure administration. By following the steps mentioned above, you ensure that your servers can interact seamlessly, allowing you to run commands and deploy apps without having to enter passwords repeatedly.

    Ansible's ease of use, scalability, and flexibility enable you to manage a wide range of IT automation jobs, from simple file operations to complicated orchestration.

    Happy Automating !

0
Subscribe to my newsletter

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

Written by

Reshma
Reshma

I'm an enthusiastic student investigating the dynamic area of DevOps, where I enjoy creating initiatives that combine technology with efficiency. My creative side shines through in design, as I use tools like Canva and Figma to bring ideas to life. I'm all about learning, experimenting, and closing the gap between automation and design.