Playbook Keywords

playbook对象上可用的关键字是配置可执行行为的几个来源之一。有关每个源的相对优先级:

Precedence categories(more)
Ansible offers four sources for controlling its behavior. In order of precedence from lowest (most easily overridden) to highest (overrides all others), the categories are:

  • Configuration settings
  • Command-line options
  • Playbook keywords
  • Variables

通用关键字

以下为角色 - Play/Role/Block/Task 通用的关键字整理:

**any_errors_fatal**
强制任何主机上的任何未处理任务错误传播到所有主机并结束播放

**become**
布尔值,切换成其它用户身份执行,值为yes或者no

**become_exe**
UNDOCUMENTED!!

**become_flags**
当变为True的时候,要传递给权限提升程序的标志

**become_method**
与became一起用,适用那种权限升级方法(such as sudo or su)

**become_user**
设置为具有所需权限的用户(你要切换到的目标用户),而不是您登录的用户。远程/登录用户必须具有成为该用户的权限。必须跟become: yes 一起使用。

**check_mode**
一个布尔值,控制是否以“检查”模式执行任务

**collections**
UNDOCUMENTED!!

**connection**[(more)](https://docs.ansible.com/ansible/latest/plugins/connection.html#using-connection)
Allows you to change the connection plugin used for tasks to execute on the target.

**debugger**
调试器,根据任务结果的状态启用调试任务

**diff**
切换使任务是否返回“ diff”信息。

**environment**
一个字典,该字典将转换为环境变量,以便在执行时为任务提供。这不会影响Ansible本身或其配置,它只会为负责执行任务的代码设置变量。

**ignore_errors**
布尔值,允许您忽略任务失败并继续执行。它不会影响连接错误

**ignore_unreachable**
布尔值,允许您忽略无法访问的主机并继续这个play

**module_defaults**
指定模块的默认参数值

**name**
Identifier. Can be used for documentation, in or tasks/handlers.

**no_log**
控制信息泄露的布尔值

**port**
用于覆盖连接中使用的默认端口

**remote_user**
以哪个用户身份执行

**run_once**
布尔值,它将绕过主机循环,强制任务尝试在第一个可用主机上执行,然后将任何结果和事实应用于同一批次中的所有活动主机

**tags**
应用于任务或包含任务的标签,允许从命令行选择任务子集

**throttle**
限制在任务、块和剧本级别上运行的并发任务的数量。这与fork和serial设置无关,但不能设置得高于这些限制。例如,如果将fork设置为10,而将throttle设置为15,则最多将并行操作10台主机。

**vars**
变量

非通用关键字

Play

fact_path
为由gather_facts控制的事实收集插件设置事实路径选项

force_handlers
即使在播放期间失败,也会强制通知处理程序执行主机

gather_facts
一个布尔值,用于控制播放是否将自动运行“ setup”任务来为主机收集事实。

gather_subset
允许您将子集选项传递给gather_facts控制的事实收集插件

gather_timeout
允许您设置由gather_facts控制的事实收集插件的超时

handlers
处理器,是playbook的event,默认不会执行,在action里触发才会执行。多次触发只执行一次。

hosts
主机或主机组列表

max_fail_percentage
在当前批处理中给定百分比的主机失败后,可用于中止运行

order
控制主机在用于执行play时的排序。可能的值是inventory(默认),sorted,reverse_sorted,reverse_inventory和shuffle。

post_tasks
任务部分后要执行的任务列表

pre_tasks
在roles之前执行的任务列表

roles
要导入到剧本中的角色列表

serial
明确定义Ansible如何在剧本目标上分批执行当前剧本

strategy
允许您选择用于play的连接插件

tasks
在play中执行的任务的主要列表,它们在角色之后和post_tasks之前运行

vars_files
包含vars的文件列表到剧本中

vars_prompt
要提示的变量列表


Role

delegate_facts
布尔值,允许您将事实应用于委托主机而不是inventory_hostname
delegate_to
主机执行任务而不是目标(inventory_hostname)。来自委派主机的连接变量也将用于该任务
when
条件表达式,确定是否运行任务的迭代


block

always
block中的任务列表,无论block中是否有错误,都将执行。
block
List of tasks in a block.
rescue
当主block中出现任务错误时,运行rescue,然后做一些补救性的工作

delegate_facts
布尔值,允许您将事实应用于委托主机而不是inventory_hostname
delegate_to
主机执行任务而不是目标(inventory_hostname)。来自委派主机的连接变量也将用于该任务
when
条件表达式,确定是否运行任务的迭代


task

action
任务要执行的操作
args
将参数传递到任务的第二种方法
async
Run a task asynchronously if the C(action) supports this; value is maximum runtime in seconds.
block
List of tasks in a block.
changed_when
覆盖任务的正常“‘changed’”状态的条件表达式
delay
延迟的秒数
failed_when
覆盖任务的正常“failed”状态的条件表达式
local_action
Same as action but also implies delegate_to: localhost
loop
循环取值的任务列表
loop_control
Several keys here allow you to modify/set loop behaviour in a task.
notify
当任务返回changed=True状态时要通知处理程序
poll
Sets the polling interval in seconds for async tasks (default 10s).
register
寄存器,接收任务的返回值或者状态(用于自定义变量定义)
retries
重试次数,与until配合适用
until
直到…结束循环
with_[lookup_plugin]
The same as loop but magically adds the output of any lookup plugin to generate the item list.

delegate_facts
布尔值,允许您将事实应用于委托主机而不是inventory_hostname
delegate_to
主机执行任务而不是目标(inventory_hostname)。来自委派主机的连接变量也将用于该任务
when
条件表达式,确定是否运行任务的迭代


总结