Getting Started with Configuration Management Using Ansible

Harsh SoniHarsh Soni
3 min read

Configuration management is an essential part of modern IT infrastructure, and tools like Ansible make it easy to automate repetitive tasks, ensure consistency, and manage configurations efficiently. In this blog, I’ll show you the steps to set up and use Ansible to manage a target server.

Step 1: Install Ansible on the Control Node

To begin, install Ansible on your control node. In this case, I’m using a Linux server with the apt package manager.

Commands to Install Ansible:

sudo apt-get update
sudo apt install ansible

Once the installation is complete, verify it:

ansible --version

Step 2: Create a Target Server

I created another EC2 instance, which will act as the Target Server. This is the server that Ansible will manage.

Step 3: Set Up Passwordless Authentication

Passwordless SSH authentication ensures that the control node can connect to the target server securely and seamlessly.

  • Copy the content of this newly generated public key into Target Server ‘authorized_keys’ and saved it

  • Go back to Ansible-server and try to connect with Target server without any password and you will successfully be able to connect.

Step 4: Create a File on the Target Server Using Ansible

To demonstrate Ansible’s power, let’s create a file on the target server from the control node.

  • Create an Inventory File:
    The inventory file lists all the target servers Ansible will manage. Create a file named inventory with the target server's IP address:

  • Run an Ad-hoc Command:
    Use the following command to create a file named devopsclass on the target server:

This command uses the shell module to execute a command on the target server.

ansible -i inventory -m “shell” -a “touch devopsclass”

Step 5: First Ansible Playbook

Ansible playbooks allow you to define a series of tasks in a structured YAML file. Let’s write a simple playbook to install Nginx on the target server.

first-playbook.yml:

Step 6: Execute the Playbook

Run the playbook using the following command:

ansible-playbook -i inventory first-playbook.yml

Step 7: Verify Nginx Installation

After executing the playbook, check whether Nginx is installed on the target server:


Bonus: Debugging with Verbose Mode

To get detailed logs and understand what’s happening internally, use the -vvv option:

bashCopy codeansible-playbook -vvv -i inventory first-playbook.yml

Verbose mode provides valuable insights for troubleshooting and debugging.


Conclusion

In this blog, we covered the basics of using Ansible for configuration management:

  • Installing Ansible

  • Setting up passwordless SSH authentication

  • Running ad-hoc commands

  • Writing and executing a playbook

Ansible’s simplicity and power make it an excellent tool for automating repetitive tasks and managing your infrastructure effectively. Stay tuned for more Ansible use cases in future blogs!

Happy Automating! 🚀


Join the community of learners and be a part of the conversation! Your feedback is valuable to us, so please share your thoughts in the comments section. Help us make this blog even better for everyone. And if you found this post helpful, spread the word! Share it with those who could benefit from the information. And don't forget to follow along and subscribe to our newsletter for instant updates on our latest content. Thank you for taking the time to read and engage with us!

0
Subscribe to my newsletter

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

Written by

Harsh Soni
Harsh Soni

👋 Hello! I'm Harsh, a DevOps enthusiast driven by a passion for continuous learning and innovation. With hands-on experience across cloud platforms, infrastructure tools, and programming languages, I'm committed to creating scalable, automated, and efficient solutions. Let’s connect, share knowledge, and build amazing things together! SKILLS: 🔹Languages & Runtimes: Python, C#, Shell Scripting, YAML 🔹Cloud Expertise: AWS (proficient in EC2, ELB, EBS, S3, VPC, Route53, SES, SNS, CloudFormation, CloudWatch) 🔹Infrastructure & DevOps Tools: Docker, Terraform, AWS CloudFormation 🔹Development & CI/CD: Linux, Git, GitHub Actions, Jenkins, Jira, GitLab (beginner), AWS DevOps 🔹Web Development: HTML, CSS, Bootstrap, .NET, Python, SQL Why Connect with Me? I'm a detail-oriented professional with strong communication skills, always ready to tackle complex problems with a positive mindset. Whether you’re here to network or explore potential collaborations, feel free to reach out. Let’s grow together in the DevOps journey! 📧 Contact Me: harshsoni6011@gmail.com