Jump to section

Learning Ansible basics

Copy URL

Ansible® is an open source IT automation engine that automates provisioning, configuration management, application deployment, orchestration, and many other IT processes.

Ansible can be used to install software, automate daily tasks, provision infrastructure and network components, improve security and compliance, patch systems, and orchestrate complex workflows.

Red Hat® Ansible Automation Platform is built on the same fundamentals as the community version of Ansible, but it provides full enterprise life cycle support and includes features designed to help organizations standardize, operationalize, and scale automation. 

This article will explain the basics that drive both community Ansible and Ansible Automation Platform.

Modules

Ansible works by connecting to nodes (or hosts) and pushing out small programs—called modules—to these nodes. Nodes are the target endpoints—servers, network devices, or any computer—that you aim to manage with Ansible. Modules are used to accomplish automation tasks in Ansible. These programs are written to be resource models of the desired state of the system. Ansible then executes these modules and removes them when finished.

Without modules, you’d have to rely on ad-hoc commands and scripting to accomplish tasks. Ansible contains built-in modules that you can use to automate tasks, or you can write new ones on your own. Ansible modules can be written in any language that can return JSON, such as Ruby, Python, or bash. Windows automation modules can even be written in Powershell. 

Agentless automation 

Ansible is agentless, which means the nodes it manages do not require any software to be installed on them. Ansible reads information about which machines you want to manage from your inventory. Ansible has a default inventory file, but you can create your own and define which servers you want to be managed. 

Ansible uses SSH protocol to connect to servers and run tasks. By default, Ansible uses SSH keys with ssh-agent and connects to remote machines using your current user name. Root logins are not required. You can log in as any user, and then use su or sudo commands as any user.

Once it has connected, Ansible transfers the modules required by your command or Ansible Playbook to the remote machine(s) for execution. Ansible uses human-readable YAML templates so users can program repetitive tasks to happen automatically without having to learn an advanced programming language.

Using Ansible for ad-hoc commands 

You can also use Ansible to run ad-hoc commands, which automate a single task on one or more managed nodes. To do this, you will need to run a command or call a module directly from the command line. No playbook is used, and ad-hoc commands are not reusable. This is fine for a one-time task, but anything more frequent or complex will require the use of an Ansible Playbook.

Ansible Playbooks are used to orchestrate IT processes. A playbook is a YAML file—which uses a .yml or .yaml extension—containing 1 or more plays, and is used to define the desired state of a system. This differs from an Ansible module, which is a standalone script that can be used inside an Ansible Playbook. 

Plays consist of an ordered set of tasks to execute against host selections from your Ansible inventory file. Tasks are the pieces that make up a play and call Ansible modules. In a play, tasks are executed in the order in which they are written.

When Ansible runs, it can keep track of the state of the system. If Ansible scans a system and finds the playbook description of a system and the actual system state don't agree, then Ansible will make whatever changes are necessary for the system to match the playbook. 

Ansible includes a check mode which allows you to validate playbooks and ad-hoc commands before making any state changes on a system. This shows you what Ansible would do, without actually making any changes. Handlers in Ansible are used to run a specific task only after a change has been made to the system. They are triggered by tasks and run once, at the end of all of the other plays in the playbook.

Variables enable you to alter how playbooks run to manage differences between systems, such as package versions or file paths. With Ansible, you can use a single command to execute playbooks across different systems. Variables account for the variations between these systems, and can be defined in playbooks, inventory, reusable files or roles, or at the command line. Variables follow variable precedence, which defines the order in which variables will override each other.

Ansible Roles are a special kind of playbook that are fully self-contained and portable groupings of tasks, variables, configuration templates, and other supporting files that are needed to complete a complex orchestration. Multiple roles can exist inside a collection, which allow content to be easily shared via Automation Hub and Ansible Galaxy.

Collections are a distribution format for Ansible content that can include playbooks, roles, modules, plugins, and documentation all in one bundle, making it easier for creators to share automation and use content created by others. These collections are sorted by content domain and require less upfront work to find and assemble different roles and modules.

Ansible Content Collections function in the same way, but are specifically designed to help Ansible Automation Platform users automate faster with prebuilt content from Red Hat and our certified partners. These collections—which include both Red Hat Ansible Certified Content and Ansible validated content—are developed and tested with partner input to ensure that they are security-focused, reliable, and enterprise-ready.

Learn about the difference between certified and validated content for Ansible and what they're used for. Video duration: 1:55.

Ansible is free to use, download, and modify—and the project benefits from the experience and intelligence of its thousands of contributors. The community distribution of Ansible contains a suite of powerful command line tools supported on most operating systems with Python installed. This includes Red Hat Enterprise Linux®, Debian, Ubuntu, MacOS, FreeBSD, Microsoft Windows, and more. 

Ansible Automation Platform combines more than a dozen upstream projects into a unified, security-hardened enterprise product. It builds on the foundations of community Ansible to create an end-to-end automation experience aimed at cross-functional teams—while providing a plug-and-play experience between automation developers, engineers, and operations teams.

Want to learn more about the differences between Ansible and Red Hat Ansible Automation Platform?

Ansible Basics: Automation Technical Overview

This series of on-demand, online videos introduces you to Ansible automation and configuration management, provisioning, deploying, and managing compute infrastructure across cloud, virtual, and physical environments with Ansible.

Red Hat Enterprise Linux Automation with Ansible 

This course will teach you how to automate Linux® system administration tasks with the latest version of Red Hat® Ansible Automation Platform. You will learn the techniques needed to use Ansible Automation Platform to automate provisioning, configuration, application deployment, and orchestration.

Find learning resources

Explore learning materials and tools designed to help you use Ansible Automation Platform, organized by the tasks you need to accomplish. These resources will guide you through deployment options, installation, how to get the most out of features, and use cases for applying automation to new challenges.

Get hands-on experience with interactive labs

These interactive scenarios provide a preconfigured Ansible Automation Platform environment that runs directly in your browser, so you can start learning how to automate for a variety of use cases—at your own pace.

Generative AI, the Ansible way

Red Hat has partnered with IBM to create Red Hat Ansible Lightspeed with IBM watsonx Code Assistant—a generative AI service that helps teams learn, create, and maintain automation content more efficiently. You can enter a task request in simple language, and Ansible Lightspeed interacts with IBM watsonx foundation models to generate code recommendations that can then be used to create Ansible Playbooks.

Provisioning

You can use Ansible Playbooks to describe the desired state of your infrastructure and then have Ansible Automation Platform provision it, so that you provision the same environments the same way, every time. This can be applied to building all of the infrastructure for your IT environment—from creating new instances across physical, cloud, or virtual landscapes, to adding new services, applications, compute hosts, or other resources—all within a single workflow.

Configuration management

Automating configuration management allows you to make changes and deployments faster, minimize human error, and make system management predictable and scalable. Maintaining computer systems, servers, and software in a desired, consistent state reduces the risk of security breaches, service degradation, or even outages. And IT teams are able to spend less time manually applying patches and updates and more time on higher impact projects.

Network automation

Network automation uses programmable logic to manage network resources and services, allowing network operations (NetOps) teams to configure, scale, protect, and integrate network infrastructure and application services more quickly than when performed manually.

Application deployment

Automating application deployment allows you to move your software between testing and production environments with coordinated processes. This speeds up the software delivery cycle, and improves the reliability of your applications in production. It's an essential piece of enabling DevOps practices and managing a CI/CD pipeline.

Security automation

Security automation integrates security processes, applications, and infrastructure into a single worksteam. It can help make security operations (SecOps) more efficient, while reducing inconsistencies and errors that lead to security breaches and other threats. Using Ansible Automation Platform, security teams can configure a sequence of jobs that share inventory, playbooks, or permissions to fully automate investigations or remediations.

Orchestration

Automating a single task has limited benefits, which is why an automation solution, like Ansible Automation Platform, allows you to easily set up and automate a workflow that involves many steps, coordinated across multiple disparate systems—such as infrastructure, networking devices, and security tools. Orchestration also improves communication across different IT teams.

Accelerate your IT with Automation as Code

Ansible Automation Platform is often used to automate Infrastructure as Code (IaC) tasks like building, provisioning, and deploying infrastructure, but it can also be used to automate processes across the entire operational life cycle. With a unified automation platform that includes event-driven capabilities, organizations can now extend IaC practices into Ops as Code and Policy as Code.

Learn how

Red Hat Ansible Automation Platform includes all the tools you need to implement enterprise-wide automation, including an event-driven solution, playbooks, and analytics. It allows you to centralize and control your IT infrastructure with a visual dashboard, role-based access control, and more features designed to reduce operational complexity.

With a Red Hat subscription, you get certified content from our robust partner ecosystem, access to hosted management services, and life cycle technical support that allows your teams to create, manage, and scale automation across your organization. And you’ll get expert knowledge gained from our success with thousands of customers.

Organizations not only need the ability to easily create automation, but they also need to be able to share and reuse automation across projects and teams with the right level of governance and control. With Ansible Automation Platform, you can deploy new applications and services faster, manage IT infrastructure more efficiently, and increase application development productivity.

Icon-Red_Hat-Media_and_documents-Quotemark_Open-B-Red-RGB The built-in capabilities of Red Hat Ansible Automation Platform provide an accelerator in a box. It’s the de facto standard that many of our vendors and partners also use to write scripts to install, configure, and maintain their technology.

Jesse Amerson

IT director, Ulta Beauty

Keep reading

Article

Learning Ansible basics

Ansible automates IT processes like provisioning and configuration management. Learn the basics of Ansible with this introduction to key concepts.

Article

What's an Ansible Playbook?

An Ansible Playbook is a blueprint of automation tasks, which are IT actions executed with limited manual effort across an inventory of IT solutions.

Article

Why choose Red Hat for automation?

Red Hat Ansible Automation Platform includes all the tools needed to share automation across teams and implement enterprise-wide automation.

More about automation

Products

Engagements with our strategic advisers who take a big-picture view of your organization, analyze your challenges, and help you overcome them with comprehensive, cost-effective solutions.

A platform for implementing enterprise-wide automation, no matter where you are in your automation journey

Resources

Podcast

Command Line Heroes Season 3, Episode 5:
"The infrastructure effect"

E-book

The automated enterprise: Unify people and processes

E-Book

Automate infrastructure workflows

Training

Free training course

Ansible Essentials: Simplicity in Automation Technical Overview

Free training course

Red Hat Ansible Automation for SAP