LinuxCommandLibrary

ansible-playbook

TLDR

Run a playbook

$ ansible-playbook [playbook.yml]
copy
Run with inventory file
$ ansible-playbook -i [inventory.ini] [playbook.yml]
copy
Run with sudo
$ ansible-playbook [playbook.yml] --become --ask-become-pass
copy
Check mode (dry run)
$ ansible-playbook [playbook.yml] --check
copy
Run specific tags
$ ansible-playbook [playbook.yml] --tags "[deploy,config]"
copy
Pass extra variables
$ ansible-playbook [playbook.yml] -e "env=production version=1.2.3"
copy

SYNOPSIS

ansible-playbook [-i inventory] [-e vars] [--tags tags] [options] playbook.yml

DESCRIPTION

ansible-playbook executes Ansible playbooks, which are YAML files defining automation tasks. Playbooks can provision servers, deploy applications, configure services, and orchestrate complex multi-tier deployments.
Unlike ad-hoc ansible commands, playbooks define complete automation workflows with variables, conditionals, loops, and handlers.

PARAMETERS

-i inventory

Inventory file or path
-e vars, --extra-vars vars
Extra variables (key=value or @file.yml)
--tags tags
Run only tasks with these tags
--skip-tags tags
Skip tasks with these tags
--become
Run with privilege escalation
-K, --ask-become-pass
Prompt for become password
--check
Dry run without making changes
--diff
Show differences in changed files
-l hosts, --limit hosts
Limit to specific hosts
--list-tasks
List tasks without executing
--list-tags
List available tags
-f forks, --forks forks
Parallel processes
--start-at-task task
Start at specific task
--step
Prompt before each task

CAVEATS

Playbook syntax errors fail fast; use --syntax-check first. Check mode may not work perfectly with all modules. Always test in non-production first.

HISTORY

ansible-playbook has been the primary execution method for Ansible automation since the project's creation in 2012, enabling infrastructure as code and declarative automation.

SEE ALSO

Copied to clipboard