
This is a cheat sheet for basic Ansible commands that vSphere Tanzu / VCF Automation admins can use daily.
Inventory & Host Discovery
| Command | Description |
|---|
ansible-inventory --list | Show full inventory |
ansible-inventory --graph | Same as above; alternative syntax. |
| ansible-inventory –host <hostname> | Show host variables |
ansible all -m ping | Ping all hosts |
ansible -m ping | Ping a specific group |
Ad-Hoc Commands
- shell = run anything you’d type in bash
- command = run a single command, no shell, no pipes, no magic
| Command | Description |
|---|
ansible all -m shell -a "uptime" | Run shell command |
ansible ubuntu -m command -a "df -h" | Run anything to query on Ubuntu host group |
| ansible centos -m shell -a “ifconfig” | Run command on centos host group |
| ansible all -m copy -a “src=/tmp/a dest=/tmp/b” | Create directory |
| ansible all -m file -a “path=/tmp/test state=directory” | View logs for a specific pod. |
Package Management
| Command | Description |
|---|
ansible ubuntu -m apt -a "name=htop state=present" | Install package on (Ubuntu) host group |
| ansible ubuntu -m apt -a “update_cache=yes” | Update apt cache on (Ubuntu) host group |
| ansible centos -m dnf -a “name=git state=present” | Install package on (CentOS)host group |
| ansible centos -m yum -a “name=curl state=absent” | Remove package on (CentOS) host group |
| ansible gitlab -m package -a “name=git state=absent” | Remove package from gitlab host |
Running Playbooks
| Command | Description |
|---|
ansible-playbook site.yml | Run playbook |
| ansible-playbook install-packages.yml -l ubuntu | Limit to Ubuntu group |
| ansible-playbook deploy.yml –tags apache | Run only tagged tasks |
| ansible-playbook upgrade.yml –check | Dry run |
Syntax, Linting & Debugging
| Command | Description |
|---|
ansible-playbook site.yml --syntax-check | Validate syntax |
ansible-playbook site.yml -vvv | Verbose debug |
(Visited 7 times, 1 visits today)
Ash Thomas is a seasoned IT professional with extensive experience as a technical expert, complemented by a keen interest in blockchain technology.