Posts

Showing posts with the label Ansible

Ansible Jinja Templates Explained with Real world examples

Image
Here I'm starting this post with famous ARISTOTLE quote. "We are what we repeatedly do. Excellence, then is not an act, but a Habit" Welcome back Ansible Automations and who are habituated as Ansible automation specialists this post for them to give boosted walk through, In this post why Jinja templates, When managing hundreds of Linux servers, it becomes difficult to maintain separate configuration files for each environment. Development, Testing, UAT, and Production environments often require different values such as hostnames, IP addresses, ports, memory settings, and application URLs. Instead of creating multiple configuration files manually, Ansible uses Jinja2 Templates to dynamically generate configuration files during deployment. Jinja2 allows variables, loops, conditions, and filters to be embedded within template files so that a single template can be reused across multiple systems.  I would like to share my experiments with Jinja2 templates usage on the Ansibl...

Ansible Automations Designing & Implementation | Best Practices for DevOps, DevSecOps, SRE, and Automation Architects

Image
Hello DevOps, DevSecOps Engineers, SREs, and Automation Enthusiasts! Over the years of building automation solutions using Ansible, AWX, and Red Hat Ansible Automation Platform , I have learned that successful automation is not only about writing playbooks. The real challenge lies in designing maintainable, scalable, and production-ready automation that multiple teams can safely execute. This article consolidates practical lessons, architecture patterns, performance improvements, and operational best practices that I have successfully applied in enterprise environments. Whether you are building your first automation workflow or managing thousands of servers through AWX, these recommendations can help improve reliability, maintainability, and execution performance. A Successful Automation Strategy Why Automation Projects Fail Many automation initiatives start with enthusiasm but gradually become difficult to maintain because of: Poor documentation Hardcoded values Lack of te...

Ansible powerful parameters - delegate_to, connection

  Delegation to a host Here is an example where we can delegate the task to a particular host. This play book is using inventory_hostname from the gather facts. - name: Delegation to localhost hosts: all tasks: - name: create a file on target server file: path: /tmp/i_m_on_target_server.txt state: touch - name: create a file with host named file by delegation to localhost file: state: touch path: "/tmp/{{ inventory_hostname }}.txt" delegate_to: localhost connection paramer We can use this "connection" parameter add to your task level or play level. # Filename: connection_local.yml # To do some task on ansible server # local means without doing ssh command (no need of password and no need of ssh keys) # with the local connection parameter for the play --- - name: This is to determine how the connection parameter works with local hosts: app connection: local gather_facts: false tasks: - name: connecti...

Ansible Vault - To save Secrets

Image
Hello DevOps Automations Engineers!!  Ansible provides us special command 'ansible-vault' that is used to encrypt, decrypt, view an Ansible  playbook, this is also have amazing feature specific to role, vars YAML files, we can apply this to string of text in regular variables.  Why do we need to encrypt our Play books? Our Ansible automation projects, we need to work on multiple tasks and which may have some sensitive data such as database user credentials, any cloud IAM role details or it can be some other applications login credentials that's used to validate URL availability. Or it can be used to store the SSL certificates. At any point of time if the system is using plain text and it  has trouble to your confidential and sensitive data otherwise it could causes huge damage to your organization. Where we need a way to store the sensitive data can be protected by data encryption  tool, and this can be done using the Ansible-vault command.  Le...

Ansible Handlers and Notify Explained with Examples – Restart Services Only When Changes Occur

Image
Hello DevOps Experts!! let's zoom  into the usage of the Ansible Handlers and notifies   Have you ever restarted a service in Ansible even though nothing actually changed? Many beginners add service restart tasks directly into their playbooks. While this works, it can cause unnecessary service interruptions, increase deployment times, and introduce avoidable downtime. Ansible provides a smarter mechanism called Handlers , which execute only when a task reports a change. Combined with the notify directive, handlers help build efficient, idempotent, and production-ready automation. In this article, we'll explore how Ansible Handlers work, when to use them, and common DevOps use cases. What We'll Learn By the end of this article, you will understand: What Ansible Handlers are Why handlers are important How the notify keyword works When handlers are triggered How multiple tasks can notify a single handler Real-world DevOps use cases Best practices for handle...

Ansible real-time project - Installing and configure Tomcat 10

Image
 Hey DevOps or DevSecOps or SRE Guys!! What's up? in the automation journey one more wonderful learning here!  In this post we will be implementing all our Ansible modules one after other to build a complete solution for Java based Application server installation and running using Ansible playbook. At present Tomcat latest version is 10.0.27 so I've used same  Pre-requisites:  To install Apache Tomcat there is separate JDK/JRE compatibility we need to validate before we proceed Create a dedicated user account as 'tomcat' with shell as bash  to manage Tomcat application server Create a separate directory for tomcat server to be installed Execution of multiple tasks in the Playbook will be as follows: Download the Tomcat software from Apache Tomcat 10.0.27.tar.gz Uncompressing the tomcat tar.gz file Change the file permissions and ownership Cleanup after unarchive the tar.gz file Start the Tomcat server Have a task to stop the Tomcat server --- - n...

Ansible Tags - Controls Tasks

Image
 Ansible playbook can be a construct of multiple plays or each play may contains multiple tasks. This is where we may have situation where you need to add new task to the existing play or playbook, and we need to test many times that newly added task.  While testing multiple times we many don't want to execute certain tasks such as a task 'Send email notification' when you preparing a 'Reboot of server' or 'Restart of Service' or 'Deployment of a service'. During the testing time you may want to exclude these notification tasks.  There are situations where we might want to run a particular task as per the input at the run time of a playbook. This may be from AWX/Tower UI select them. Ansible tags - to control the tasks of a Playbook I will be explaining in this post, How to run or not to run a particular task in given  playbook.  Important concepts about Ansible tags Ansible tags are keys to identify and control the tasks for execution or exclude fr...

Ansible Facts - Customizations

Image
Hey DevOps Team, In this post I would like to give you the knowledge on the special feature about Ansible Facts and we can also customize these facts as global variables to use in multiple playbooks. What is ansible facts?  Ansible facts are just simple variables that are automatically discovered by ansible on a managed nodes. such as system information disk info, os info, package info IP Network and many more ... Why we manage facts? Default these facts will be automatically collected exclusively we need to disable some times. - multiple play in a playbook How can we use facts? we want to run only when enough memory is available on the target machine then install the package. That is the smartest way to do the automation! --- # File : hello.yaml - name: Facts example hosts: "{{targets|default('localhost')}}" tasks: - name: prints details debug: msg: "Hello this machine have {{ ansible_memory_mb['real'] }}" whe...