DEV Community

Janak Shrestha
Janak Shrestha

Posted on

Ansible Ping Module Usage

The Nautilus DevOps team is planning to test several Ansible playbooks on different app servers in Stratos DC. Before that, some pre-requisites must be met. Essentially, the team needs to set up a password-less SSH connection between Ansible controller and Ansible managed nodes. One of the tickets is assigned to you; please complete the task as per details mentioned below:

a. Jump host is our Ansible controller, and we are going to run Ansible playbooks through thor user from jump host.

b. There is an inventory file /home/thor/ansible/inventory on jump host. Using that inventory file test Ansible ping from jump host to App Server 3, make sure ping works.


Introduction

In modern DevOps environments, automation is key to maintaining efficiency and consistency across infrastructure. Ansible, a powerful configuration management tool, enables teams to manage multiple servers seamlessly. However, before running playbooks, establishing password-less SSH connectivity between the Ansible controller and managed nodes is essential for smooth operations.

Recently, I completed a task for the Nautilus DevOps team to set up password-less SSH access from the jump host (Ansible controller) to App Server 3 in the Stratos DC. This blog post outlines the process and the successful outcome.


The Setup Process

Step 1: Creating the Inventory File

First, we created the inventory file at /home/thor/ansible/inventory containing all three application servers:

[app_servers]
stapp01 ansible_user=tony ansible_ssh_pass=Ir0nM@n ansible_ssh_common_args='-o StrictHostKeyChecking=no'
stapp02 ansible_user=steve ansible_ssh_pass=Am3ric@ ansible_ssh_common_args='-o StrictHostKeyChecking=no'
stapp03 ansible_user=banner ansible_ssh_pass=BigGr33n ansible_ssh_common_args='-o StrictHostKeyChecking=no'
Enter fullscreen mode Exit fullscreen mode

Step 2: Generating SSH Key Pair

Since no SSH keys existed on the jump host, we generated a new RSA key pair:

ssh-keygen -t rsa -b 2048 -N "" -f ~/.ssh/id_rsa
Enter fullscreen mode Exit fullscreen mode

This created both the private key (id_rsa) and public key (id_rsa.pub) in the .ssh directory.

Step 3: Copying the SSH Key to App Server 3

Using sshpass, we securely copied the public key to App Server 3:

sshpass -p 'BigGr33n' ssh-copy-id -o StrictHostKeyChecking=no banner@stapp03
Enter fullscreen mode Exit fullscreen mode

The command successfully installed the key, enabling password-less authentication for future connections.

Step 4: Verifying Password-less SSH

To confirm the setup worked, we tested the SSH connection without a password prompt:

ssh -o StrictHostKeyChecking=no banner@stapp03 "echo 'SSH connection successful'"
Enter fullscreen mode Exit fullscreen mode

The output confirmed success: SSH connection successful

Step 5: Updating the Inventory

With password-less SSH now working, we updated the inventory file to remove the password parameter for stapp03:

stapp03 ansible_user=banner ansible_ssh_common_args='-o StrictHostKeyChecking=no'
Enter fullscreen mode Exit fullscreen mode

Step 6: Testing Ansible Ping

The final step was to run the Ansible ping test:

cd /home/thor/ansible
ansible -i inventory stapp03 -m ping
Enter fullscreen mode Exit fullscreen mode

Key Takeaways

  • Password-less SSH is a fundamental requirement for Ansible automation, eliminating manual password entry and enabling seamless playbook execution.
  • SSH Key Management is straightforward with tools like sshpass and ssh-copy-id, which streamline the key distribution process.
  • Inventory Flexibility allows teams to maintain different authentication methods for different servers, accommodating various security requirements.

Conclusion

The Nautilus DevOps team can now proceed with their Ansible playbook testing on App Server 3 without authentication barriers. This setup lays the foundation for efficient configuration management across the entire Stratos DC infrastructure. The success of this task demonstrates the reliability of Ansible's ping module and the effectiveness of password-less SSH authentication in DevOps workflows.

Top comments (0)