Ansible 2 cheatsheet

Ansible 2: Inventory, roles and collections

8 common Ansible 2 tasks.

Show the inventory

Print the inventory as JSON, with variables.

ansible-inventory -i inventory.ini --list

Show the inventory as a tree

Print the groups and hosts as a tree.

ansible-inventory -i inventory.ini --graph

Install a role

Download a role from Ansible Galaxy.

ansible-galaxy role install geerlingguy.nginx

Install a collection

Download a collection from Ansible Galaxy.

ansible-galaxy collection install community.general

Install from a requirements file

Install the roles and collections listed in requirements.yml.

ansible-galaxy install -r requirements.yml

Create a role skeleton

Create the standard folder layout for a role.

ansible-galaxy role init my_role

Read module documentation

Show a module's options and examples in the terminal.

ansible-doc ansible.builtin.copy

Lint playbooks

Check playbooks for style problems and common mistakes. Needs ansible-lint installed.

ansible-lint site.yml

Was this page helpful?