Catalog / Ansible Essentials Cheatsheet
Ansible Essentials Cheatsheet
A concise guide to Ansible, covering essential concepts, commands, and best practices for automating infrastructure and application deployment. Includes playbook structure, module usage, and task management.
Getting Started with Ansible
Installation & Setup
Install Ansible:
Verify Installation:
|
Configure Hosts File (
|
SSH Key Configuration:
|
Basic Commands
|
Verify connectivity to all managed hosts. |
|
Execute the |
|
Run an Ansible playbook. |
Ansible Configuration File
The Ansible configuration file (
|
Playbook Essentials
Playbook Structure
A playbook is a YAML file containing one or more plays. Each play defines tasks to be executed on a set of hosts.
|
Tasks
|
A descriptive name for the task. |
|
The Ansible module to be executed (e.g., |
|
Parameters for the module. |
|
Escalate privileges (sudo). |
|
Specify the user for privilege escalation. |
|
Store the task’s output in a variable. |
Handlers
Handlers are tasks that are only run when notified by another task. They are typically used for restarting services after configuration changes.
|
Variables & Templates
Defining Variables
Variables can be defined in several places:
|
Variable Precedence
Ansible uses a specific order of precedence when resolving variables. From highest to lowest:
|
Templates
Templates allow you to dynamically generate configuration files using Jinja2 templating. They are useful for customizing configurations based on variables.
|
Advanced Features
Roles
Roles are a way to organize and reuse Ansible code. A role typically includes tasks, handlers, variables, and templates.
Directory structure:
|
Includes
|
Include a list of tasks from another file. |
|
Include variables from another file. |
|
Statically include a task list at playbook parse time. |
Conditionals
Tasks can be conditionally executed using
|