Understanding Ansible Basics
What is Ansible?
Ansible is an open-source software provisioning, configuration management, and application-deployment tool. It enables infrastructure as code, where infrastructure settings are stored in version control and can be easily replicated. Ansible uses a simple, human-readable language called YAML to describe desired system configurations.
Ansible Architecture
Ansible follows a client-server architecture, where the control node (the machine running the Ansible commands) communicates with the managed nodes (the target machines) over SSH. Ansible does not require any special software to be installed on the managed nodes, as it uses the existing SSH connection to execute tasks.
graph TD
A[Control Node] -- SSH --> B[Managed Node 1]
A -- SSH --> C[Managed Node 2]
A -- SSH --> D[Managed Node 3]
Ansible Modules
Ansible provides a wide range of built-in modules that can be used to perform various tasks, such as managing files, packages, services, and more. Modules are the building blocks of Ansible playbooks, which are YAML files that describe the desired state of the infrastructure.
Ansible Playbooks
Ansible playbooks are YAML files that define the tasks to be executed on the managed nodes. Playbooks can include variables, conditionals, and loops to make them more flexible and reusable.
- hosts: all
tasks:
- name: Create a directory
file:
path: /tmp/example
state: directory
Ansible Inventory
The Ansible inventory is a file that defines the managed nodes and their connection details, such as the hostname, IP address, and SSH credentials. Ansible supports various inventory formats, including static files and dynamic sources like cloud providers.