标签:port plugin pack 这一 eating 游戏 显示 wrap output
While it is possible to write a playbook in one very large file (and you might start out learning playbooks this way), eventually you’ll want to reuse files and start to organize things. In Ansible, there are three ways to do this: includes, imports, and roles.
虽然可以在一个非常大的文件中编写一个剧本(并且你可能会开始以这种方式学习剧本),但最终你会想要重用文件并开始组织事情。在Ansible中,有三种方法可以做到这一点:包括,导入和角色。
Includes and imports (added in Ansible version 2.4) allow users to break up large playbooks into smaller files, which can be used across multiple parent playbooks or even multiple times within the same Playbook.
包含和导入(在Ansible 2.4版中添加)允许用户将大型剧本分解为较小的文件,这些文件可以在多个父级剧本中使用,甚至可以在同一个Playbook中多次使用。
Roles allow more than just tasks to be packaged together and can include variables, handlers, or even modules and other plugins. Unlike includes and imports, roles can also be uploaded and shared via Ansible Galaxy.
角色不仅可以将任务打包在一起,还可以包含变量,处理程序,甚至模块和其他插件。与包含和导入不同,角色也可以通过Ansible Galaxy上传和共享。
Ansible has two modes of operation for reusable content: dynamic and static.
Ansible有两种可重用内容的操作模式:动态和静态。
In Ansible 2.0, the concept of dynamic includes was introduced. Due to some limitations with making all includes dynamic in this way, the ability to force includes to be static was introduced in Ansible 2.1. Because the include task became overloaded to encompass both static and dynamic syntaxes, and because the default behavior of an include could change based on other options set on the Task, Ansible 2.4 introduces the concept of include
vs. import
.
在Ansible 2.0中,引入了动态包含的概念。由于以这种方式使所有包括动态的一些限制,在Ansible 2.1中引入了强制包括静态的能力。因为include任务变得过载以包含静态和动态语法,并且因为include的默认行为可能会根据Task上设置的其他选项而改变,所以Ansible 2.4引入了include
vs import. 的概念
。
If you use any import*
Task (import_playbook
, import_tasks
, etc.), it will be static. If you use any include*
Task (include_tasks
, include_role
, etc.), it will be dynamic.
如果您使用任何import*
任务(import_playbook
,import_tasks
等),它将是静态的。如果您使用任何include*
任务(include_tasks
,include_role
等),它将是动态的。
The bare include
task (which was used for both Task files and Playbook-level includes) is still available, however it is now considered deprecated.
裸include
任务(用于任务文件和Playbook级别包括)仍然可用,但现在它被认为已弃用。
The two modes of operation are pretty simple:
这两种操作模式非常简单:
When it comes to Ansible task options like tags
and conditional statements (when:
):
当涉及Ansible任务选项tags
和条件语句(when:
)时:
Roles are a somewhat special case. Prior to Ansible 2.3, roles were always statically included via the special roles: option for a given play and were always executed first before any other play tasks (unless pre_tasks were used). Roles can still be used this way, however, Ansible 2.3 introduced the include_role option to allow roles to be executed inline with other tasks. 角色是一种特殊情况。在Ansible 2.3之前,角色总是静态地包含在roles:给定游戏的特殊选项中,并且总是在任何其他游戏任务之前首先执行(除非pre_tasks被使用)。角色仍然可以这种方式使用,但是,Ansible 2.3引入了include_role允许角色与其他任务一起执行的选项。
Using include*
vs. import*
has some advantages as well as some tradeoffs which users should consider when choosing to use each:
使用include*
vs. import*
具有一些优势以及用户在选择使用每个时应考虑的一些权衡:
The primary advantage of using include*
statements is looping. When a loop is used with an include, the included tasks or role will be executed once for each item in the loop.
使用include*
语句的主要优点是循环。当循环与include一起使用时,包含的任务或角色将对循环中的每个项执行一次。
Using include*
does have some limitations when compared to import*
statements:
include*
与import*
语句相比,使用确实有一些限制:
--list-tags
output.--list-tags
输出中。--list-tasks
output.--list-tasks
输出中。notify
to trigger a handler name which comes from inside a dynamic include (see note below).notify
触发来自动态包含内的处理程序名称(请参阅下面的注释)。--start-at-task
to begin execution at a task inside a dynamic include.--start-at-task
在动态包含内的任务开始执行。Using import*
can also have some limitations when compared to dynamic includes:
import*
与动态包含相比,使用也可能有一些限制:
1 Note: 2 3 Regarding the use of notify for dynamic tasks: it is still possible to trigger the dynamic include itself, which would result in all tasks within the include being run. 4 5 关于notify动态任务的使用:仍然可以触发动态包含本身,这将导致包含内的所有任务被运行。
Working With Playbooks--Creating Reusable Playbooks
标签:port plugin pack 这一 eating 游戏 显示 wrap output
原文地址:https://www.cnblogs.com/cevinchen/p/9610170.html