Ansible Quick Start Guide | Generated by AI

Home 2025.12

No worries! The ansible --help output is indeed scary, but 99% of the time you only need a few options.

Here’s the absolute simplest “getting started” way to use ansible ad-hoc (without writing a playbook) in 2025.

1. Quickest possible test (run on localhost, no SSH, no inventory)

ansible localhost -m ping

Output you should see:

localhost | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

Congratulations — Ansible is working!

2. Run a command on one remote server (most common beginner case)

Assume:

ansible 192.168.1.100 -m command -a "uptime" -u ubuntu --private-key ~/.ssh/id_rsa

Or even shorter (if your SSH key is already in ssh-agent and user is correct in ~/.ssh/config or default):

ansible 192.168.1.100 -m command -a "uptime"

3. Run the same command on many servers at once

Just give a comma-separated list or a pattern:

ansible 192.168.1.10,192.168.1.11,192.168.1.12 -m command -a "df -h"

# or with a wildcard if you use an inventory file later
ansible webservers -m ping

4. Most useful beginner one-liners you’ll use every day

# Check which hosts are reachable
ansible all -m ping

# Reboot all servers and wait for them to come back
ansible all -m reboot --forks 20

# Update all packages (Debian/Ubuntu)
ansible all -m apt -a "name=* state=latest" -b

# Update all packages (RHEL/CentOS/Rocky/Fedora)
ansible all -m dnf -a "name=* state=latest" -b
# or yum on older systems
ansible all -m yum -a "name=* state=latest" -b

# Copy a file to all servers
ansible all -m copy -a "src=./motd dest=/etc/motd backup=yes" -b

# Run a raw shell command with sudo
ansible all -m shell -a "tail -20 /var/log/syslog" -b

The -b means “become root” (like sudo). Add -K if it asks for your sudo password:

ansible all -m apt -a "name=* state=latest" -b -K

Create a file called inventory.ini in your current directory:

[webservers]
web1.example.com
web2.example.com
web3.example.com

[dbservers]
db1.example.com ansible_user=centos ansible_ssh_private_key_file=~/.ssh/special.pem

Then just do:

ansible webservers -m ping -i inventory.ini

or put it in ~/.ansible/hosts or /etc/ansible/hosts and you can skip -i completely.

TL;DR — The 3 commands you need to remember as a beginner

# 1. Test locally
ansible localhost -m ping

# 2. Test remote servers (replace IP or hostname)
ansible your.server.com -m ping

# 3. Do something useful (example: update everything)
ansible all -m apt -a "name=* state=latest" -b    # Ubuntu/Debian
# or
ansible all -m dnf -a "name=* state=latest" -b    # RHEL 8+/Rocky/Fedora

That’s it! Once you’re comfortable with these, you’ll naturally graduate to real playbooks. But ad-hoc commands with ansible will already save you hours every week. 🚀

Let me know what you want to do next (update servers, deploy a file, install Docker, etc.) and I’ll give you the exact one-liner!


Back

x-ai/grok-4.1-fast

Donate