Basic Commands
Command | Description |
---|---|
ansible <hostname> -m ping | Test connectivity to a host |
ansible-playbook <playbook>.yml | Run an Ansible playbook |
ansible-vault create <filename>.yml | Create a new encrypted file |
ansible-vault edit <filename>.yml | Edit an encrypted file |
ansible-vault view <filename>.yml | View an encrypted file |
Inventory Management
Command | Description |
---|---|
ansible-inventory --list | Display the inventory |
ansible-inventory --graph | Display the inventory as a graph |
ansible-inventory --host <hostname> | Display information for a specific host |
ansible-inventory --yaml --host <hostname> | Display the YAML for a specific host |
Playbooks
Command | Description |
---|---|
hosts: <hostname> | Specify the target host(s) for the playbook |
gather_facts: true | Gather facts about the target host(s) |
tasks: | Define a list of tasks to be executed |
when: <condition> | Execute a task conditionally |
vars: | Define variables for use in the playbook |
roles: | Include a role in the playbook |
include_vars: | Include variables from an external file |
Modules
Module | Description |
---|---|
file | Manage files and directories |
apt | Manage packages on Ubuntu/Debian systems |
yum | Manage packages on CentOS/Red Hat systems |
service | Manage system services |
user | Manage system users and groups |
copy | Copy files from the control node to the target hosts |
template | Copy template files from the control node to the target hosts and substitute variables |
lineinfile | Manage lines in text files |
command | Run a command on the target hosts |
shell | Run a shell command on the target hosts |
cron | Manage cron jobs on the target hosts |
iptables | Manage firewall rules on the target hosts |
wait_for | Wait for a specific condition to be met |
debug | Display debug information |