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_intro.rst
+27-31Lines changed: 27 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,13 @@
5
5
Ansible playbooks
6
6
*****************
7
7
8
-
Ansible Playbooks offer a repeatable, reusable, simple configuration management and multi-machine deployment system, one that is well suited to deploying complex applications. If you need to execute a task with Ansible more than once, write a playbook and put it under source control. Then you can use the playbook to push out new configuration or confirm the configuration of remote systems.
8
+
Ansible Playbooks provide a repeatable, reusable, simple configuration management and multimachine deployment systemthat is well suited to deploying complex applications. If you need to execute a task with Ansible more than once, you can write a playbook and put the playbook under source control. You can then use the playbook to push new configurations or confirm the configuration of remote systems.
9
9
10
-
Playbooks can:
10
+
Playbooks allow you to perform the following actions:
11
11
12
-
* declare configurations
13
-
* orchestrate steps of any manual ordered process, on multiple sets of machines, in a defined order
14
-
* launch tasks synchronously or :ref:`asynchronously <playbooks_async>`
12
+
* Declare configurations.
13
+
* Orchestrate steps of any manual ordered process on multiple sets of machines in a defined order.
14
+
* Launch tasks synchronously or :ref:`asynchronously <playbooks_async>`.
15
15
16
16
.. contents::
17
17
:local:
@@ -21,23 +21,21 @@ Playbooks can:
21
21
Playbook syntax
22
22
===============
23
23
24
-
Playbooks are expressed in YAML format with a minimum of syntax. If you are not familiar with YAML, look at our overview of :ref:`yaml_syntax` and consider installing an add-on for your text editor (see :ref:`other_tools_and_programs`) to help you write clean YAML syntax in your playbooks.
24
+
You express playbooks in YAML format with a minimum of syntax. If you are not familiar with YAML, review the :ref:`yaml_syntax` overview and consider installing an add-on for your text editor (see :ref:`other_tools_and_programs`) to help you write clean YAML syntax in your playbooks.
25
25
26
-
A playbook is composed of one or more 'plays' in an ordered list. The terms 'playbook' and 'play' are sports analogies. Each play executes part of the overall goal of the playbook, running one or more tasks. Each task calls an Ansible module.
26
+
A playbook consists of one or more 'plays' in an ordered list. The terms 'playbook' and 'play' are sports analogies. Each play executes part of the overall goal of the playbook, running one or more tasks. Each task calls an Ansible module.
27
27
28
28
Playbook execution
29
29
==================
30
30
31
-
A playbook runs in order from top to bottom. Within each play, tasks also run in order from top to bottom. Playbooks with multiple 'plays' can orchestrate multi-machine deployments, running one play on your webservers, then another play on your database servers, then a third play on your network infrastructure, and so on. At a minimum, each play defines two things:
31
+
A playbook runs in order from top to bottom. Within each play, tasks also run in order from top to bottom. Playbooks with multiple plays can orchestrate multimachine deployments, running one play on your webservers, another play on your database servers, and a third play on your network infrastructure. At a minimum, each play defines two things:
32
32
33
-
* the managed nodes to target, using a :ref:`pattern <intro_patterns>`
34
-
* at least one task to execute
33
+
* The managed nodes to target, using a :ref:`pattern <intro_patterns>`.
34
+
* At least one task to execute.
35
35
36
-
.. note::
36
+
For Ansible 2.10 and later, you should use the fully-qualified collection name (FQCN) in your playbooks. Using the FQCN ensures that you have selected the correct module, because multiple collections can contain modules with the same name. For example, ``user``. See :ref:`collections_using_playbook`.
37
37
38
-
In Ansible 2.10 and later, we recommend you use the fully-qualified collection name in your playbooks to ensure the correct module is selected, because multiple collections can contain modules with the same name (for example, ``user``). See :ref:`collections_using_playbook`.
39
-
40
-
In this example, the first play targets the web servers; the second play targets the database servers.
38
+
In the following example, the first play targets the web servers and the second play targets the database servers.
41
39
42
40
.. code-block:: yaml
43
41
@@ -72,23 +70,23 @@ In this example, the first play targets the web servers; the second play targets
72
70
name: postgresql
73
71
state: started
74
72
75
-
Your playbook can include more than just a hosts line and tasks. For example, the playbook above sets a ``remote_user`` for each play. This is the user account for the SSH connection. You can add other :ref:`playbook_keywords` at the playbook, play, or task level to influence how Ansible behaves. Playbook keywords can control the :ref:`connection plugin <connection_plugins>`, whether to use :ref:`privilege escalation <become>`, how to handle errors, and more. To support a variety of environments, Ansible lets you set many of these parameters as command-line flags, in your Ansible configuration, or in your inventory. Learning the :ref:`precedence rules <general_precedence_rules>` for these sources of data will help you as you expand your Ansible ecosystem.
73
+
Your playbook can include more than just a hosts line and tasks. For example, the playbook above sets a ``remote_user`` for each play. The ``remote_user`` is the user account for the SSH connection. You can add other :ref:`playbook_keywords` at the playbook, play, or task level to influence how Ansible behaves. Playbook keywords can control the :ref:`connection plugin <connection_plugins>`, whether to use :ref:`privilege escalation <become>`, how to handle errors, and more. To support a variety of environments, you can set many of these parameters as command-line flags in your Ansible configuration, or in your inventory. Learning the :ref:`precedence rules <general_precedence_rules>` for these sources of data helps you as you expand your Ansible ecosystem.
76
74
77
75
.. _tasks_list:
78
76
79
77
Task execution
80
78
--------------
81
79
82
-
By default, Ansible executes each task in order, one at a time, against all machines matched by the host pattern. Each task executes a module with specific arguments. When a task has executed on all target machines, Ansible moves on to the next task. You can use :ref:`strategies <playbooks_strategies>` to change this default behavior. Within each play, Ansible applies the same task directives to all hosts. If a task fails on a host, Ansible takes that host out of the rotation for the rest of the playbook.
80
+
By default, Ansible executes each task in order, one at a time, against all machines matched by the host pattern. Each task executes a module with specific arguments. After a task has executed on all target machines, Ansible moves to the next task. You can use :ref:`strategies <playbooks_strategies>` to change this default behavior. Within each play, Ansible applies the same task directives to all hosts. If a task fails on a host, Ansible removes that host from the rotation for the rest of the playbook.
83
81
84
82
When you run a playbook, Ansible returns information about connections, the ``name`` lines of all your plays and tasks, whether each task has succeeded or failed on each machine, and whether each task has made a change on each machine. At the bottom of the playbook execution, Ansible provides a summary of the nodes that were targeted and how they performed. General failures and fatal "unreachable" communication attempts are kept separate in the counts.
85
83
86
84
.. _idempotency:
87
85
88
-
Desired state and 'idempotency'
86
+
Desired state and idempotency
89
87
-------------------------------
90
88
91
-
Most Ansible modules check whether the desired final state has already been achieved, and exit without performing any actions if that state has been achieved, so that repeating the task does not change the final state. Modules that behave this way are often called 'idempotent.' Whether you run a playbook once, or multiple times, the outcome should be the same. However, not all playbooks and not all modules behave this way. If you are unsure, test your playbooks in a sandbox environment before running them multiple times in production.
89
+
Most Ansible modules check whether the desired final state has already been achieved and exit without performing any actions if that state has been achieved. Repeating the task does not change the final state. Modules that behave this way are 'idempotent'. Whether you run a playbook once or multiple times, the outcome should be the same. However, not all playbooks and not all modules behave this way. If you are unsure, test your playbooks in a sandbox environment before running them multiple times in production.
92
90
93
91
.. _executing_a_playbook:
94
92
@@ -101,45 +99,43 @@ To run your playbook, use the :ref:`ansible-playbook` command.
101
99
102
100
ansible-playbook playbook.yml -f 10
103
101
104
-
Use the ``--verbose`` flag when running your playbook to see detailed output from successful modules as well as unsuccessful ones.
102
+
Use the ``--verbose`` flag when running your playbook to see detailed output from successful and unsuccessful tasks.
105
103
106
104
107
-
Running playbooks in check mode
105
+
Running playbooks in check mode
108
106
--------------------------------
109
107
110
-
Ansible's check mode allows you to execute a playbook without applying any alterations to your systems. You can use check mode to test playbooks before implementing them in a production environment.
108
+
The Ansible check mode allows you to execute a playbook without applying any alterations to your systems. You can use check mode to test playbooks before you implement them in a production environment.
111
109
112
-
To run a playbook in check mode, you can pass the ``-C`` or ``--check`` flag to the ``ansible-playbook`` command:
110
+
To run a playbook in check mode, pass the ``-C`` or ``--check`` flag to the ``ansible-playbook`` command:
113
111
114
112
.. code-block:: bash
115
113
116
114
ansible-playbook --check playbook.yaml
117
115
118
116
119
-
Executing this command will run the playbook normally, but instead of implementing any modifications, Ansible will simply provide a report on the changes it would have made. This report encompasses details such as file modifications, command execution, and module calls.
117
+
Executing this command runs the playbook normally. Instead of implementing any modifications, Ansible provides a report on the changes it would have made. This report includes details such as file modifications, command execution, and module calls.
120
118
121
-
Check mode offers a safe and practical approach to examine the functionality of your playbooks without risking unintended changes to your systems. Moreover, it is a valuable tool for troubleshooting playbooks that are not functioning as expected.
119
+
Check mode offers a safe and practical approach to examine the functionality of your playbooks without risking unintended changes to your systems. Check mode is also a valuable tool for troubleshooting playbooks that are not functioning as expected.
122
120
123
121
124
122
.. _playbook_ansible-pull:
125
123
126
124
Ansible-Pull
127
125
============
128
126
129
-
Should you want to invert the architecture of Ansible, so that nodes check in to a central location, instead
130
-
of pushing configuration out to them, you can.
127
+
You can invert the Ansible architecture so that nodes check in to a central location instead of you pushing configuration out to them.
131
128
132
-
The ``ansible-pull`` is a small script that will checkout a repo of configuration instructions from git, and then
133
-
run ``ansible-playbook`` against that content.
129
+
The ``ansible-pull`` command is a small script that checks out a repo of configuration instructions from git and then runs ``ansible-playbook`` against that content.
134
130
135
-
Assuming you load balance your checkout location, ``ansible-pull`` scales essentially infinitely.
131
+
If you load balance your checkout location, ``ansible-pull`` scales infinitely.
136
132
137
133
Run ``ansible-pull --help`` for details.
138
134
139
135
Verifying playbooks
140
136
===================
141
137
142
-
You may want to verify your playbooks to catch syntax errors and other problems before you run them. The :ref:`ansible-playbook` command offers several options for verification, including ``--check``, ``--diff``, ``--list-hosts``, ``--list-tasks``, and ``--syntax-check``. The :ref:`validate-playbook-tools` describes other tools for validating and testing playbooks.
138
+
You may want to verify your playbooks to catch syntax errors and other problems before you run them. The :ref:`ansible-playbook` command offers several options for verification, including ``--check``, ``--diff``, ``--list-hosts``, ``--list-tasks``, and ``--syntax-check``. The :ref:`validate-playbook-tools` topic describes other tools for validating and testing playbooks.
143
139
144
140
.. _linting_playbooks:
145
141
@@ -155,7 +151,7 @@ You can use `ansible-lint <https://ansible.readthedocs.io/projects/lint/>`_ for
155
151
verify-apache.yml:8
156
152
Task/Handler: ensure apache is at the latest version
157
153
158
-
The `ansible-lint default rules <https://ansible.readthedocs.io/projects/lint/rules/>`_ page describes each error. For ``[403]``, the recommended fix is to change ``state: latest`` to ``state: present`` in the playbook.
154
+
The `ansible-lint default rules <https://ansible.readthedocs.io/projects/lint/rules/>`_ page describes each error.
0 commit comments