cheatsheet

Ansible Commands Cheatsheet

Quick reference for Ansible commands - inventory, playbooks, and common operations.

Published: December 4, 2024

Ansible Commands Cheatsheet

Ansible is an automation tool for configuration management, application deployment, and task automation.


Inventory

List Dynamic Inventory

ansible-inventory -i <inventory-path> --list

Playbooks

Run a Playbook

ansible-playbook -i <inventory-path> <playbook>.yml -t <tag> --user=<user>

Common Options

OptionDescription
-iSpecify inventory file
-tRun only tagged tasks
--userSSH user
-v, -vv, -vvvVerbosity levels
--checkDry run (don’t make changes)
--diffShow differences
-eExtra variables

Quick Reference

TaskCommand
List inventoryansible-inventory -i inv --list
Run playbookansible-playbook -i inv playbook.yml
Dry runansible-playbook --check playbook.yml
Single taskansible all -m ping -i inv
Ad-hoc commandansible all -a "uptime" -i inv

Ad-Hoc Commands

# Ping all hosts
ansible all -m ping -i inventory

# Run shell command
ansible all -a "df -h" -i inventory

# Copy file
ansible all -m copy -a "src=/local/file dest=/remote/file" -i inventory

# Install package
ansible all -m apt -a "name=nginx state=present" -i inventory

Tags

ansibledevopsautomationconfiguration-management

Found this useful?

Subscribe to get more cheatsheets and resources.