Part 7 – Ansible Commands You’ll Use Most in a VCF Job

This is a cheat sheet for basic Ansible commands that vSphere Tanzu / VCF Automation admins can use daily.

Inventory & Host Discovery

CommandDescription
ansible-inventory --listShow full inventory
ansible-inventory --graphSame as above; alternative syntax.
ansible-inventory –host <hostname>Show host variables
ansible all -m pingPing all hosts
ansible -m pingPing 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
CommandDescription
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

CommandDescription
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

CommandDescription
ansible-playbook site.ymlRun playbook
ansible-playbook install-packages.yml -l ubuntuLimit to Ubuntu group
ansible-playbook deploy.yml –tags apacheRun only tagged tasks
ansible-playbook upgrade.yml –checkDry run

Syntax, Linting & Debugging

CommandDescription
ansible-playbook site.yml --syntax-checkValidate syntax
ansible-playbook site.yml -vvvVerbose debug
(Visited 7 times, 1 visits today)

By Ash Thomas

Ash Thomas is a seasoned IT professional with extensive experience as a technical expert, complemented by a keen interest in blockchain technology.