# Ansible
> Automate IT infrastructure provisioning and configuration

## Summary
Agentless IT automation. Define infrastructure and configuration as YAML playbooks, push changes over SSH to any number of servers. No agent required on managed nodes. Supports cloud provisioning, app deployment, and configuration management.

## Capabilities
- Configure servers and services using declarative YAML playbooks
- Manage hundreds of servers without installing agents
- Provision cloud resources on AWS, GCP, Azure, and others
- Orchestrate multi-step deployment workflows with roles and playbooks
- Manage secrets with Ansible Vault encryption
- Run ad-hoc commands across an inventory of servers
- Create reusable roles and share them via Ansible Galaxy

## When to Use
- Configuring and managing multiple servers consistently
- Automating application deployments across environments
- Need agentless configuration management over SSH
- Orchestrating complex multi-step provisioning workflows
- Managing cloud infrastructure alongside server configuration

## When NOT to Use
- Managing a single local machine only (overkill for simple tasks)
- Need real-time infrastructure state tracking (use Terraform for state management)
- Windows-only environments where PowerShell DSC is preferred

## Key Flags
- `-i`: Specify the inventory file or host list
- `-m`: Module to execute (e.g., ping, shell, copy, apt)
- `-a`: Module arguments
- `--become / -b`: Run operations with privilege escalation (sudo)
- `--check`: Dry run — show what would change without making changes
- `--vault-password-file`: Provide the password file for Ansible Vault

## Usage Patterns
### Ping all hosts
```
ansible all -m ping -i inventory.ini
```
Tests connectivity to all hosts in the inventory

### Run a playbook
```
ansible-playbook -i inventory.ini site.yml --become
```
Executes a playbook with sudo privileges on all targeted hosts

### Run an ad-hoc command
```
ansible webservers -m shell -a 'uptime' -i inventory.ini
```
Runs the uptime command on all hosts in the webservers group

### Encrypt a file with Vault
```
ansible-vault encrypt secrets.yml
```
Encrypts a YAML file containing sensitive variables

## Input / Output
- **stdin**: Vault passwords, confirmation prompts
- **stdout**: Task results, changed/ok/failed status per host

## Installation
- **pip**: `pip install ansible`
- **homebrew**: `brew install ansible`
- **apt**: `sudo apt install ansible`

## Related Tools
- [terraform](/tools/terraform) (complementary): Terraform provisions infrastructure, Ansible configures it
- [aws-cli](/tools/aws-cli) (complementary): Ansible can use AWS modules; aws-cli for direct API commands
- [docker](/tools/docker) (complementary): Ansible can manage Docker containers and build images

---
Source: https://littlescripts.sh/tools/ansible
