← 返回命令列表

Linux command

ansible-playbook 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Run

ansible-playbook [playbook.yml]

Example

ansible-playbook -i [inventory.ini] [playbook.yml]

Example

ansible-playbook [playbook.yml] --become --ask-become-pass

Check

ansible-playbook [playbook.yml] --check

Example

ansible-playbook [playbook.yml] --tags "[deploy,config]"

Example

ansible-playbook [playbook.yml] -e "env=production version=1.2.3"

说明

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.

参数

-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

FAQ

What is the ansible-playbook command used for?

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.

How do I run a basic ansible-playbook example?

Run `ansible-playbook [playbook.yml]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -i _inventory_ do in ansible-playbook?

Inventory file or path