Show Menu
Cheatography

Ansible Cheat Sheet (DRAFT) by

Ansible Commands Guide

This is a draft cheat sheet. It is a work in progress and is not finished yet.

ansible (ad-hoc command)

# Syntax
ansible <ho­sts> -m <mo­dul­e> -a "­<module argume­nts­>"
Executes a single task on one or more hosts.
# Ping all servers
ansible all -m ping
# Execute a shell command
ansible webservers -m shell -a "­upt­ime­"
# Check disk space
ansible all -m shell -a "df -h"

ansibl­e-i­nve­ntory

View entire inventory in JSON format
ansibl­e-i­nve­ntory --list
View inform­ation for a specific group
ansibl­e-i­nve­ntory --graph webservers
Export inventory to YAML
ansibl­e-i­nve­ntory --list -y
El inventario define los hosts y grupos sobre los que Ansible ejecutará las tareas.
Caract­erí­sticas del Invent­ario:
- Puede ser estático (archivo) o dinámico (script)
- Soporta grupos y subgrupos
- Permite definir variables por host y por grupo
- Puede tener múltiples invent­arios (produ­cción, staging, desarr­ollo)

ansibl­e-vault

Create new encrypted file
ansibl­e-vault create secret­s.yml
Encrypt existing file
ansibl­e-vault encrypt vars.yml
Edit encrypted file
ansibl­e-vault edit secret­s.yml
Decrypt file
ansibl­e-vault decrypt secret­s.yml
View content without decrypting
ansibl­e-vault view secret­s.yml
Encrypts and decrypts sensitive files.

ansibl­e-vault

Create new encrypted file
ansibl­e-vault create secret­s.yml
Encrypt existing file
ansibl­e-vault encrypt vars.yml
Encrypts and decrypts sensitive files.
 

ansibl­e-p­laybook

Basic syntax
ansibl­e-p­laybook [options] playbo­ok.yml
Run a playbook
ansibl­e-p­laybook site.yml
Run in check mode (simul­ation)
ansibl­e-p­laybook site.yml --check
Run with extra variables
ansibl­e-p­laybook site.yml --extr­a-vars "­var­iab­le=­val­ue"
# Run limiting to certain hosts
ansibl­e-p­laybook site.yml --limit webservers
Los playbooks son archivos YAML que definen la config­uración deseada y las tareas a ejecutar.
Caract­erí­sticas de los Playbooks:
- Definen una serie de plays (jugadas)
- Cada play asocia hosts con roles y tareas
- Pueden incluir variables, handlers y roles
- Soportan condic­ionales y bucles
- Permiten reutil­ización de código

ansibl­e-doc

List all modules
ansibl­e-doc -l
View docume­ntation for a specific module
ansibl­e-doc apt
View usage examples for a module
ansibl­e-doc -s copy
Shows module docume­nta­tion.