Ansible is an open-source automation engine that automates software provisioning, configuration management, and application deployment. It is agentless, meaning no special software needs to be installed on the managed nodes, relying primarily on SSH for communication and Python for module execution.
## Control Node & Managed Nodes
The Control Node is the machine where Ansible is installed and executed. It's where you run `ansible` commands or `ansible-playbook`. Managed Nodes (also called hosts) are the target servers or devices that Ansible manages. Communication between the control node and managed nodes typically occurs over SSH.
## Inventory
The Inventory is a file (or set of files) that defines the managed nodes Ansible will operate on. It lists hosts, groups them, and can assign variables specific to hosts or groups. Inventories can be static (INI or YAML files) or dynamic (generated by scripts).
You can use the `ansible-inventory` command to view and manage your inventory.
## Modules & Tasks
Modules are the actual units of code Ansible executes on managed nodes. Each module is designed to perform a specific action, such as installing a package, managing a service, or copying a file. Modules are generally idempotent, meaning they can be run multiple times without causing unintended changes beyond the initial execution.
A Task is a call to an Ansible module with specific arguments. Tasks are defined within plays in a playbook.
## Playbooks & Plays
Playbooks are YAML formatted files that are the core of Ansible's configuration, deployment, and orchestration language. They contain one or more Plays.
A Play is a block within a playbook that maps a set of tasks to a specific group of hosts defined in the inventory. Each play targets a specific set of hosts and runs tasks on them.
```yaml
---
hosts: webservers
tasks:
ansible.builtin.dnf:
name: nginx
state: present
```
## Variables & Facts
Variables are used to store values that can be reused throughout playbooks, making them more dynamic and flexible. They can be defined in inventory, playbooks, or separate variable files.
Facts are pieces of information about managed nodes (e.g., operating system, IP addresses, memory) that Ansible gathers automatically using the `setup` module. These facts can be accessed as variables within playbooks and are useful for conditional logic or dynamic configuration.
## Plugins
Plugins extend Ansible's core functionality. Examples include: Connection plugins (how Ansible connects), Lookup plugins (fetch external data), Filter plugins (manipulate data), and Callback plugins (add new behaviors).