mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-20 11:04:00 -07:00
Switch to the 'Sphinx Bootstrap' Theme:
https://github.com/ryan-roemer/sphinx-bootstrap-theme Fix some rst related formatting.
This commit is contained in:
parent
26800d5db8
commit
f25b39b7ce
38 changed files with 7224 additions and 1089 deletions
|
@ -1,3 +1,5 @@
|
|||
.. _patterns:
|
||||
|
||||
The Inventory File, Patterns, and Groups
|
||||
========================================
|
||||
|
||||
|
@ -43,16 +45,17 @@ It is also possible to address specific hosts::
|
|||
one.example.com:two.example.com
|
||||
|
||||
|
||||
The following patterns address one or more groups, which are denoted with the bracket
|
||||
headers in the inventory file::
|
||||
The following patterns address one or more groups, which are denoted
|
||||
with the bracket headers in the inventory file::
|
||||
|
||||
webservers
|
||||
webservers:dbservers
|
||||
|
||||
Individual hosts, but not groups, can also be referenced using wildcards:
|
||||
Individual hosts, but not groups, can also be referenced using
|
||||
wildcards::
|
||||
|
||||
*.example.com
|
||||
*.com
|
||||
*.example.com
|
||||
*.com
|
||||
|
||||
It's also ok to mix wildcard patterns and groups at the same time::
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
Playbooks: Ansible for Deployment, Configuration Management, and Orchestration
|
||||
==============================================================================
|
||||
Playbooks
|
||||
=========
|
||||
|
||||
.. seealso::
|
||||
|
||||
|
@ -11,21 +11,28 @@ Playbooks: Ansible for Deployment, Configuration Management, and Orchestration
|
|||
Learn about how to select hosts
|
||||
|
||||
|
||||
Playbooks are a completely different way to use ansible and are particularly awesome.
|
||||
Playbooks are a completely different way to use ansible and are
|
||||
particularly awesome.
|
||||
|
||||
They are the basis for a really simple configuration management and multi-machine deployment system, unlike any that already exist, and one that is very well suited to deploying complex applications.
|
||||
They are the basis for a really simple configuration management and
|
||||
multi-machine deployment system, unlike any that already exist, and
|
||||
one that is very well suited to deploying complex applications.
|
||||
|
||||
While you might run the main /usr/bin/ansible program for ad-hoc tasks, playbooks are more likely to be kept in source control and used to push out your configuration or assure the configurations of your remote systems are in spec.
|
||||
While you might run the main /usr/bin/ansible program for ad-hoc
|
||||
tasks, playbooks are more likely to be kept in source control and used
|
||||
to push out your configuration or assure the configurations of your
|
||||
remote systems are in spec.
|
||||
|
||||
|
||||
Playbook Example
|
||||
````````````````
|
||||
|
||||
Playbooks are expressed in YAML format and have a minimum of syntax. Each playbook is composed
|
||||
of one or more 'plays' in a list. By composing a playbook of multiple 'plays', it is possible
|
||||
to orchestrate multi-machine deployments, running certain steps on all machines in
|
||||
the webservers group, then certain steps on the database server group, then more commands
|
||||
back on the webservers group, etc::
|
||||
Playbooks are expressed in YAML format and have a minimum of syntax.
|
||||
Each playbook is composed of one or more 'plays' in a list. By
|
||||
composing a playbook of multiple 'plays', it is possible to
|
||||
orchestrate multi-machine deployments, running certain steps on all
|
||||
machines in the webservers group, then certain steps on the database
|
||||
server group, then more commands back on the webservers group, etc::
|
||||
|
||||
---
|
||||
- hosts: webservers
|
||||
|
@ -47,21 +54,26 @@ back on the webservers group, etc::
|
|||
Hosts line
|
||||
``````````
|
||||
|
||||
The hosts line is a list of one or more groups or host patterns, seperated by colons, asdescribed in the 'patterns' documentation. This is just like the first parameter to /usr/bin/ansible.
|
||||
The hosts line is a list of one or more groups or host patterns,
|
||||
seperated by colons, as described in the :ref:`patterns`
|
||||
documentation. This is just like the first parameter to
|
||||
`/usr/bin/ansible`.
|
||||
|
||||
Vars section
|
||||
````````````
|
||||
|
||||
A list of variables and values that can be used in the plays. These can be used in templates
|
||||
or 'action' lines and are dereferenced using ```jinja2``` syntax like this::
|
||||
A list of variables and values that can be used in the plays. These
|
||||
can be used in templates or 'action' lines and are dereferenced using
|
||||
`jinja2` syntax like this::
|
||||
|
||||
{{ varname }}
|
||||
|
||||
Further, if there are discovered variables about the system (say, if facter or ohai were
|
||||
installed) these variables bubble up back into the playbook, and can be used on each
|
||||
system just like explicitly set variables. Facter variables are prefixed with 'facter_'
|
||||
and Ohai variables are prefixed with 'ohai_'. So for instance, if I wanted to write the
|
||||
hostname into the /etc/motd file, I could say::
|
||||
Further, if there are discovered variables about the system (say, if
|
||||
facter or ohai were installed) these variables bubble up back into the
|
||||
playbook, and can be used on each system just like explicitly set
|
||||
variables. Facter variables are prefixed with ``facter_`` and Ohai
|
||||
variables are prefixed with ``ohai_``. So for instance, if I wanted
|
||||
to write the hostname into the /etc/motd file, I could say::
|
||||
|
||||
- name: write the motd
|
||||
- action: template src=/srv/templates/motd.j2 dest=/etc/motd
|
||||
|
@ -75,27 +87,32 @@ But we're getting ahead of ourselves. Let's talk about tasks.
|
|||
Tasks list
|
||||
``````````
|
||||
|
||||
Each play contains a list of tasks. Tasks are executed in order, one at a time, against
|
||||
all machines matched by the play's host pattern, before moving on to the next task.
|
||||
Each play contains a list of tasks. Tasks are executed in order, one
|
||||
at a time, against all machines matched by the play's host pattern,
|
||||
before moving on to the next task.
|
||||
|
||||
Hosts with failed tasks are taken out of the rotation for the entire playbook. If things fail,
|
||||
simply correct the playbook file and rerun.
|
||||
Hosts with failed tasks are taken out of the rotation for the entire
|
||||
playbook. If things fail, simply correct the playbook file and rerun.
|
||||
|
||||
Modules other than command are idempotent, meaning if you run them again, they will make the
|
||||
changes they are told to make to bring the system to the desired state.
|
||||
Modules other than command are idempotent, meaning if you run them
|
||||
again, they will make the changes they are told to make to bring the
|
||||
system to the desired state.
|
||||
|
||||
Task name and action
|
||||
`````````````````````
|
||||
|
||||
Every task must have a name, which is included in the output from running the playbook.
|
||||
Every task must have a name, which is included in the output from
|
||||
running the playbook.
|
||||
|
||||
The action line is the name of an ansible module followed by parameters. Usually these
|
||||
are expressed in key=value form, except for the command module, which looks just like a Linux/Unix
|
||||
command line. See the module documentation for more info.
|
||||
The action line is the name of an ansible module followed by
|
||||
parameters. Usually these are expressed in ``key=value`` form, except
|
||||
for the command module, which looks just like a Linux/Unix command
|
||||
line. See the module documentation for more info.
|
||||
|
||||
Variables, as mentioned above, can be used in action lines. So if, hypothetically, you wanted
|
||||
to make a directory on each system named after the hostname ... yeah, that's I know silly ... you could
|
||||
do it like so::
|
||||
Variables, as mentioned above, can be used in action lines. So if,
|
||||
hypothetically, you wanted to make a directory on each system named
|
||||
after the hostname ... yeah, that's I know silly ... you could do it
|
||||
like so::
|
||||
|
||||
- name: make a directory
|
||||
- action: mkdir /tmp/{{ facter_hostname }}
|
||||
|
@ -103,44 +120,49 @@ do it like so::
|
|||
Notify statements
|
||||
`````````````````
|
||||
|
||||
Nearly all modules are written to be 'idempotent' and can signal when they have affected a change
|
||||
on the remote system. If a notify statement is used, the named handler will be run against
|
||||
each system where a change was effected, but NOT on systems where no change occurred. This happens
|
||||
after all of the tasks are run. For example, if notifying Apache and potentially replacing lots of
|
||||
configuration files, you could have Apache restart just once, at the end of a run. If you need
|
||||
Apache restarted in the middle of a run, you could just make a task for it, no harm done. Notifiers
|
||||
are optional.
|
||||
Nearly all modules are written to be 'idempotent' and can signal when
|
||||
they have affected a change on the remote system. If a notify
|
||||
statement is used, the named handler will be run against each system
|
||||
where a change was effected, but NOT on systems where no change
|
||||
occurred. This happens after all of the tasks are run. For example,
|
||||
if notifying Apache and potentially replacing lots of configuration
|
||||
files, you could have Apache restart just once, at the end of a run.
|
||||
If you need Apache restarted in the middle of a run, you could just
|
||||
make a task for it, no harm done. Notifiers are optional.
|
||||
|
||||
Handlers
|
||||
````````
|
||||
|
||||
Handlers are lists of tasks, not really any different from regular tasks, that are referenced
|
||||
by name. Handlers are what notifiers notify. If nothing notifies a handler, it will not run.
|
||||
Regardless of how many things notify a handler, it will run only once, after all of the tasks
|
||||
complete in a particular play.
|
||||
Handlers are lists of tasks, not really any different from regular
|
||||
tasks, that are referenced by name. Handlers are what notifiers
|
||||
notify. If nothing notifies a handler, it will not run. Regardless
|
||||
of how many things notify a handler, it will run only once, after all
|
||||
of the tasks complete in a particular play.
|
||||
|
||||
Includes
|
||||
````````
|
||||
|
||||
Not all tasks have to be listed directly in the main file. An include file can contain
|
||||
a list of tasks (in YAML) as well, optionally passing extra variables into the file.
|
||||
Variables passed in can be deferenced like this (assume a variable named 'user')::
|
||||
Not all tasks have to be listed directly in the main file. An include
|
||||
file can contain a list of tasks (in YAML) as well, optionally passing
|
||||
extra variables into the file. Variables passed in can be deferenced
|
||||
like this (assume a variable named 'user')::
|
||||
|
||||
{{ user }}
|
||||
|
||||
For instance, if deploying multiple wordpress instances, I could contain all of my tasks
|
||||
in a wordpress.yml file, and use it like so::
|
||||
For instance, if deploying multiple wordpress instances, I could
|
||||
contain all of my tasks in a wordpress.yml file, and use it like so::
|
||||
|
||||
- tasks:
|
||||
- include: wordpress.yml user=timmy
|
||||
- include: wordpress.yml user=alice
|
||||
- include: wordpress.yml user=bob
|
||||
|
||||
In addition to the explicitly passed in parameters, all variables from the vars section
|
||||
are also available.
|
||||
In addition to the explicitly passed in parameters, all variables from
|
||||
the vars section are also available.
|
||||
|
||||
The format of an included list of tasks or handlers looks just like a flat list of tasks. Here
|
||||
is an example of what base.yml might look like::
|
||||
The format of an included list of tasks or handlers looks just like a
|
||||
flat list of tasks. Here is an example of what base.yml might look
|
||||
like::
|
||||
|
||||
---
|
||||
- name: no selinux
|
||||
|
@ -150,18 +172,20 @@ is an example of what base.yml might look like::
|
|||
- name: this is just to show variables work here, favcolor={{ favcolor }}
|
||||
action: command /bin/true
|
||||
|
||||
As you can see above, variables in include files work just like they do in the main file.
|
||||
Including a variable in the name of a task is a contrived example, you could also
|
||||
pass them to the action command line or use them inside a template file.
|
||||
As you can see above, variables in include files work just like they
|
||||
do in the main file. Including a variable in the name of a task is a
|
||||
contrived example, you could also pass them to the action command line
|
||||
or use them inside a template file.
|
||||
|
||||
Note that include statements are only usable from the top level playbook file.
|
||||
At this time, includes can not include other includes.
|
||||
Note that include statements are only usable from the top level
|
||||
playbook file. At this time, includes can not include other includes.
|
||||
|
||||
Using Includes To Assign Classes of Systems
|
||||
```````````````````````````````````````````
|
||||
|
||||
Include files are best used to reuse logic between playbooks. You could imagine
|
||||
a playbook describing your entire infrastructure like this::
|
||||
Include files are best used to reuse logic between playbooks. You
|
||||
could imagine a playbook describing your entire infrastructure like
|
||||
this::
|
||||
|
||||
---
|
||||
- hosts: atlanta-webservers
|
||||
|
@ -181,21 +205,23 @@ a playbook describing your entire infrastructure like this::
|
|||
handlers:
|
||||
- include: generic-handlers.yml
|
||||
|
||||
There is one (or more) play defined for each group of systems, and each play maps
|
||||
each group includes one or more 'class definitions' telling the systems what they
|
||||
are supposed to do or be.
|
||||
There is one (or more) play defined for each group of systems, and
|
||||
each play maps each group includes one or more 'class definitions'
|
||||
telling the systems what they are supposed to do or be.
|
||||
|
||||
Using a common handlers file could allow one task in 'webservers' to define 'restart apache',
|
||||
and it could be reused between multiple plays.
|
||||
Using a common handlers file could allow one task in 'webservers' to
|
||||
define 'restart apache', and it could be reused between multiple
|
||||
plays.
|
||||
|
||||
Variables like 'database' above can be used in templates referenced from the
|
||||
configuration file to generate machine specific variables.
|
||||
Variables like 'database' above can be used in templates referenced
|
||||
from the configuration file to generate machine specific variables.
|
||||
|
||||
Asynchronous Actions and Polling
|
||||
````````````````````````````````
|
||||
|
||||
(Information on this feature is pending)
|
||||
|
||||
|
||||
Executing A Playbook
|
||||
````````````````````
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue