Update docs

This commit is contained in:
Michael DeHaan 2012-03-09 07:42:53 -05:00
parent fe2d1c7cc9
commit e8eb7ab5ed
22 changed files with 379 additions and 214 deletions

View file

@ -183,7 +183,7 @@ languages:
</div>
<div class="footer">
&copy; Copyright 2012 Michael DeHaan.
Last updated on Mar 08, 2012.
Last updated on Mar 09, 2012.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.8.
</div>
</body>

View file

@ -1,5 +1,5 @@
API
```
Using the Python API
====================
The Python API is very powerful, and is how the ansible CLI and ansible-playbook
are implemented.
@ -32,4 +32,42 @@ expressed in the 'ansible-modules' documentation.::
A module can return any type of JSON data it wants, so Ansible can
be used as a framework to rapidly build powerful applications and scripts.
Detailed API Example
````````````````````
The following script prints out the uptime information for all hosts::
#!/usr/bin/python
import ansible.runner
import sys
# construct the ansible runner and execute on all hosts
results = ansible.runner.Runner(
pattern='*', forks=10,
module_name='command', module_args=['/usr/bin/uptime'],
).run()
if results is None:
print "No hosts found"
sys.exit(1)
print "UP ***********"
for (hostname, result) in results['contacted'].items():
if not 'failed' in result:
print "%s >>> %s" % (hostname, result['stdout'])
print "FAILED *******"
for (hostname, result) in results['contacted'].items():
if 'failed' in result:
print "%s >>> %s" % (hostname, result['msg'])
print "DOWN *********"
for (hostname, result) in results['dark'].items():
print "%s >>> %s" % (hostname, result)
Advanced programmers may also wish to read the source to ansible itself, for
it uses the Runner() API (with all available options) to implement the
command line tools ``ansible`` and ``ansible-playbook``.

View file

@ -1,5 +1,9 @@
Examples
========
Command Line Examples
=====================
The following examples show how to use `/usr/bin/ansible` for running ad-hoc tasks.
Start here. For configuration management and deployments, you'll want to pick up on
using `/usr/bin/ansible-playbook` -- the concepts port over directly.
.. seealso::
@ -24,19 +28,6 @@ The -f 10 specifies the usage of 10 simultaneous processes.
Note that other than the command module, ansible modules do not work like simple scripts. They make the remote system look like you state, and run the commands neccessary to get it there. This is commonly refered to
as 'idempotency'.
Time Limited Background Operations
``````````````````````````````````
Long running operations can be backgrounded, and their status can be checked on later. The same job ID is given to the same task on all hosts, so you won't lose track. Polling support is pending in the command line.::
ansible all -B 3600 -a "/usr/bin/long_running_operation --do-stuff"
ansible all -n job_status -a jid=123456789
Any module other than 'copy' or 'template' can be backgrounded. Typically you'll be backgrounding shell
commands or software upgrades only.
After the time limit (in seconds) runs out (-B), the process on the remote nodes will be killed.
File Transfer & Templating
``````````````````````````
@ -74,4 +65,17 @@ Alternatively, restart a service on all webservers::
ansible webservers -m service name=httpd state=restarted
Time Limited Background Operations
``````````````````````````````````
Long running operations can be backgrounded, and their status can be checked on later. The same job ID is given to the same task on all hosts, so you won't lose track. Polling support is pending in the command line.::
ansible all -B 3600 -a "/usr/bin/long_running_operation --do-stuff"
ansible all -n job_status -a jid=123456789
Any module other than 'copy' or 'template' can be backgrounded. Typically you'll be backgrounding shell
commands or software upgrades only.
After the time limit (in seconds) runs out (-B), the process on the remote nodes will be killed.

View file

@ -47,8 +47,7 @@ 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, as
described 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, asdescribed in the 'patterns' documentation. This is just like the first parameter to /usr/bin/ansible.
Vars section
````````````
@ -140,6 +139,58 @@ in a wordpress.yml file, and use it like so::
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::
---
- name: no selinux
action: command /usr/sbin/setenforce 0
- name: no iptables
action: service name=iptables state=stopped
- 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.
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::
---
- hosts: atlanta-webservers
vars:
datacenter: atlanta
tasks:
- include: base.yml
- include: webservers.yml database=db.atlanta.com
handlers:
- include: generic-handlers.yml
- hosts: atlanta-dbservers
vars:
datacenter: atlanta
tasks:
- include: base.yml
- include: dbservers.yml
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.
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.
Asynchronous Actions and Polling
````````````````````````````````

View file

@ -7,7 +7,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>API &mdash; Ansible v0.0.1 documentation</title>
<title>Using the Python API &mdash; Ansible v0.0.1 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
@ -48,8 +48,8 @@
<div class="bodywrapper">
<div class="body">
<div class="section" id="api">
<h1>API<a class="headerlink" href="#api" title="Permalink to this headline"></a></h1>
<div class="section" id="using-the-python-api">
<h1>Using the Python API<a class="headerlink" href="#using-the-python-api" title="Permalink to this headline"></a></h1>
<p>The Python API is very powerful, and is how the ansible CLI and ansible-playbook
are implemented.</p>
<p>It&#8217;s pretty simple:</p>
@ -78,6 +78,43 @@ expressed in the &#8216;ansible-modules&#8217; documentation.:</p>
</div>
<p>A module can return any type of JSON data it wants, so Ansible can
be used as a framework to rapidly build powerful applications and scripts.</p>
<div class="section" id="detailed-api-example">
<h2>Detailed API Example<a class="headerlink" href="#detailed-api-example" title="Permalink to this headline"></a></h2>
<p>The following script prints out the uptime information for all hosts:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c">#!/usr/bin/python</span>
<span class="kn">import</span> <span class="nn">ansible.runner</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="c"># construct the ansible runner and execute on all hosts</span>
<span class="n">results</span> <span class="o">=</span> <span class="n">ansible</span><span class="o">.</span><span class="n">runner</span><span class="o">.</span><span class="n">Runner</span><span class="p">(</span>
<span class="n">pattern</span><span class="o">=</span><span class="s">&#39;*&#39;</span><span class="p">,</span> <span class="n">forks</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span>
<span class="n">module_name</span><span class="o">=</span><span class="s">&#39;command&#39;</span><span class="p">,</span> <span class="n">module_args</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;/usr/bin/uptime&#39;</span><span class="p">],</span>
<span class="p">)</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
<span class="k">if</span> <span class="n">results</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="k">print</span> <span class="s">&quot;No hosts found&quot;</span>
<span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="k">print</span> <span class="s">&quot;UP ***********&quot;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">hostname</span><span class="p">,</span> <span class="n">result</span><span class="p">)</span> <span class="ow">in</span> <span class="n">results</span><span class="p">[</span><span class="s">&#39;contacted&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="k">if</span> <span class="ow">not</span> <span class="s">&#39;failed&#39;</span> <span class="ow">in</span> <span class="n">result</span><span class="p">:</span>
<span class="k">print</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s"> &gt;&gt;&gt; </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">hostname</span><span class="p">,</span> <span class="n">result</span><span class="p">[</span><span class="s">&#39;stdout&#39;</span><span class="p">])</span>
<span class="k">print</span> <span class="s">&quot;FAILED *******&quot;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">hostname</span><span class="p">,</span> <span class="n">result</span><span class="p">)</span> <span class="ow">in</span> <span class="n">results</span><span class="p">[</span><span class="s">&#39;contacted&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="k">if</span> <span class="s">&#39;failed&#39;</span> <span class="ow">in</span> <span class="n">result</span><span class="p">:</span>
<span class="k">print</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s"> &gt;&gt;&gt; </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">hostname</span><span class="p">,</span> <span class="n">result</span><span class="p">[</span><span class="s">&#39;msg&#39;</span><span class="p">])</span>
<span class="k">print</span> <span class="s">&quot;DOWN *********&quot;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">hostname</span><span class="p">,</span> <span class="n">result</span><span class="p">)</span> <span class="ow">in</span> <span class="n">results</span><span class="p">[</span><span class="s">&#39;dark&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="k">print</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s"> &gt;&gt;&gt; </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">hostname</span><span class="p">,</span> <span class="n">result</span><span class="p">)</span>
</pre></div>
</div>
<p>Advanced programmers may also wish to read the source to ansible itself, for
it uses the Runner() API (with all available options) to implement the
command line tools <tt class="docutils literal"><span class="pre">ansible</span></tt> and <tt class="docutils literal"><span class="pre">ansible-playbook</span></tt>.</p>
</div>
</div>
@ -86,6 +123,14 @@ be used as a framework to rapidly build powerful applications and scripts.</p>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Using the Python API</a><ul>
<li><a class="reference internal" href="#detailed-api-example">Detailed API Example</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="playbooks.html"
title="previous chapter">Playbooks: Ansible for Deployment, Configuration Management, and Orchestration</a></p>
@ -131,7 +176,7 @@ be used as a framework to rapidly build powerful applications and scripts.</p>
</div>
<div class="footer">
&copy; Copyright 2012 Michael DeHaan.
Last updated on Mar 08, 2012.
Last updated on Mar 09, 2012.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.8.
</div>
</body>

View file

@ -1,118 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Communicate and Get Involved &mdash; Ansible v0.0.1 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '0.0.1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Ansible v0.0.1 documentation" href="index.html" />
<link rel="next" title="Man Pages" href="man.html" />
<link rel="prev" title="API" href="api.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="man.html" title="Man Pages"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="api.html" title="API"
accesskey="P">previous</a> |</li>
<li><a href="index.html">Ansible v0.0.1 documentation</a> &raquo;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="communicate-and-get-involved">
<h1>Communicate and Get Involved<a class="headerlink" href="#communicate-and-get-involved" title="Permalink to this headline"></a></h1>
<ul class="simple">
<li>Join the <a class="reference external" href="http://groups.google.com/group/ansible-project">ansible-project mailing list</a> on Google Groups</li>
<li>Join <a class="reference external" href="irc://irc.freenode.net/#ansible">#ansible</a> on the <a class="reference external" href="http://freenode.net/">freenode IRC network</a></li>
<li>Visit the <a class="reference external" href="https://github.com/ansible/ansible">project page</a> on Github<ul>
<li>View the <a class="reference external" href="https://github.com/ansible/ansible/issues">issue tracker</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h4>Previous topic</h4>
<p class="topless"><a href="api.html"
title="previous chapter">API</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="man.html"
title="next chapter">Man Pages</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/communicate.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="man.html" title="Man Pages"
>next</a> |</li>
<li class="right" >
<a href="api.html" title="API"
>previous</a> |</li>
<li><a href="index.html">Ansible v0.0.1 documentation</a> &raquo;</li>
</ul>
</div>
<div class="footer">
&copy; Copyright 2012 Michael DeHaan.
Last updated on Mar 08, 2012.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.8.
</div>
</body>
</html>

View file

@ -7,7 +7,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Examples &mdash; Ansible v0.0.1 documentation</title>
<title>Command Line Examples &mdash; Ansible v0.0.1 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
@ -48,8 +48,11 @@
<div class="bodywrapper">
<div class="body">
<div class="section" id="examples">
<h1>Examples<a class="headerlink" href="#examples" title="Permalink to this headline"></a></h1>
<div class="section" id="command-line-examples">
<h1>Command Line Examples<a class="headerlink" href="#command-line-examples" title="Permalink to this headline"></a></h1>
<p>The following examples show how to use <cite>/usr/bin/ansible</cite> for running ad-hoc tasks.
Start here. For configuration management and deployments, you&#8217;ll want to pick up on
using <cite>/usr/bin/ansible-playbook</cite> &#8211; the concepts port over directly.</p>
<div class="admonition-see-also admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
@ -71,16 +74,6 @@ ansible atlanta -a "/sbin/reboot" -f 10</pre>
<p>Note that other than the command module, ansible modules do not work like simple scripts. They make the remote system look like you state, and run the commands neccessary to get it there. This is commonly refered to
as &#8216;idempotency&#8217;.</p>
</div>
<div class="section" id="time-limited-background-operations">
<h2>Time Limited Background Operations<a class="headerlink" href="#time-limited-background-operations" title="Permalink to this headline"></a></h2>
<p>Long running operations can be backgrounded, and their status can be checked on later. The same job ID is given to the same task on all hosts, so you won&#8217;t lose track. Polling support is pending in the command line.:</p>
<div class="highlight-python"><pre>ansible all -B 3600 -a "/usr/bin/long_running_operation --do-stuff"
ansible all -n job_status -a jid=123456789</pre>
</div>
<p>Any module other than &#8216;copy&#8217; or &#8216;template&#8217; can be backgrounded. Typically you&#8217;ll be backgrounding shell
commands or software upgrades only.</p>
<p>After the time limit (in seconds) runs out (-B), the process on the remote nodes will be killed.</p>
</div>
<div class="section" id="file-transfer-templating">
<h2>File Transfer &amp; Templating<a class="headerlink" href="#file-transfer-templating" title="Permalink to this headline"></a></h2>
<p>Ansible can SCP lots of files to multiple machines in parallel, and optionally use them as template sources.</p>
@ -110,6 +103,16 @@ ansible webservers -m template -a "src=/srv/ntp.j2 dest=/etc/ntp.conf"</pre>
<div class="highlight-python"><pre>ansible webservers -m service name=httpd state=restarted</pre>
</div>
</div>
<div class="section" id="time-limited-background-operations">
<h2>Time Limited Background Operations<a class="headerlink" href="#time-limited-background-operations" title="Permalink to this headline"></a></h2>
<p>Long running operations can be backgrounded, and their status can be checked on later. The same job ID is given to the same task on all hosts, so you won&#8217;t lose track. Polling support is pending in the command line.:</p>
<div class="highlight-python"><pre>ansible all -B 3600 -a "/usr/bin/long_running_operation --do-stuff"
ansible all -n job_status -a jid=123456789</pre>
</div>
<p>Any module other than &#8216;copy&#8217; or &#8216;template&#8217; can be backgrounded. Typically you&#8217;ll be backgrounding shell
commands or software upgrades only.</p>
<p>After the time limit (in seconds) runs out (-B), the process on the remote nodes will be killed.</p>
</div>
</div>
@ -120,12 +123,12 @@ ansible webservers -m template -a "src=/srv/ntp.j2 dest=/etc/ntp.conf"</pre>
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Examples</a><ul>
<li><a class="reference internal" href="#">Command Line Examples</a><ul>
<li><a class="reference internal" href="#parallelism-and-shell-commands">Parallelism and Shell Commands</a></li>
<li><a class="reference internal" href="#time-limited-background-operations">Time Limited Background Operations</a></li>
<li><a class="reference internal" href="#file-transfer-templating">File Transfer &amp; Templating</a></li>
<li><a class="reference internal" href="#deploying-from-source-control">Deploying From Source Control</a></li>
<li><a class="reference internal" href="#managing-services">Managing Services</a></li>
<li><a class="reference internal" href="#time-limited-background-operations">Time Limited Background Operations</a></li>
</ul>
</li>
</ul>
@ -175,7 +178,7 @@ ansible webservers -m template -a "src=/srv/ntp.j2 dest=/etc/ntp.conf"</pre>
</div>
<div class="footer">
&copy; Copyright 2012 Michael DeHaan.
Last updated on Mar 08, 2012.
Last updated on Mar 09, 2012.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.8.
</div>
</body>

View file

@ -84,7 +84,7 @@
</div>
<div class="footer">
&copy; Copyright 2012 Michael DeHaan.
Last updated on Mar 08, 2012.
Last updated on Mar 09, 2012.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.8.
</div>
</body>

View file

@ -54,7 +54,7 @@
<div class="admonition-see-also admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt><a class="reference internal" href="examples.html"><em>Examples</em></a></dt>
<dt><a class="reference internal" href="examples.html"><em>Command Line Examples</em></a></dt>
<dd>Examples of basic commands</dd>
<dt><a class="reference internal" href="playbooks.html"><em>Playbooks: Ansible for Deployment, Configuration Management, and Orchestration</em></a></dt>
<dd>Learning ansible&#8217;s configuration management language</dd>
@ -209,7 +209,7 @@ have a working infrastructure!</p>
</div>
<div class="footer">
&copy; Copyright 2012 Michael DeHaan.
Last updated on Mar 08, 2012.
Last updated on Mar 09, 2012.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.8.
</div>
</body>

View file

@ -106,12 +106,12 @@ short &amp; simple, and the source will be blindingly obvious.</p>
<li class="toctree-l2"><a class="reference internal" href="patterns.html#selecting-targets">Selecting Targets</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="examples.html">Examples</a><ul>
<li class="toctree-l1"><a class="reference internal" href="examples.html">Command Line Examples</a><ul>
<li class="toctree-l2"><a class="reference internal" href="examples.html#parallelism-and-shell-commands">Parallelism and Shell Commands</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples.html#time-limited-background-operations">Time Limited Background Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples.html#file-transfer-templating">File Transfer &amp; Templating</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples.html#deploying-from-source-control">Deploying From Source Control</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples.html#managing-services">Managing Services</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples.html#time-limited-background-operations">Time Limited Background Operations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="modules.html">Ansible Modules</a><ul>
@ -140,11 +140,15 @@ short &amp; simple, and the source will be blindingly obvious.</p>
<li class="toctree-l2"><a class="reference internal" href="playbooks.html#notify-statements">Notify statements</a></li>
<li class="toctree-l2"><a class="reference internal" href="playbooks.html#handlers">Handlers</a></li>
<li class="toctree-l2"><a class="reference internal" href="playbooks.html#includes">Includes</a></li>
<li class="toctree-l2"><a class="reference internal" href="playbooks.html#using-includes-to-assign-classes-of-systems">Using Includes To Assign Classes of Systems</a></li>
<li class="toctree-l2"><a class="reference internal" href="playbooks.html#asynchronous-actions-and-polling">Asynchronous Actions and Polling</a></li>
<li class="toctree-l2"><a class="reference internal" href="playbooks.html#executing-a-playbook">Executing A Playbook</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
<li class="toctree-l1"><a class="reference internal" href="api.html">Using the Python API</a><ul>
<li class="toctree-l2"><a class="reference internal" href="api.html#detailed-api-example">Detailed API Example</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="man.html">Man Pages</a><ul>
<li class="toctree-l2"><a class="reference internal" href="man.html#ansible-1">ansible(1)</a></li>
</ul>
@ -221,7 +225,7 @@ IBM, Motorola, Red Hat&#8217;s Emerging Technologies Group, Puppet Labs, and rPa
</div>
<div class="footer">
&copy; Copyright 2012 Michael DeHaan.
Last updated on Mar 08, 2012.
Last updated on Mar 09, 2012.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.8.
</div>
</body>

View file

@ -23,7 +23,7 @@
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Ansible v0.0.1 documentation" href="index.html" />
<link rel="prev" title="API" href="api.html" />
<link rel="prev" title="Using the Python API" href="api.html" />
</head>
<body>
<div class="related">
@ -33,7 +33,7 @@
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="api.html" title="API"
<a href="api.html" title="Using the Python API"
accesskey="P">previous</a> |</li>
<li><a href="index.html">Ansible v0.0.1 documentation</a> &raquo;</li>
</ul>
@ -71,7 +71,7 @@
<h4>Previous topic</h4>
<p class="topless"><a href="api.html"
title="previous chapter">API</a></p>
title="previous chapter">Using the Python API</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/man.txt"
@ -101,14 +101,14 @@
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="api.html" title="API"
<a href="api.html" title="Using the Python API"
>previous</a> |</li>
<li><a href="index.html">Ansible v0.0.1 documentation</a> &raquo;</li>
</ul>
</div>
<div class="footer">
&copy; Copyright 2012 Michael DeHaan.
Last updated on Mar 08, 2012.
Last updated on Mar 09, 2012.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.8.
</div>
</body>

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>ansible-modules</title><link rel="stylesheet" href="./docbook-xsl.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /></head><body><div xml:lang="en" class="refentry" title="ansible-modules" lang="en"><a id="id481479"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>ansible-modules — stock modules shipped with ansible</p></div><div class="refsect1" title="DESCRIPTION"><a id="_description"></a><h2>DESCRIPTION</h2><p>Ansible ships with a number of modules that can be executed directly on remote hosts or through
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>ansible-modules</title><link rel="stylesheet" href="./docbook-xsl.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /></head><body><div xml:lang="en" class="refentry" title="ansible-modules" lang="en"><a id="id581114"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>ansible-modules — stock modules shipped with ansible</p></div><div class="refsect1" title="DESCRIPTION"><a id="_description"></a><h2>DESCRIPTION</h2><p>Ansible ships with a number of modules that can be executed directly on remote hosts or through
ansible playbooks.</p></div><div class="refsect1" title="IDEMPOTENCE"><a id="_idempotence"></a><h2>IDEMPOTENCE</h2><p>Most modules other than command are idempotent, meaning they will seek to avoid changes
unless a change needs to be made. When using ansible playbooks, these modules can
trigger change events, as described in <span class="strong"><strong>ansible-playbooks</strong></span>(5).</p><p>Unless otherwise noted, all modules support change hooks.</p></div><div class="refsect1" title="command"><a id="_command"></a><h2>command</h2><p>The command module takes the command name followed by a list of arguments, space delimited.

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>ansible-modules</title><link rel="stylesheet" href="./docbook-xsl.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /></head><body><div xml:lang="en" class="refentry" title="ansible-modules" lang="en"><a id="id350237"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>ansible-playbook — format and function of an ansible playbook file</p></div><div class="refsect1" title="DESCRIPTION"><a id="_description"></a><h2>DESCRIPTION</h2><p>Ansible ships with <span class="emphasis"><em>ansible-playbook</em></span>, a tool for running playbooks.
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>ansible-modules</title><link rel="stylesheet" href="./docbook-xsl.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /></head><body><div xml:lang="en" class="refentry" title="ansible-modules" lang="en"><a id="id566369"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>ansible-playbook — format and function of an ansible playbook file</p></div><div class="refsect1" title="DESCRIPTION"><a id="_description"></a><h2>DESCRIPTION</h2><p>Ansible ships with <span class="emphasis"><em>ansible-playbook</em></span>, a tool for running playbooks.
Playbooks can represent frequent tasks, desired system configurations,
or deployment processes.</p></div><div class="refsect1" title="FORMAT"><a id="_format"></a><h2>FORMAT</h2><p>Playbooks are written in YAML.</p></div><div class="refsect1" title="EXAMPLE"><a id="_example"></a><h2>EXAMPLE</h2><p>See:</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
<a class="ulink" href="https://github.com/mpdehaan/ansible/blob/master/examples/playbook.yml" target="_top">https://github.com/mpdehaan/ansible/blob/master/examples/playbook.yml</a>

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>ansible</title><link rel="stylesheet" href="./docbook-xsl.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /></head><body><div xml:lang="en" class="refentry" title="ansible" lang="en"><a id="id561794"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>ansible — run a command somewhere else</p></div><div class="refsynopsisdiv" title="Synopsis"><a id="_synopsis"></a><h2>Synopsis</h2><p>ansible &lt;host-pattern&gt; [-f forks] [-m module_name] [-a args]</p></div><div class="refsect1" title="DESCRIPTION"><a id="_description"></a><h2>DESCRIPTION</h2><p><span class="strong"><strong>Ansible</strong></span> is an extra-simple tool/framework/API for doing 'remote things' over
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>ansible</title><link rel="stylesheet" href="./docbook-xsl.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /></head><body><div xml:lang="en" class="refentry" title="ansible" lang="en"><a id="id564661"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>ansible — run a command somewhere else</p></div><div class="refsynopsisdiv" title="Synopsis"><a id="_synopsis"></a><h2>Synopsis</h2><p>ansible &lt;host-pattern&gt; [-f forks] [-m module_name] [-a args]</p></div><div class="refsect1" title="DESCRIPTION"><a id="_description"></a><h2>DESCRIPTION</h2><p><span class="strong"><strong>Ansible</strong></span> is an extra-simple tool/framework/API for doing 'remote things' over
SSH.</p></div><div class="refsect1" title="ARGUMENTS"><a id="_arguments"></a><h2>ARGUMENTS</h2><div class="variablelist"><dl><dt><span class="term">
<span class="strong"><strong>host-pattern</strong></span>
</span></dt><dd>

View file

@ -24,7 +24,7 @@
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Ansible v0.0.1 documentation" href="index.html" />
<link rel="next" title="YAML Format" href="YAMLScripts.html" />
<link rel="prev" title="Examples" href="examples.html" />
<link rel="prev" title="Command Line Examples" href="examples.html" />
</head>
<body>
<div class="related">
@ -37,7 +37,7 @@
<a href="YAMLScripts.html" title="YAML Format"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="examples.html" title="Examples"
<a href="examples.html" title="Command Line Examples"
accesskey="P">previous</a> |</li>
<li><a href="index.html">Ansible v0.0.1 documentation</a> &raquo;</li>
</ul>
@ -55,11 +55,11 @@ ansible playbooks.</p>
<div class="admonition-see-also admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt><a class="reference internal" href="examples.html"><em>Examples</em></a></dt>
<dt><a class="reference internal" href="examples.html"><em>Command Line Examples</em></a></dt>
<dd>Examples of using modules in /usr/bin/ansible</dd>
<dt><a class="reference internal" href="playbooks.html"><em>Playbooks: Ansible for Deployment, Configuration Management, and Orchestration</em></a></dt>
<dd>Examples of using modules with /usr/bin/ansible-playbook</dd>
<dt><a class="reference internal" href="api.html"><em>API</em></a></dt>
<dt><a class="reference internal" href="api.html"><em>Using the Python API</em></a></dt>
<dd>Examples of using modules with the Python API</dd>
</dl>
</div>
@ -216,7 +216,7 @@ the command line, passing them arguments just like they would be passed with ans
<h4>Previous topic</h4>
<p class="topless"><a href="examples.html"
title="previous chapter">Examples</a></p>
title="previous chapter">Command Line Examples</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="YAMLScripts.html"
title="next chapter">YAML Format</a></p>
@ -252,14 +252,14 @@ the command line, passing them arguments just like they would be passed with ans
<a href="YAMLScripts.html" title="YAML Format"
>next</a> |</li>
<li class="right" >
<a href="examples.html" title="Examples"
<a href="examples.html" title="Command Line Examples"
>previous</a> |</li>
<li><a href="index.html">Ansible v0.0.1 documentation</a> &raquo;</li>
</ul>
</div>
<div class="footer">
&copy; Copyright 2012 Michael DeHaan.
Last updated on Mar 08, 2012.
Last updated on Mar 09, 2012.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.8.
</div>
</body>

View file

@ -23,7 +23,7 @@
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Ansible v0.0.1 documentation" href="index.html" />
<link rel="next" title="Examples" href="examples.html" />
<link rel="next" title="Command Line Examples" href="examples.html" />
<link rel="prev" title="Getting Started" href="gettingstarted.html" />
</head>
<body>
@ -34,7 +34,7 @@
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="examples.html" title="Examples"
<a href="examples.html" title="Command Line Examples"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="gettingstarted.html" title="Getting Started"
@ -54,7 +54,7 @@
<div class="admonition-see-also admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt><a class="reference internal" href="examples.html"><em>Examples</em></a></dt>
<dt><a class="reference internal" href="examples.html"><em>Command Line Examples</em></a></dt>
<dd>Examples of basic commands</dd>
<dt><a class="reference internal" href="playbooks.html"><em>Playbooks: Ansible for Deployment, Configuration Management, and Orchestration</em></a></dt>
<dd>Learning ansible&#8217;s configuration management language</dd>
@ -124,7 +124,7 @@ webservers:dbservers</pre>
title="previous chapter">Getting Started</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="examples.html"
title="next chapter">Examples</a></p>
title="next chapter">Command Line Examples</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/patterns.txt"
@ -154,7 +154,7 @@ webservers:dbservers</pre>
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="examples.html" title="Examples"
<a href="examples.html" title="Command Line Examples"
>next</a> |</li>
<li class="right" >
<a href="gettingstarted.html" title="Getting Started"
@ -164,7 +164,7 @@ webservers:dbservers</pre>
</div>
<div class="footer">
&copy; Copyright 2012 Michael DeHaan.
Last updated on Mar 08, 2012.
Last updated on Mar 09, 2012.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.8.
</div>
</body>

View file

@ -23,7 +23,7 @@
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Ansible v0.0.1 documentation" href="index.html" />
<link rel="next" title="API" href="api.html" />
<link rel="next" title="Using the Python API" href="api.html" />
<link rel="prev" title="YAML Format" href="YAMLScripts.html" />
</head>
<body>
@ -34,7 +34,7 @@
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="api.html" title="API"
<a href="api.html" title="Using the Python API"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="YAMLScripts.html" title="YAML Format"
@ -91,8 +91,7 @@ back on the webservers group, etc:</p>
</div>
<div class="section" id="hosts-line">
<h2>Hosts line<a class="headerlink" href="#hosts-line" title="Permalink to this headline"></a></h2>
<p>The hosts line is a list of one or more groups or host patterns, seperated by colons, as
described in the &#8216;patterns&#8217; documentation. This is just like the first parameter to /usr/bin/ansible.</p>
<p>The hosts line is a list of one or more groups or host patterns, seperated by colons, asdescribed in the &#8216;patterns&#8217; documentation. This is just like the first parameter to /usr/bin/ansible.</p>
</div>
<div class="section" id="vars-section">
<h2>Vars section<a class="headerlink" href="#vars-section" title="Permalink to this headline"></a></h2>
@ -168,6 +167,51 @@ in a wordpress.yml file, and use it like so:</p>
</div>
<p>In addition to the explicitly passed in parameters, all variables from the vars section
are also available.</p>
<p>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:</p>
<div class="highlight-python"><pre>---
- name: no selinux
action: command /usr/sbin/setenforce 0
- name: no iptables
action: service name=iptables state=stopped
- name: this is just to show variables work here, favcolor={{ favcolor }}
action: command /bin/true</pre>
</div>
<p>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.</p>
<p>Note that include statements are only usable from the top level playbook file.
At this time, includes can not include other includes.</p>
</div>
<div class="section" id="using-includes-to-assign-classes-of-systems">
<h2>Using Includes To Assign Classes of Systems<a class="headerlink" href="#using-includes-to-assign-classes-of-systems" title="Permalink to this headline"></a></h2>
<p>Include files are best used to reuse logic between playbooks. You could imagine
a playbook describing your entire infrastructure like this:</p>
<div class="highlight-python"><pre>---
- hosts: atlanta-webservers
vars:
datacenter: atlanta
tasks:
- include: base.yml
- include: webservers.yml database=db.atlanta.com
handlers:
- include: generic-handlers.yml
- hosts: atlanta-dbservers
vars:
datacenter: atlanta
tasks:
- include: base.yml
- include: dbservers.yml
handlers:
- include: generic-handlers.yml</pre>
</div>
<p>There is one (or more) play defined for each group of systems, and each play maps
each group includes one or more &#8216;class definitions&#8217; telling the systems what they
are supposed to do or be.</p>
<p>Using a common handlers file could allow one task in &#8216;webservers&#8217; to define &#8216;restart apache&#8217;,
and it could be reused between multiple plays.</p>
<p>Variables like &#8216;database&#8217; above can be used in templates referenced from the
configuration file to generate machine specific variables.</p>
</div>
<div class="section" id="asynchronous-actions-and-polling">
<h2>Asynchronous Actions and Polling<a class="headerlink" href="#asynchronous-actions-and-polling" title="Permalink to this headline"></a></h2>
@ -198,6 +242,7 @@ are also available.</p>
<li><a class="reference internal" href="#notify-statements">Notify statements</a></li>
<li><a class="reference internal" href="#handlers">Handlers</a></li>
<li><a class="reference internal" href="#includes">Includes</a></li>
<li><a class="reference internal" href="#using-includes-to-assign-classes-of-systems">Using Includes To Assign Classes of Systems</a></li>
<li><a class="reference internal" href="#asynchronous-actions-and-polling">Asynchronous Actions and Polling</a></li>
<li><a class="reference internal" href="#executing-a-playbook">Executing A Playbook</a></li>
</ul>
@ -209,7 +254,7 @@ are also available.</p>
title="previous chapter">YAML Format</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="api.html"
title="next chapter">API</a></p>
title="next chapter">Using the Python API</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/playbooks.txt"
@ -239,7 +284,7 @@ are also available.</p>
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="api.html" title="API"
<a href="api.html" title="Using the Python API"
>next</a> |</li>
<li class="right" >
<a href="YAMLScripts.html" title="YAML Format"
@ -249,7 +294,7 @@ are also available.</p>
</div>
<div class="footer">
&copy; Copyright 2012 Michael DeHaan.
Last updated on Mar 08, 2012.
Last updated on Mar 09, 2012.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.8.
</div>
</body>

View file

@ -90,7 +90,7 @@
</div>
<div class="footer">
&copy; Copyright 2012 Michael DeHaan.
Last updated on Mar 08, 2012.
Last updated on Mar 09, 2012.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.8.
</div>
</body>

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,5 @@
API
```
Using the Python API
====================
The Python API is very powerful, and is how the ansible CLI and ansible-playbook
are implemented.
@ -32,4 +32,42 @@ expressed in the 'ansible-modules' documentation.::
A module can return any type of JSON data it wants, so Ansible can
be used as a framework to rapidly build powerful applications and scripts.
Detailed API Example
````````````````````
The following script prints out the uptime information for all hosts::
#!/usr/bin/python
import ansible.runner
import sys
# construct the ansible runner and execute on all hosts
results = ansible.runner.Runner(
pattern='*', forks=10,
module_name='command', module_args=['/usr/bin/uptime'],
).run()
if results is None:
print "No hosts found"
sys.exit(1)
print "UP ***********"
for (hostname, result) in results['contacted'].items():
if not 'failed' in result:
print "%s >>> %s" % (hostname, result['stdout'])
print "FAILED *******"
for (hostname, result) in results['contacted'].items():
if 'failed' in result:
print "%s >>> %s" % (hostname, result['msg'])
print "DOWN *********"
for (hostname, result) in results['dark'].items():
print "%s >>> %s" % (hostname, result)
Advanced programmers may also wish to read the source to ansible itself, for
it uses the Runner() API (with all available options) to implement the
command line tools ``ansible`` and ``ansible-playbook``.

View file

@ -1,5 +1,9 @@
Examples
========
Command Line Examples
=====================
The following examples show how to use `/usr/bin/ansible` for running ad-hoc tasks.
Start here. For configuration management and deployments, you'll want to pick up on
using `/usr/bin/ansible-playbook` -- the concepts port over directly.
.. seealso::
@ -24,19 +28,6 @@ The -f 10 specifies the usage of 10 simultaneous processes.
Note that other than the command module, ansible modules do not work like simple scripts. They make the remote system look like you state, and run the commands neccessary to get it there. This is commonly refered to
as 'idempotency'.
Time Limited Background Operations
``````````````````````````````````
Long running operations can be backgrounded, and their status can be checked on later. The same job ID is given to the same task on all hosts, so you won't lose track. Polling support is pending in the command line.::
ansible all -B 3600 -a "/usr/bin/long_running_operation --do-stuff"
ansible all -n job_status -a jid=123456789
Any module other than 'copy' or 'template' can be backgrounded. Typically you'll be backgrounding shell
commands or software upgrades only.
After the time limit (in seconds) runs out (-B), the process on the remote nodes will be killed.
File Transfer & Templating
``````````````````````````
@ -74,4 +65,17 @@ Alternatively, restart a service on all webservers::
ansible webservers -m service name=httpd state=restarted
Time Limited Background Operations
``````````````````````````````````
Long running operations can be backgrounded, and their status can be checked on later. The same job ID is given to the same task on all hosts, so you won't lose track. Polling support is pending in the command line.::
ansible all -B 3600 -a "/usr/bin/long_running_operation --do-stuff"
ansible all -n job_status -a jid=123456789
Any module other than 'copy' or 'template' can be backgrounded. Typically you'll be backgrounding shell
commands or software upgrades only.
After the time limit (in seconds) runs out (-B), the process on the remote nodes will be killed.

View file

@ -47,8 +47,7 @@ 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, as
described 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, asdescribed in the 'patterns' documentation. This is just like the first parameter to /usr/bin/ansible.
Vars section
````````````
@ -140,6 +139,58 @@ in a wordpress.yml file, and use it like so::
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::
---
- name: no selinux
action: command /usr/sbin/setenforce 0
- name: no iptables
action: service name=iptables state=stopped
- 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.
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::
---
- hosts: atlanta-webservers
vars:
datacenter: atlanta
tasks:
- include: base.yml
- include: webservers.yml database=db.atlanta.com
handlers:
- include: generic-handlers.yml
- hosts: atlanta-dbservers
vars:
datacenter: atlanta
tasks:
- include: base.yml
- include: dbservers.yml
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.
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.
Asynchronous Actions and Polling
````````````````````````````````