You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docsite/rst/playbook_guide/playbooks_reuse.rst
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
.. _playbooks_reuse:
2
2
3
3
**************************
4
-
Re-using Ansible artifacts
4
+
Reusing Ansible artifacts
5
5
**************************
6
6
7
7
You can write a simple playbook in one very large file, and most users learn the one-file approach first. However, breaking your automation work up into smaller files is an excellent way to organize complex sets of tasks and reuse them. Smaller, more distributed artifacts let you reuse the same variables, tasks, and plays in multiple playbooks to address different use cases. You can use distributed artifacts across multiple parent playbooks or even multiple times within one playbook. For example, you might want to update your customer database as part of several different playbooks. If you put all the tasks related to updating your database in a tasks file or a role, you can reuse them in many playbooks while only maintaining them in one place.
You can incorporate multiple playbooks into a main playbook. However, you can only use imports to reuse playbooks. For example:
@@ -49,7 +49,7 @@ When to turn a playbook into a role
49
49
50
50
For some use cases, simple playbooks work well. However, starting at a certain level of complexity, roles work better than playbooks. A role lets you store your defaults, handlers, variables, and tasks in separate directories, instead of in a single long document. Roles are easy to share on Ansible Galaxy. For complex use cases, most users find roles easier to read, understand, and maintain than all-in-one playbooks.
51
51
52
-
Re-using files and roles
52
+
Reusing files and roles
53
53
========================
54
54
55
55
Ansible offers two ways to reuse files and roles in a playbook: dynamic and static.
@@ -111,7 +111,7 @@ See :ref:`ansible_variable_precedence` for more details on variable inheritance
111
111
Comparing includes and imports: dynamic and static reuse
Each approach to re-using distributed Ansible artifacts has advantages and limitations. You may choose dynamic reuse for some playbooks and static reuse for others. Although you can use both dynamic and static reuse in a single playbook, it is best to select one approach per playbook. Mixing static and dynamic reuse can introduce difficult-to-diagnose bugs into your playbooks. This table summarizes the main differences so you can choose the best approach for each playbook you create.
114
+
Each approach to reusing distributed Ansible artifacts has advantages and limitations. You may choose dynamic reuse for some playbooks and static reuse for others. Although you can use both dynamic and static reuse in a single playbook, it is best to select one approach per playbook. Mixing static and dynamic reuse can introduce difficult-to-diagnose bugs into your playbooks. This table summarizes the main differences so you can choose the best approach for each playbook you create.
115
115
116
116
.. table::
117
117
:class: documentation-table
@@ -150,7 +150,7 @@ Each approach to re-using distributed Ansible artifacts has advantages and limit
150
150
* There are also big differences in resource consumption and performance, imports are quite lean and fast, while includes require a lot of management
151
151
and accounting.
152
152
153
-
Re-using tasks as handlers
153
+
Reusing tasks as handlers
154
154
==========================
155
155
156
156
You can also use includes and imports in the :ref:`handlers` section of a playbook. For example, if you want to define how to restart Apache, you only have to do that once for all of your playbooks. You might make a ``restarts.yml`` file that looks like:
In this example, Ansible starts executing your playbook at a task named "install packages". This feature does not work with tasks inside dynamically re-used roles or tasks (``include_*``), see :ref:`dynamic_vs_static`.
20
+
In this example, Ansible starts executing your playbook at a task named "install packages". This feature does not work with tasks inside dynamically reused roles or tasks (``include_*``), see :ref:`dynamic_vs_static`.
0 commit comments