LinuxCommandLibrary

ansible

TLDR

Ping all hosts in inventory

$ ansible all -m ping
copy
Execute a command on hosts
$ ansible [webservers] -a "uptime"
copy
Execute with sudo
$ ansible [webservers] -a "apt update" --become
copy
Run an ad-hoc module
$ ansible [hosts] -m [apt] -a "name=nginx state=present" --become
copy
Use specific inventory
$ ansible -i [inventory.ini] all -m ping
copy

SYNOPSIS

ansible pattern [-m module] [-a args] [-i inventory] [options]

DESCRIPTION

ansible is an agentless IT automation tool that executes tasks on remote systems over SSH. It uses a push-based model, requiring no software installation on managed nodes beyond Python and SSH access.
For ad-hoc commands, ansible executes modules against hosts matching a pattern. For complex automation, use ansible-playbook with YAML playbooks.

PARAMETERS

-m module

Module to execute (default: command)
-a args
Module arguments
-i inventory
Inventory file or path
--become
Run operations with privilege escalation
-K, --ask-become-pass
Prompt for privilege escalation password
-u user
Connect as this user
-k, --ask-pass
Prompt for SSH password
-f forks
Number of parallel processes
-v, -vvv
Increase verbosity
--check
Dry run (don't make changes)
--list-hosts
List hosts matching pattern

CAVEATS

Requires Python on managed nodes. SSH key-based authentication is recommended. Windows hosts require WinRM instead of SSH. Large inventories benefit from using ansible-playbook.

HISTORY

Ansible was created by Michael DeHaan and released in 2012. Red Hat acquired Ansible Inc. in 2015. It has become one of the most popular configuration management and automation tools.

SEE ALSO

Copied to clipboard