100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Ansible Cheat Sheet

Ansible Cheat Sheet

Reference for Ansible playbook YAML syntax, inventory files, common modules, and ad-hoc command usage for configuration management.

2 PagesIntermediateFeb 8, 2026

Basic Playbook

A playbook installing and starting nginx on web servers.

yaml
---- name: Configure web servers  hosts: webservers  become: true  vars:    http_port: 80  tasks:    - name: Install nginx      apt:        name: nginx        state: present        update_cache: true    - name: Start nginx      service:        name: nginx        state: started        enabled: true    - name: Copy config      template:        src: nginx.conf.j2        dest: /etc/nginx/nginx.conf      notify: restart nginx  handlers:    - name: restart nginx      service:        name: nginx        state: restarted

Inventory File

INI-style inventory grouping hosts.

ini
[webservers]web1.example.comweb2.example.com ansible_user=deploy[dbservers]db1.example.com[production:children]webserversdbservers[all:vars]ansible_ssh_private_key_file=~/.ssh/id_rsa

Ad-Hoc Commands & CLI

Common ansible and ansible-playbook CLI usage.

bash
ansible all -m ping                          # Check connectivityansible webservers -a "uptime"               # Run raw commandansible-playbook site.yml                    # Run a playbookansible-playbook site.yml --check            # Dry runansible-playbook site.yml -i inventory --tags deployansible-galaxy install geerlingguy.nginx     # Install a role

Common Modules

Frequently used built-in Ansible modules.

  • apt / yum- Manage packages on Debian-based or RHEL-based systems
  • copy / template- Copy files, or render Jinja2 templates, to remote hosts
  • service / systemd- Manage and enable system services
  • file- Manage file/directory state, permissions, and symlinks
  • user / group- Manage user accounts and groups
  • lineinfile- Ensure a particular line exists (or is absent) in a file
Pro Tip

Use 'ansible-vault encrypt secrets.yml' to store passwords and API keys encrypted at rest in your repo, then reference them normally in playbooks — Ansible decrypts them at runtime with --ask-vault-pass or a vault password file.

Was this cheat sheet helpful?

Explore Topics

#Ansible#AnsibleCheatSheet#DevOps#Intermediate#BasicPlaybook#InventoryFile#AdHocCommandsCLI#CommonModules#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet