Ansible | Sheetly Cheat Sheet

Last Updated: November 21, 2025

Ansible

IT automation and configuration management

Core Concepts

Item Description
Playbook YAML file defining automation tasks
Task Single action to execute
Role Reusable automation unit
Inventory List of managed hosts
Module Reusable script for tasks
Handler Task triggered by changes
Fact System information variable

Common Commands

ansible all -m ping
Test connectivity to hosts
ansible-playbook playbook.yml
Run playbook
ansible-playbook playbook.yml --check
Dry run mode
ansible-galaxy install role_name
Install role from Galaxy
ansible-vault encrypt file.yml
Encrypt sensitive data

Playbook Example

---
- name: Configure web servers
  hosts: webservers
  become: yes

  vars:
    http_port: 80
    max_clients: 200

  tasks:
    - name: Install nginx
      apt:
        name: nginx
        state: present
        update_cache: yes

    - name: Copy nginx config
      template:
        src: templates/nginx.conf.j2
        dest: /etc/nginx/nginx.conf
      notify: restart nginx

    - name: Start nginx service
      service:
        name: nginx
        state: started
        enabled: yes

  handlers:
    - name: restart nginx
      service:
        name: nginx
        state: restarted

Best Practices

  • Use roles to organize complex playbooks
  • Encrypt sensitive data with ansible-vault
  • Use tags for selective task execution
  • Test playbooks in check mode first

💡 Pro Tips

Quick Reference

Use ansible-vault to secure sensitive variables

← Back to DevOps & Cloud | Browse all categories | View all cheat sheets