Ansible 2 cheatsheet
Ansible 2: Playbooks
10 common Ansible 2 tasks.
Dry run with diff
Show what would change, without changing anything.
ansible-playbook -i inventory.ini site.yml --check --diff
Check playbook syntax
Check the playbook for syntax errors without running it.
ansible-playbook site.yml --syntax-check
Limit to some hosts
Run only against one host or group from the play.
ansible-playbook -i inventory.ini site.yml --limit web1
Run only tagged tasks
Run tasks that have a given tag.
ansible-playbook -i inventory.ini site.yml --tags deploy
Pass variables
Set a variable on the command line, which overrides other sources.
ansible-playbook site.yml -e "app_version=1.4.2"
Ask for the sudo password
Prompt for the password used for privilege escalation.
ansible-playbook -i inventory.ini site.yml --ask-become-pass
Increase verbosity
Show connection details. Add more v's for more detail.
ansible-playbook -i inventory.ini site.yml -vvv
List the tasks in a playbook
Show the tasks and hosts without running anything.
ansible-playbook site.yml --list-tasks
Playbook skeleton
A minimal playbook that installs and starts nginx.
- name: Configure web servers
hosts: webservers
become: true
tasks:
- name: Install nginx
ansible.builtin.package:
name: nginx
state: present
- name: Start nginx
ansible.builtin.service:
name: nginx
state: started
enabled: true