ansible(1)
Run ad hoc commands and playbooks across remote hosts using SSH without requiring agents.
Synopsis
ansible [HOST-PATTERN] [OPTIONS] -m [MODULE]Description
Ansible is an agentless automation platform that executes commands and orchestrates configuration management, application deployment, and task execution across multiple remote systems. It uses SSH for transport and Python for execution, requiring no special daemons or agents on target hosts.
The command-line tool allows running ad hoc operations against inventory hosts using modules, while playbooks provide structured, reusable automation workflows. Ansible reads from an inventory file (default: /etc/ansible/hosts) to determine target hosts and their connection details.
Common options
| Flag | What it does |
|---|---|
-i INVENTORY | specify inventory file or dynamic inventory script (comma-separated hosts also work) |
-m MODULE | specify the module to execute (default: command) |
-a ARGS | pass arguments to the module |
-u USERNAME | connect as this user (default: current user or ansible_user from inventory) |
-k | prompt for SSH password |
-K | prompt for sudo password when using become |
-b, --become | run operations with become (escalate privileges, usually sudo) |
-e VARS | set additional variables as key=value or load from JSON file |
-f NUM | number of parallel processes to use (default: 5) |
-v | increase verbosity (use -vvv or -vvvv for more details) |
--syntax-check | check playbook syntax without executing |
--check | run in dry-run mode, no changes are made |
Examples
test connectivity to all hosts defined in inventory.ini using the ping module
ansible all -i inventory.ini -m pingrun the uptime command on all hosts in the 'webservers' group
ansible webservers -m command -a 'uptime'copy a file from the control machine to /tmp/backup/ on localhost
ansible localhost -m copy -a 'src=/tmp/file.txt dest=/tmp/backup/'restart postgresql service with sudo privileges on all db_servers
ansible db_servers -b -m service -a 'name=postgresql state=restarted'run disk usage command on a specific IP with SSH password prompt as ubuntu user
ansible 192.168.1.100 -u ubuntu -k -m shell -a 'df -h'execute playbook in dry-run mode with verbose output to see what would change
ansible-playbook site.yml -i hosts.ini -v --checkgather and display OS family facts for all hosts
ansible all -m setup -a 'filter=ansible_os_family'install nginx package in parallel (20 processes) on all hosts matching prod_* with sudo
ansible prod_* -f 20 -m apt -a 'name=nginx state=present' -b