Lorem ipsum dolor sit amet, consectetur adipiscing elit. In dignissim
placerat nibh, non feugiat risus varius vitae. Donec eu libero
lectus. Ut non orci felis, eget mattis mauris. Etiam ut tellus in
magna porta venenatis. Quisque scelerisque, sem non ultrices bibendum,
dolor diam rutrum lectus, sed luctus neque neque vitae eros. Vivamus
mattis, ipsum ut bibendum gravida, lectus arcu venenatis elit, vitae
luctus diam leo sit amet ligula. Nunc egestas justo in nulla sagittis
ut suscipit sapien gravida. Morbi id dui nibh. Nullam diam massa,
rhoncus a dignissim non, adipiscing vel arcu. Quisque ultricies
tincidunt purus ut sodales. Quisque scelerisque dapibus purus quis
egestas. Maecenas sagittis porttitor adipiscing. Duis eu magna
sem. Donec arcu felis, faucibus et malesuada non, blandit vitae
metus. Fusce nec sapien dolor.
Examples 2
``````````
Aenean ac fermentum nisl. Integer leo sem, rutrum nec dictum at,
pretium quis sapien. Duis felis metus, sodales sit amet gravida in,
pretium ut arcu. Nulla ligula quam, aliquam sit amet sollicitudin
eget, molestie tincidunt ipsum. Nulla leo nunc, mattis sed auctor at,
suscipit ut metus. Suspendisse hendrerit, justo sagittis malesuada
molestie, nisi nunc placerat libero, vel vulputate elit tellus et
augue. Phasellus tempor lectus ac nisi aliquam faucibus. Donec feugiat
egestas nibh id mattis. In hac habitasse platea dictumst. Ut accumsan
lorem eget leo dictum viverra.
Examples 3
``````````
Quisque egestas lorem sit amet felis tincidunt adipiscing. Aenean
ornare fermentum accumsan. Aenean eu mauris arcu, id pulvinar
quam. Suspendisse nec massa vel augue laoreet ultricies in convallis
dolor. Mauris sodales porta enim, non ultricies dolor luctus
in. Phasellus eu tortor lectus, vel porttitor nulla. Mauris vulputate,
erat id scelerisque lobortis, nibh ipsum tristique elit, ac viverra
arcu sem a ante. Praesent nec metus vestibulum augue eleifend
suscipit. In feugiat, sem nec dignissim consequat, velit tortor
scelerisque metus, sit amet mollis nisl sem eu nibh. Quisque in nibh
turpis. Proin ac nisi ligula, a pretium augue.
Examples 3
``````````
In nibh eros, laoreet id interdum vel, sodales sed tortor. Sed
ullamcorper, sem vel mattis consectetur, nibh turpis molestie nisl,
eget lobortis mi magna sed metus. Cras justo est, tempus quis
adipiscing ut, hendrerit convallis sem. Mauris ullamcorper, sapien et
luctus iaculis, urna elit egestas ipsum, et tristique enim risus vitae
nunc. Vivamus aliquet lorem eu urna pulvinar hendrerit malesuada nunc
sollicitudin. Cras in mi rhoncus quam egestas dignissim vel sit amet
lacus. Maecenas interdum viverra laoreet. Quisque elementum
sollicitudin ullamcorper.
Examples 4
``````````
Pellentesque mauris sem, malesuada at lobortis in, porta eget
urna. Duis aliquet quam eget risus elementum quis auctor ligula
gravida. Phasellus et ullamcorper libero. Nam elementum ultricies
tellus, in sagittis magna aliquet quis. Ut sit amet tellus id erat
tristique lobortis. Suspendisse est enim, tristique eu convallis id,
rutrum nec lacus. Fusce iaculis diam non felis rutrum lobortis. Proin
hendrerit mi tincidunt dui fermentum placerat.
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::
:doc:`modules`
A list of available modules
:doc:`playbooks`
Alternative ways to use ansible
Parallelism and Shell Commands
``````````````````````````````
Let's use ansible's command line tool to reboot all web servers in Atlanta, 10 at a time::
ssh-agent bash
ssh-add ~/.ssh/id_rsa.pub
ansible atlanta -a "/sbin/reboot" -f 10
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'.
File Transfer & Templating
``````````````````````````
Ansible can SCP lots of files to multiple machines in parallel, and optionally use them as template sources.
To just transfer a file directly to many different servers::
ansible atlanta copy -a "/etc/hosts /tmp/hosts"
To use templating, first run the setup module to put the template variables you would like to use on the remote host. Then use the template module to write the files using the templates. Templates are written in Jinja2 format. Playbooks (covered elsewhere in the documentation) will run the setup module for you, making this even simpler.::
ansible webservers -m setup -a "favcolor=red ntp_server=192.168.1.1"
ansible webservers -m template -a "src=/srv/motd.j2 dest=/etc/motd"
ansible webservers -m template -a "src=/srv/ntp.j2 dest=/etc/ntp.conf"
Need something like the fqdn in a template? If facter or ohai are installed, data from these projects will also be made available to the template engine, using 'facter' and 'ohai' prefixes for each.
Deploying From Source Control
`````````````````````````````
Deploy your webapp straight from git::
ansible webservers -m git -a "repo=git://foo dest=/srv/myapp version=HEAD"
Since ansible modules can notify change handlers (see 'Playbooks') it is possible to tell ansible to run specific tasks when the code is updated, such as deploying Perl/Python/PHP/Ruby directly from git and then restarting apache.
Managing Services
`````````````````
Ensure a service is started on all webservers::
ansible webservers -m service name=httpd state=started
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.
Ansible is a extra-simple tool/API for doing 'parallel remote things'
over SSH -- whether executing commands, running "modules", or
executing larger 'playbooks' that can serve as a configuration
management or deployment system.
While `Func installation <http://fedorahosted.org/func>`_ which I
co-wrote, aspired to avoid using SSH and have it's own daemon
infrastructure, Ansible aspires to be quite different and more
minimal, but still able to grow more modularly over time. This is
based on talking to a lot of users of various tools and wishing to
eliminate problems with connectivity and long running daemons, or not
picking tool `X` because they preferred to code in `Y`. Further,
playbooks take things a whole step further, building the config and
deployment system I always wanted to build.
Why use Ansible versus something else? (Fabric, Capistrano,
mCollective, Func, SaltStack, etc?) It will have far less code, it
will be more correct, and it will be the easiest thing to hack on and
Ansible is a radically simple deployment, configuration, and command execution framework.
Other tools in this space have been too complicated for too long, require too much bootstrapping,
and have too much learning curve. Ansible is dead simple and painless to extend. For comparison, Puppet and Chef have about 60k lines of code. Ansible's core is a little over 1000 lines.
Ansible isn't just for configuration -- it's also great for Ad-Hoc tasks,
quickly firing off commands against nodes. Where Ansible excels though, is expressing complex multi-node deployment processes, executing complex sequences of commands on different hosts through "playbooks".
Extending ansible does not require programming in any particular language -- you can write modules
as scripts or programs that return simple JSON. It's also trivially easy to just execute
useful shell commands.
Why use Ansible versus something else? (Puppet, Chef, Fabric, Capistrano,
mCollective, Func, SaltStack, etc?) Ansible will have far less code, it
will be (by extension) more correct, and it will be the easiest thing to hack on and
use you'll ever see -- regardless of your favorite language of choice.
Want to only code plugins in bash or clojure? Ansible doesn't care.
The docs will fit on one page and the source will be blindingly
obvious.
Systems management doesn't have to be complicated. Ansible's docs will remain
short & simple, and the source will be blindingly obvious.
Design Principles
`````````````````
Design Goals
````````````
* Dead simple setup
* Super fast & parallel by default
* No server or client daemons; use existing SSHd
* No server or client daemons; use existing SSHd out of the box
* No additional software required on client boxes
* Modules can be written in ANY language
* Awesome API for creating very powerful distributed scripts
* Be usable as non-root
* Be very usable as non-root
* Create the easiest config management system to use, ever.
Communicate and Get Involved
````````````````````````````
Requirements
````````````
Requirements are extremely minimal.
If you are running python 2.6 on the **overlord** machine, you will
need:
* ``paramiko``
* ``PyYAML``
* ``python-jinja2`` (for playbooks)
* ``Asciidoc`` (for building documentation)
If you are running less than Python 2.6, you will also need:
* The Python 2.4 or 2.5 backport of the ``multiprocessing`` module
- `Installation and Testing Instructions <http://code.google.com/p/python-multiprocessing/wiki/Install>`_
* ``simplejson``
On the managed nodes, to use templating, you will need:
* ``python-jinja2`` (you can install this with ansible)
Getting Ansible
```````````````
Tagged releases are available as tar.gz files from the Ansible github
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In dignissim
placerat nibh, non feugiat risus varius vitae. Donec eu libero
lectus. Ut non orci felis, eget mattis mauris. Etiam ut tellus in
magna porta venenatis. Quisque scelerisque, sem non ultrices bibendum,
dolor diam rutrum lectus, sed luctus neque neque vitae eros. Vivamus
mattis, ipsum ut bibendum gravida, lectus arcu venenatis elit, vitae
luctus diam leo sit amet ligula. Nunc egestas justo in nulla sagittis
ut suscipit sapien gravida. Morbi id dui nibh. Nullam diam massa,
rhoncus a dignissim non, adipiscing vel arcu. Quisque ultricies
tincidunt purus ut sodales. Quisque scelerisque dapibus purus quis
egestas. Maecenas sagittis porttitor adipiscing. Duis eu magna
sem. Donec arcu felis, faucibus et malesuada non, blandit vitae
metus. Fusce nec sapien dolor.
Aenean ac fermentum nisl. Integer leo sem, rutrum nec dictum at,
pretium quis sapien. Duis felis metus, sodales sit amet gravida in,
pretium ut arcu. Nulla ligula quam, aliquam sit amet sollicitudin
eget, molestie tincidunt ipsum. Nulla leo nunc, mattis sed auctor at,
suscipit ut metus. Suspendisse hendrerit, justo sagittis malesuada
molestie, nisi nunc placerat libero, vel vulputate elit tellus et
augue. Phasellus tempor lectus ac nisi aliquam faucibus. Donec feugiat
egestas nibh id mattis. In hac habitasse platea dictumst. Ut accumsan
lorem eget leo dictum viverra.
Quisque egestas lorem sit amet felis tincidunt adipiscing. Aenean
ornare fermentum accumsan. Aenean eu mauris arcu, id pulvinar
quam. Suspendisse nec massa vel augue laoreet ultricies in convallis
dolor. Mauris sodales porta enim, non ultricies dolor luctus
in. Phasellus eu tortor lectus, vel porttitor nulla. Mauris vulputate,
erat id scelerisque lobortis, nibh ipsum tristique elit, ac viverra
arcu sem a ante. Praesent nec metus vestibulum augue eleifend
suscipit. In feugiat, sem nec dignissim consequat, velit tortor
scelerisque metus, sit amet mollis nisl sem eu nibh. Quisque in nibh
turpis. Proin ac nisi ligula, a pretium augue.
In nibh eros, laoreet id interdum vel, sodales sed tortor. Sed
ullamcorper, sem vel mattis consectetur, nibh turpis molestie nisl,
eget lobortis mi magna sed metus. Cras justo est, tempus quis
adipiscing ut, hendrerit convallis sem. Mauris ullamcorper, sapien et
luctus iaculis, urna elit egestas ipsum, et tristique enim risus vitae
nunc. Vivamus aliquet lorem eu urna pulvinar hendrerit malesuada nunc
sollicitudin. Cras in mi rhoncus quam egestas dignissim vel sit amet
lacus. Maecenas interdum viverra laoreet. Quisque elementum
sollicitudin ullamcorper.
Pellentesque mauris sem, malesuada at lobortis in, porta eget
urna. Duis aliquet quam eget risus elementum quis auctor ligula
gravida. Phasellus et ullamcorper libero. Nam elementum ultricies
tellus, in sagittis magna aliquet quis. Ut sit amet tellus id erat
tristique lobortis. Suspendisse est enim, tristique eu convallis id,
rutrum nec lacus. Fusce iaculis diam non felis rutrum lobortis. Proin
hendrerit mi tincidunt dui fermentum placerat.
Ansible Modules
===============
Ansible ships with a number of modules that can be executed directly on remote hosts or through
ansible playbooks.
.. seealso::
:doc:`examples`
Examples of using modules in /usr/bin/ansible
:doc:`playbooks`
Examples of using modules with /usr/bin/ansible-playbook
:doc:`api`
Examples of using modules with the Python API
Nearly all modules take key=value parameters. Some modules take no parameters, and the command
module just takes arguments for the command you want to run.
All modules return JSON format data, thoug if you are using the command line or playbooks, you
don't really need to know much about that.
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. Unless otherwise noted, all modules support change hooks.
Stock modules:
command
```````
The command module takes the command name followed by a list of arguments, space delimited.
This is the only module that does not use key=value style parameters.
Example usage::
/sbin/shutdown -t now
The given shell command will be executed on all selected nodes.
This module does not support change hooks and returns the return code from the program as well as timing information about how long the command was running for.
copy
````
The copy module moves a file on the local box to remote locations.
*src*::
Local path to a file to copy to the remote server. This can be an absolute or relative path.
*dest*::
Remote absolute path where the file should end up.
This module also returns md5sum information about the resultant file.
facter
``````
Runs the discovery program 'facter' on the remote system, returning
JSON data that can be useful for inventory purposes.
Requires that 'facter' and 'ruby-json' be installed on the remote end.
This module is informative only - it takes no parameters & does not support change hooks,
nor does it make any changes on the system. Playbooks do not actually use
this module, they use the 'setup' module behind the scenes.
git
```
Deploys software (or files) from git checkouts.
*repo*::
git or http protocol address of the repo to checkout
*dest*::
where to check it out, an absolute directory path
*version*::
what version to check out -- either the git SHA, the literal string 'HEAD', or a tag name
ohai
````
Similar to the facter module, this returns JSON inventory data. Ohai
data is a bit more verbose and nested than facter.
Requires that 'ohai' be installed on the remote end.
This module is information only - it takes no parameters & does not
support change hooks, nor does it make any changes on the system.
Playbooks should not call the ohai module, playbooks call the 'setup'
module behind the scenes instead.
ping
````
A trivial test module, this module always returns the integer '1' on
successful contact.
This module does not support change hooks and is informative only - it takes no parameters & does not
support change hooks, nor does it make any changes on the system.
service
```````
Controls services on remote machines.
*state*
Values are 'started', 'stopped', or 'restarted'. Started/stopped
are idempotent actions that will not run commands unless neccessary.
'restarted' will always bounce the service
*name*
The name of the service
setup
`````
Writes a JSON file containing key/value data, for use in templating.
Call this once before using the template modules. Playbooks will
execute this module automatically as the first step in each play using
the variables section, so it is unneccessary to make explicit calls to
setup within a playbook.
If facter or ohai are installed, variables from these programs will also
be snapshotted into the JSON file for usage in templating. These variables
are prefixed with 'facter_' and 'ohai_" so it's easy to tell their source.
All variables are then bubbled up to the caller.
*anything*
any other parameters can be named basically anything, and set a key=value
pair in the JSON file for use in templating.
template
````````
Templates a file out to a remote server. Call the setup module prior to usage.
*src*
path of a Jinja2 formatted template on the local server. This can be a relative
or absolute path.
*dest*
location to render the template on the remote server
This module also returns md5sum information about the resultant file.
Writing your own modules
````````````````````````
To write your own modules, simply follow the convention of those already available in
/usr/share/ansible. Modules must return JSON but can be written in any language.
Modules should return hashes, but hashes can be nested.
To support change hooks, modules should return hashes with a changed: True/False
element at the top level::
{
'changed' : True,
'something' : 42
}
Modules can also choose to indicate a failure scenario by returning a top level 'failure'
element with a True value, and a 'msg' element describing the nature of the failure.
Other return values are up to the module.
{
'failure' : True,
'msg' : "here is what happened..."
}
When shipping modules, drop them in /usr/share/ansible, or specify the module path to the
command line tool or API. It is easy to test modules by running them directly on
the command line, passing them arguments just like they would be passed with ansible.
Learn about available modules and writing your own
:doc:`patterns`
Learn about how to select hosts
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.
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
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
````````````
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
<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 <ttclass="docutils literal"><spanclass="pre">ansible</span></tt> and <ttclass="docutils literal"><spanclass="pre">ansible-playbook</span></tt>.</p>
</div>
</div>
...
...
@@ -106,12 +123,20 @@ hendrerit mi tincidunt dui fermentum placerat.</p>
</div>
<divclass="sphinxsidebar">
<divclass="sphinxsidebarwrapper">
<h3><ahref="index.html">Table Of Contents</a></h3>
<ul>
<li><aclass="reference internal"href="#">Using the Python API</a><ul>
<li><aclass="reference internal"href="#detailed-api-example">Detailed API Example</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<pclass="topless"><ahref="examples.html"
title="previous chapter">Examples</a></p>
<pclass="topless"><ahref="playbooks.html"
title="previous chapter">Playbooks: Ansible for Deployment, Configuration Management, and Orchestration</a></p>
<h4>Next topic</h4>
<pclass="topless"><ahref="communicate.html"
title="next chapter">Communicate</a></p>
<pclass="topless"><ahref="man.html"
title="next chapter">Man Pages</a></p>
<h3>This Page</h3>
<ulclass="this-page-menu">
<li><ahref="_sources/api.txt"
...
...
@@ -120,7 +145,7 @@ hendrerit mi tincidunt dui fermentum placerat.</p>
<h2>Parallelism and Shell Commands<aclass="headerlink"href="#parallelism-and-shell-commands"title="Permalink to this headline">¶</a></h2>
<p>Let’s use ansible’s command line tool to reboot all web servers in Atlanta, 10 at a time:</p>
<divclass="highlight-python"><pre>ssh-agent bash
ssh-add ~/.ssh/id_rsa.pub
ansible atlanta -a "/sbin/reboot" -f 10</pre>
</div>
<p>The -f 10 specifies the usage of 10 simultaneous processes.</p>
<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 ‘idempotency’.</p>
</div>
<divclass="section"id="file-transfer-templating">
<h2>File Transfer & Templating<aclass="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>
<p>To just transfer a file directly to many different servers:</p>
<divclass="highlight-python"><pre>ansible atlanta copy -a "/etc/hosts /tmp/hosts"</pre>
</div>
<p>To use templating, first run the setup module to put the template variables you would like to use on the remote host. Then use the template module to write the files using the templates. Templates are written in Jinja2 format. Playbooks (covered elsewhere in the documentation) will run the setup module for you, making this even simpler.:</p>
<divclass="highlight-python"><pre>ansible webservers -m setup -a "favcolor=red ntp_server=192.168.1.1"
ansible webservers -m template -a "src=/srv/motd.j2 dest=/etc/motd"
ansible webservers -m template -a "src=/srv/ntp.j2 dest=/etc/ntp.conf"</pre>
</div>
<p>Need something like the fqdn in a template? If facter or ohai are installed, data from these projects will also be made available to the template engine, using ‘facter’ and ‘ohai’ prefixes for each.</p>
<h2>Deploying From Source Control<aclass="headerlink"href="#deploying-from-source-control"title="Permalink to this headline">¶</a></h2>
<p>Deploy your webapp straight from git:</p>
<divclass="highlight-python"><pre>ansible webservers -m git -a "repo=git://foo dest=/srv/myapp version=HEAD"</pre>
</div>
<p>Since ansible modules can notify change handlers (see ‘Playbooks’) it is possible to tell ansible to run specific tasks when the code is updated, such as deploying Perl/Python/PHP/Ruby directly from git and then restarting apache.</p>
</div>
<divclass="section"id="managing-services">
<h2>Managing Services<aclass="headerlink"href="#managing-services"title="Permalink to this headline">¶</a></h2>
<p>Ensure a service is started on all webservers:</p>
<divclass="highlight-python"><pre>ansible webservers -m service name=httpd state=started</pre>
</div>
<p>Alternatively, restart a service on all webservers:</p>
<divclass="highlight-python"><pre>ansible webservers -m service name=httpd state=restarted</pre>
</div>
<divclass="section"id="examples-3">
<h2>Examples 3<aclass="headerlink"href="#examples-3"title="Permalink to this headline">¶</a></h2>
<p>Quisque egestas lorem sit amet felis tincidunt adipiscing. Aenean
ornare fermentum accumsan. Aenean eu mauris arcu, id pulvinar
quam. Suspendisse nec massa vel augue laoreet ultricies in convallis
dolor. Mauris sodales porta enim, non ultricies dolor luctus
in. Phasellus eu tortor lectus, vel porttitor nulla. Mauris vulputate,
erat id scelerisque lobortis, nibh ipsum tristique elit, ac viverra
arcu sem a ante. Praesent nec metus vestibulum augue eleifend
suscipit. In feugiat, sem nec dignissim consequat, velit tortor
scelerisque metus, sit amet mollis nisl sem eu nibh. Quisque in nibh
turpis. Proin ac nisi ligula, a pretium augue.</p>
</div>
<divclass="section"id="id1">
<h2>Examples 3<aclass="headerlink"href="#id1"title="Permalink to this headline">¶</a></h2>
<p>In nibh eros, laoreet id interdum vel, sodales sed tortor. Sed
ullamcorper, sem vel mattis consectetur, nibh turpis molestie nisl,
eget lobortis mi magna sed metus. Cras justo est, tempus quis
adipiscing ut, hendrerit convallis sem. Mauris ullamcorper, sapien et
luctus iaculis, urna elit egestas ipsum, et tristique enim risus vitae
nunc. Vivamus aliquet lorem eu urna pulvinar hendrerit malesuada nunc
sollicitudin. Cras in mi rhoncus quam egestas dignissim vel sit amet
lacus. Maecenas interdum viverra laoreet. Quisque elementum
<h2>Time Limited Background Operations<aclass="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’t lose track. Polling support is pending in the command line.:</p>
<divclass="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>
<divclass="section"id="examples-4">
<h2>Examples 4<aclass="headerlink"href="#examples-4"title="Permalink to this headline">¶</a></h2>
<p>Pellentesque mauris sem, malesuada at lobortis in, porta eget
urna. Duis aliquet quam eget risus elementum quis auctor ligula
gravida. Phasellus et ullamcorper libero. Nam elementum ultricies
tellus, in sagittis magna aliquet quis. Ut sit amet tellus id erat
tristique lobortis. Suspendisse est enim, tristique eu convallis id,
rutrum nec lacus. Fusce iaculis diam non felis rutrum lobortis. Proin
hendrerit mi tincidunt dui fermentum placerat.</p>
<p>Any module other than ‘copy’ or ‘template’ can be backgrounded. Typically you’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>
...
...
@@ -123,22 +123,22 @@ hendrerit mi tincidunt dui fermentum placerat.</p>
<divclass="sphinxsidebarwrapper">
<h3><ahref="index.html">Table Of Contents</a></h3>
<h2>What you need<aclass="headerlink"href="#what-you-need"title="Permalink to this headline">¶</a></h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In dignissim
placerat nibh, non feugiat risus varius vitae. Donec eu libero
lectus. Ut non orci felis, eget mattis mauris. Etiam ut tellus in
magna porta venenatis. Quisque scelerisque, sem non ultrices bibendum,
dolor diam rutrum lectus, sed luctus neque neque vitae eros. Vivamus
mattis, ipsum ut bibendum gravida, lectus arcu venenatis elit, vitae
luctus diam leo sit amet ligula. Nunc egestas justo in nulla sagittis
ut suscipit sapien gravida. Morbi id dui nibh. Nullam diam massa,
rhoncus a dignissim non, adipiscing vel arcu. Quisque ultricies
tincidunt purus ut sodales. Quisque scelerisque dapibus purus quis
egestas. Maecenas sagittis porttitor adipiscing. Duis eu magna
sem. Donec arcu felis, faucibus et malesuada non, blandit vitae
metus. Fusce nec sapien dolor.</p>
<p>Aenean ac fermentum nisl. Integer leo sem, rutrum nec dictum at,
pretium quis sapien. Duis felis metus, sodales sit amet gravida in,
pretium ut arcu. Nulla ligula quam, aliquam sit amet sollicitudin
eget, molestie tincidunt ipsum. Nulla leo nunc, mattis sed auctor at,
suscipit ut metus. Suspendisse hendrerit, justo sagittis malesuada
molestie, nisi nunc placerat libero, vel vulputate elit tellus et
augue. Phasellus tempor lectus ac nisi aliquam faucibus. Donec feugiat
egestas nibh id mattis. In hac habitasse platea dictumst. Ut accumsan
lorem eget leo dictum viverra.</p>
<p>Quisque egestas lorem sit amet felis tincidunt adipiscing. Aenean
ornare fermentum accumsan. Aenean eu mauris arcu, id pulvinar
quam. Suspendisse nec massa vel augue laoreet ultricies in convallis
dolor. Mauris sodales porta enim, non ultricies dolor luctus
in. Phasellus eu tortor lectus, vel porttitor nulla. Mauris vulputate,
erat id scelerisque lobortis, nibh ipsum tristique elit, ac viverra
arcu sem a ante. Praesent nec metus vestibulum augue eleifend
suscipit. In feugiat, sem nec dignissim consequat, velit tortor
scelerisque metus, sit amet mollis nisl sem eu nibh. Quisque in nibh
turpis. Proin ac nisi ligula, a pretium augue.</p>
<p>In nibh eros, laoreet id interdum vel, sodales sed tortor. Sed
ullamcorper, sem vel mattis consectetur, nibh turpis molestie nisl,
eget lobortis mi magna sed metus. Cras justo est, tempus quis
adipiscing ut, hendrerit convallis sem. Mauris ullamcorper, sapien et
luctus iaculis, urna elit egestas ipsum, et tristique enim risus vitae
nunc. Vivamus aliquet lorem eu urna pulvinar hendrerit malesuada nunc
sollicitudin. Cras in mi rhoncus quam egestas dignissim vel sit amet
lacus. Maecenas interdum viverra laoreet. Quisque elementum
sollicitudin ullamcorper.</p>
<p>Pellentesque mauris sem, malesuada at lobortis in, porta eget
urna. Duis aliquet quam eget risus elementum quis auctor ligula
gravida. Phasellus et ullamcorper libero. Nam elementum ultricies
tellus, in sagittis magna aliquet quis. Ut sit amet tellus id erat
tristique lobortis. Suspendisse est enim, tristique eu convallis id,
rutrum nec lacus. Fusce iaculis diam non felis rutrum lobortis. Proin
hendrerit mi tincidunt dui fermentum placerat.</p>
<divclass="section"id="requirements">
<h2>Requirements<aclass="headerlink"href="#requirements"title="Permalink to this headline">¶</a></h2>
<p>Requirements for Ansible are extremely minimal.</p>
<p>If you are running python 2.6 on the <strong>overlord</strong> machine (the machine that you’ll be talking to the other machines from), you will need:</p>
<h1>Ansible<aclass="headerlink"href="#ansible"title="Permalink to this headline">¶</a></h1>
<p>Ansible is a extra-simple tool/API for doing ‘parallel remote things’
over SSH – whether executing commands, running “modules”, or
executing larger ‘playbooks’ that can serve as a configuration
management or deployment system.</p>
<p>While <aclass="reference external"href="http://fedorahosted.org/func">Func installation</a> which I
co-wrote, aspired to avoid using SSH and have it’s own daemon
infrastructure, Ansible aspires to be quite different and more
minimal, but still able to grow more modularly over time. This is
based on talking to a lot of users of various tools and wishing to
eliminate problems with connectivity and long running daemons, or not
picking tool <cite>X</cite> because they preferred to code in <cite>Y</cite>. Further,
playbooks take things a whole step further, building the config and
deployment system I always wanted to build.</p>
<p>Why use Ansible versus something else? (Fabric, Capistrano,
mCollective, Func, SaltStack, etc?) It will have far less code, it
will be more correct, and it will be the easiest thing to hack on and
use you’ll ever see – regardless of your favorite language of choice.
Want to only code plugins in bash or clojure? Ansible doesn’t care.
The docs will fit on one page and the source will be blindingly
obvious.</p>
<divclass="section"id="design-principles">
<h2>Design Principles<aclass="headerlink"href="#design-principles"title="Permalink to this headline">¶</a></h2>
<p>Ansible is a radically simple deployment, configuration, and command execution framework.
Other tools in this space have been too complicated for too long, require too much bootstrapping,
and have too much learning curve. Ansible is dead simple and painless to extend. For comparison, Puppet and Chef have about 60k lines of code. Ansible’s core is a little over 1000 lines.</p>
<p>Ansible isn’t just for configuration – it’s also great for Ad-Hoc tasks,
quickly firing off commands against nodes. Where Ansible excels though, is expressing complex multi-node deployment processes, executing complex sequences of commands on different hosts through “playbooks”.</p>
<p>Extending ansible does not require programming in any particular language – you can write modules
as scripts or programs that return simple JSON. It’s also trivially easy to just execute
useful shell commands.</p>
<p>Why use Ansible versus something else? (Puppet, Chef, Fabric, Capistrano,
mCollective, Func, SaltStack, etc?) Ansible will have far less code, it
will be (by extension) more correct, and it will be the easiest thing to hack on and
use you’ll ever see – regardless of your favorite language of choice.</p>
<p>Systems management doesn’t have to be complicated. Ansible’s docs will remain
short & simple, and the source will be blindingly obvious.</p>
<divclass="section"id="design-goals">
<h2>Design Goals<aclass="headerlink"href="#design-goals"title="Permalink to this headline">¶</a></h2>
<ulclass="simple">
<li>Dead simple setup</li>
<li>Super fast & parallel by default</li>
<li>No server or client daemons; use existing SSHd</li>
<li>No server or client daemons; use existing SSHd out of the box</li>
<li>No additional software required on client boxes</li>
<li>Modules can be written in ANY language</li>
<li>Awesome API for creating very powerful distributed scripts</li>
<li>Be usable as non-root</li>
<li>Be very usable as non-root</li>
<li>Create the easiest config management system to use, ever.</li>
</ul>
</div>
<divclass="section"id="requirements">
<h2>Requirements<aclass="headerlink"href="#requirements"title="Permalink to this headline">¶</a></h2>
<p>Requirements are extremely minimal.</p>
<p>If you are running python 2.6 on the <strong>overlord</strong> machine, you will
<li><ttclass="docutils literal"><spanclass="pre">Asciidoc</span></tt> (for building documentation)</li>
</ul>
<p>If you are running less than Python 2.6, you will also need:</p>
<ulclass="simple">
<li>The Python 2.4 or 2.5 backport of the <ttclass="docutils literal"><spanclass="pre">multiprocessing</span></tt> module<ul>
<li><aclass="reference external"href="http://code.google.com/p/python-multiprocessing/wiki/Install">Installation and Testing Instructions</a></li>
<li>Join the <aclass="reference external"href="http://groups.google.com/group/ansible-project">ansible-project mailing list</a> on Google Groups</li>
<li>Join <aclass="reference external"href="irc://irc.freenode.net/#ansible">#ansible</a> on the <aclass="reference external"href="http://freenode.net/">freenode IRC network</a></li>
<li>Visit the <aclass="reference external"href="https://github.com/ansible/ansible">project page</a> on Github<ul>
<li>View the <aclass="reference external"href="https://github.com/ansible/ansible/issues">issue tracker</a></li>
<liclass="toctree-l1"><aclass="reference internal"href="playbooks.html">Playbooks: Ansible for Deployment, Configuration Management, and Orchestration</a><ul>
<liclass="toctree-l2"><aclass="reference internal"href="playbooks.html#using-includes-to-assign-classes-of-systems">Using Includes To Assign Classes of Systems</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="playbooks.html#asynchronous-actions-and-polling">Asynchronous Actions and Polling</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="playbooks.html#executing-a-playbook">Executing A Playbook</a></li>
</ul>
</li>
<liclass="toctree-l1"><aclass="reference internal"href="api.html">Using the Python API</a><ul>
<liclass="toctree-l2"><aclass="reference internal"href="api.html#detailed-api-example">Detailed API Example</a></li>
<h1>Communicate or Get Involved<aclass="headerlink"href="#communicate-or-get-involved"title="Permalink to this headline">¶</a></h1>
<ulclass="simple">
<li>Join the <aclass="reference external"href="http://groups.google.com/group/ansible-project">ansible-project mailing list</a> on Google Groups</li>
<li>Join <aclass="reference external"href="irc://irc.freenode.net/#ansible">#ansible</a> on the <aclass="reference external"href="http://freenode.net/">freenode IRC network</a></li>
<li>Visit the <aclass="reference external"href="https://github.com/ansible/ansible">project page</a> on Github<ul>
<li>View the <aclass="reference external"href="https://github.com/ansible/ansible/issues">issue tracker</a></li>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"/><title>ansible-modules</title><linkrel="stylesheet"type="text/css"href="./docbook-xsl.css"/><metaname="generator"content="DocBook XSL Stylesheets V1.76.1"/></head><body><divxml:lang="en"class="refentry"title="ansible-modules"lang="en"><aid="id327073"></a><divclass="titlepage"></div><divclass="refnamediv"><h2>Name</h2><p>ansible-modules — stock modules shipped with ansible</p></div><divclass="refsect1"title="DESCRIPTION"><aid="_description"></a><h2>DESCRIPTION</h2><p>Ansible ships with a number of modules that can be executed directly on remote hosts or through
<htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"/><title>ansible-modules</title><linkrel="stylesheet"href="./docbook-xsl.css"type="text/css"/><metaname="generator"content="DocBook XSL Stylesheets V1.75.2"/></head><body><divxml:lang="en"class="refentry"title="ansible-modules"lang="en"><aid="id373277"></a><divclass="titlepage"></div><divclass="refnamediv"><h2>Name</h2><p>ansible-modules — stock modules shipped with ansible</p></div><divclass="refsect1"title="DESCRIPTION"><aid="_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><divclass="refsect1"title="IDEMPOTENCE"><aid="_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 <spanclass="strong"><strong>ansible-playbooks</strong></span>(5).</p><p>Unless otherwise noted, all modules support change hooks.</p></div><divclass="refsect1"title="command"><aid="_command"></a><h2>command</h2><p>The command module takes the command name followed by a list of arguments, space delimited.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"/><title>ansible-modules</title><linkrel="stylesheet"type="text/css"href="./docbook-xsl.css"/><metaname="generator"content="DocBook XSL Stylesheets V1.76.1"/></head><body><divxml:lang="en"class="refentry"title="ansible-modules"lang="en"><aid="id458930"></a><divclass="titlepage"></div><divclass="refnamediv"><h2>Name</h2><p>ansible-playbook — format and function of an ansible playbook file</p></div><divclass="refsect1"title="DESCRIPTION"><aid="_description"></a><h2>DESCRIPTION</h2><p>Ansible ships with <spanclass="emphasis"><em>ansible-playbook</em></span>, a tool for running playbooks.
<htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"/><title>ansible-modules</title><linkrel="stylesheet"href="./docbook-xsl.css"type="text/css"/><metaname="generator"content="DocBook XSL Stylesheets V1.75.2"/></head><body><divxml:lang="en"class="refentry"title="ansible-modules"lang="en"><aid="id303952"></a><divclass="titlepage"></div><divclass="refnamediv"><h2>Name</h2><p>ansible-playbook — format and function of an ansible playbook file</p></div><divclass="refsect1"title="DESCRIPTION"><aid="_description"></a><h2>DESCRIPTION</h2><p>Ansible ships with <spanclass="emphasis"><em>ansible-playbook</em></span>, a tool for running playbooks.
Playbooks can represent frequent tasks, desired system configurations,
or deployment processes.</p></div><divclass="refsect1"title="FORMAT"><aid="_format"></a><h2>FORMAT</h2><p>Playbooks are written in YAML.</p></div><divclass="refsect1"title="EXAMPLE"><aid="_example"></a><h2>EXAMPLE</h2><p>See:</p><divclass="itemizedlist"><ulclass="itemizedlist"type="disc"><liclass="listitem">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"/><title>ansible</title><linkrel="stylesheet"type="text/css"href="./docbook-xsl.css"/><metaname="generator"content="DocBook XSL Stylesheets V1.76.1"/></head><body><divxml:lang="en"class="refentry"title="ansible"lang="en"><aid="id355813"></a><divclass="titlepage"></div><divclass="refnamediv"><h2>Name</h2><p>ansible — run a command somewhere else</p></div><divclass="refsynopsisdiv"title="Synopsis"><aid="_synopsis"></a><h2>Synopsis</h2><p>ansible <host-pattern> [-f forks] [-m module_name] [-a args]</p></div><divclass="refsect1"title="DESCRIPTION"><aid="_description"></a><h2>DESCRIPTION</h2><p><spanclass="strong"><strong>Ansible</strong></span> is an extra-simple tool/framework/API for doing 'remote things' over
<htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"/><title>ansible</title><linkrel="stylesheet"href="./docbook-xsl.css"type="text/css"/><metaname="generator"content="DocBook XSL Stylesheets V1.75.2"/></head><body><divxml:lang="en"class="refentry"title="ansible"lang="en"><aid="id547970"></a><divclass="titlepage"></div><divclass="refnamediv"><h2>Name</h2><p>ansible — run a command somewhere else</p></div><divclass="refsynopsisdiv"title="Synopsis"><aid="_synopsis"></a><h2>Synopsis</h2><p>ansible <host-pattern> [-f forks] [-m module_name] [-a args]</p></div><divclass="refsect1"title="DESCRIPTION"><aid="_description"></a><h2>DESCRIPTION</h2><p><spanclass="strong"><strong>Ansible</strong></span> is an extra-simple tool/framework/API for doing 'remote things' over
<p>The given shell command will be executed on all selected nodes.</p>
<p>This module does not support change hooks and returns the return code from the program as well as timing information about how long the command was running for.</p>
</div>
<divclass="section"id="copy">
<h2>copy<aclass="headerlink"href="#copy"title="Permalink to this headline">¶</a></h2>
<p>The copy module moves a file on the local box to remote locations.</p>
<p><em>src</em>:</p>
<p>Local path to a file to copy to the remote server. This can be an absolute or relative path.</p>
<p><em>dest</em>:</p>
<p>Remote absolute path where the file should end up.</p>
<p>This module also returns md5sum information about the resultant file.</p>
</div>
<divclass="section"id="facter">
<h2>facter<aclass="headerlink"href="#facter"title="Permalink to this headline">¶</a></h2>
<p>Runs the discovery program ‘facter’ on the remote system, returning
JSON data that can be useful for inventory purposes.</p>
<p>Requires that ‘facter’ and ‘ruby-json’ be installed on the remote end.</p>
<p>This module is informative only - it takes no parameters & does not support change hooks,
nor does it make any changes on the system. Playbooks do not actually use
this module, they use the ‘setup’ module behind the scenes.</p>
</div>
<divclass="section"id="git">
<h2>git<aclass="headerlink"href="#git"title="Permalink to this headline">¶</a></h2>
<p>Deploys software (or files) from git checkouts.</p>
<p><em>repo</em>:</p>
<p>git or http protocol address of the repo to checkout</p>
<p><em>dest</em>:</p>
<p>where to check it out, an absolute directory path</p>
<p><em>version</em>:</p>
<p>what version to check out – either the git SHA, the literal string ‘HEAD’, or a tag name</p>
</div>
<divclass="section"id="ohai">
<h2>ohai<aclass="headerlink"href="#ohai"title="Permalink to this headline">¶</a></h2>
<p>Similar to the facter module, this returns JSON inventory data. Ohai
data is a bit more verbose and nested than facter.</p>
<p>Requires that ‘ohai’ be installed on the remote end.</p>
<p>This module is information only - it takes no parameters & does not
support change hooks, nor does it make any changes on the system.</p>
<p>Playbooks should not call the ohai module, playbooks call the ‘setup’
module behind the scenes instead.</p>
</div>
<divclass="section"id="ping">
<h2>ping<aclass="headerlink"href="#ping"title="Permalink to this headline">¶</a></h2>
<p>A trivial test module, this module always returns the integer ‘1’ on
successful contact.</p>
<p>This module does not support change hooks and is informative only - it takes no parameters & does not
support change hooks, nor does it make any changes on the system.</p>
</div>
<divclass="section"id="service">
<h2>service<aclass="headerlink"href="#service"title="Permalink to this headline">¶</a></h2>
<p>Controls services on remote machines.</p>
<p><em>state</em></p>
<p>Values are ‘started’, ‘stopped’, or ‘restarted’. Started/stopped
are idempotent actions that will not run commands unless neccessary.
‘restarted’ will always bounce the service</p>
<p><em>name</em></p>
<p>The name of the service</p>
</div>
<divclass="section"id="setup">
<h2>setup<aclass="headerlink"href="#setup"title="Permalink to this headline">¶</a></h2>
<p>Writes a JSON file containing key/value data, for use in templating.
Call this once before using the template modules. Playbooks will
execute this module automatically as the first step in each play using
the variables section, so it is unneccessary to make explicit calls to
setup within a playbook.</p>
<p>If facter or ohai are installed, variables from these programs will also
be snapshotted into the JSON file for usage in templating. These variables
are prefixed with ‘<aclass="reference internal"href="#facter">facter</a>‘ and ‘<aclass="reference internal"href="#ohai">ohai</a>” so it’s easy to tell their source.
All variables are then bubbled up to the caller.</p>
<p><em>anything</em></p>
<p>any other parameters can be named basically anything, and set a key=value
pair in the JSON file for use in templating.</p>
</div>
<divclass="section"id="template">
<h2>template<aclass="headerlink"href="#template"title="Permalink to this headline">¶</a></h2>
<p>Templates a file out to a remote server. Call the setup module prior to usage.</p>
<p><em>src</em></p>
<p>path of a Jinja2 formatted template on the local server. This can be a relative
or absolute path.</p>
<p><em>dest</em></p>
<p>location to render the template on the remote server</p>
<p>This module also returns md5sum information about the resultant file.</p>
</div>
<divclass="section"id="writing-your-own-modules">
<h2>Writing your own modules<aclass="headerlink"href="#writing-your-own-modules"title="Permalink to this headline">¶</a></h2>
<p>To write your own modules, simply follow the convention of those already available in
/usr/share/ansible. Modules must return JSON but can be written in any language.
Modules should return hashes, but hashes can be nested.</p>
<p>To support change hooks, modules should return hashes with a changed: True/False
<h1>The Inventory File, Patterns, and Groups<aclass="headerlink"href="#the-inventory-file-patterns-and-groups"title="Permalink to this headline">¶</a></h1>
<h1>Playbooks: Ansible for Deployment, Configuration Management, and Orchestration<aclass="headerlink"href="#playbooks-ansible-for-deployment-configuration-management-and-orchestration"title="Permalink to this headline">¶</a></h1>
<dd>Learn about available modules and writing your own</dd>
<dt><aclass="reference internal"href="patterns.html"><em>The Inventory File, Patterns, and Groups</em></a></dt>
<dd>Learn about how to select hosts</dd>
</dl>
</div>
<p>Playbooks are a completely different way to use ansible and are particularly awesome.</p>
<p>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.</p>
<p>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.</p>
<divclass="section"id="playbook-example">
<h2>Playbook Example<aclass="headerlink"href="#playbook-example"title="Permalink to this headline">¶</a></h2>
<p>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
<h2>Hosts line<aclass="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, asdescribed in the ‘patterns’ documentation. This is just like the first parameter to /usr/bin/ansible.</p>
</div>
<divclass="section"id="vars-section">
<h2>Vars section<aclass="headerlink"href="#vars-section"title="Permalink to this headline">¶</a></h2>
<p>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 <ttclass="docutils literal"><spanclass="pre">`jinja2`</span></tt> syntax like this:</p>
<p>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 ‘<ahref="#id1"><spanclass="problematic"id="id2">facter_</span></a>‘
and Ohai variables are prefixed with ‘<ahref="#id3"><spanclass="problematic"id="id4">ohai_</span></a>‘. So for instance, if I wanted to write the
hostname into the /etc/motd file, I could say:</p>
<divclass="highlight-python"><pre>- name: write the motd
<h2>Using Includes To Assign Classes of Systems<aclass="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>
<divclass="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 ‘class definitions’ telling the systems what they
are supposed to do or be.</p>
<p>Using a common handlers file could allow one task in ‘webservers’ to define ‘restart apache’,
and it could be reused between multiple plays.</p>
<p>Variables like ‘database’ above can be used in templates referenced from the
configuration file to generate machine specific variables.</p>
Search.setIndex({objects:{},terms:{all:[0,1,2,3,4,5,6,7],concept:7,mcollect:1,prefix:[2,3,7],code:[1,2,7],follow:[5,6,2,3,7],scp:7,bubbl:[2,3],middl:3,elsewher:7,program:[1,2,3],selinux:3,blindingli:1,spec:3,sourc:[1,6,2,3,7],everi:[4,3],string:2,fals:[4,2],failur:[6,2],veri:[1,6,3],affect:3,level:[4,2,3],id_rsa:[0,7],list:[1,2,3,4,5,7,8],item:[4,6],form:[4,3],dotnet:4,saltstack:1,straight:7,alic:3,natur:2,seper:3,chef:1,second:[4,7],design:1,pass:[2,3],download:0,further:3,port:7,even:7,what:[0,2,3],favcolor:[3,7],section:[1,2,3],abbrevi:4,version:[2,7],varnam:3,ever:1,method:6,told:3,tar:0,hash:2,abov:3,conf:[3,7],eckersberg:4,gener:3,here:[2,3,7],let:[3,7],address:[5,2],path:2,sinc:7,valu:[4,2,3],box:[1,2],great:1,ahead:3,precursor:1,technolog:1,step:[2,3],prior:2,pick:[4,7],action:[1,2,3],extrem:0,implement:6,commonli:7,ourselv:3,employe:4,via:[0,1],regardless:[4,1,3],extra:3,modul:[0,1,2,3,6,7],releas:0,unix:3,"boolean":4,instal:[7,0,2,3,1],select:[1,2,3,5],httpd:[3,7],from:[0,1,2,3,4,7],describ:[2,3],would:[2,7],commun:1,visit:1,two:[4,0,5],noarch:0,live:0,handler:[1,3,7],call:2,usr:[6,2,3,7],msg:[6,2],suppos:3,checkout:2,tell:[2,3,7],more:[0,5,2,3,1],flat:3,desir:3,idempot:[2,3,7],comparison:1,unneccessari:2,sshd:1,agent:[0,7],particular:[1,3],easiest:1,must:[4,2,3],none:6,join:1,ibm:1,module_arg:6,dest:[2,3,7],setup:[1,2,7],work:[7,0,5,3,1],knows_oop:4,remain:1,minimum:3,can:[0,1,2,3,4,5,6,7],learn:[0,5,3,1],about:[4,0,2,3,1],purpos:2,root:[4,1,3],control:[1,2,3,7],want:[6,2,3,7],yamllint:4,process:[1,7],rpath:1,sudo:0,share:2,templat:[7,0,2,3,1],critic:1,liter:2,explor:0,occur:3,nearli:[2,3],alwai:2,multipl:[5,3,7],newlin:4,thoug:2,lame:4,capistrano:1,ping:[0,6,2,1],uptim:6,write:[4,1,2,3,7],how:[0,2,3,4,5,6,7],instead:2,simpl:[4,1,6,3,7],updat:7,map:3,financ:1,referenc:[5,3],clone:0,after:[3,7],usabl:[1,3],befor:[2,3],ohai_:3,mai:[4,0,6],end:[2,3],data:[4,6,2,7],parallel:[1,7],man:[1,8],github:[0,1],orchestr:[0,1,2,3,5,7],bootstrap:1,favorit:1,element:[4,2],issu:1,inform:[6,2,3],mango:4,combin:4,allow:3,order:3,talk:[0,3],oper:[1,7],help:1,over:[1,7],move:[2,3],orang:4,mission:1,elit:4,rpmbuild:0,comma:4,paramet:[2,3],facter_:3,jid:7,overlord:0,group:[1,6,3,5],cli:6,yaml:[4,1,3],pend:[3,7],rapidli:6,infrastructur:[0,5,3,1],mail:[1,5],job_statu:7,main:3,might:3,them:[2,3,7],"return":[1,6,2],thei:[6,2,3,7],food:4,contriv:3,scene:2,framework:[1,6],jinja2:[0,2,3,7],now:[0,2],nor:2,choic:1,multiprocess:0,name:[4,1,2,3,7],anyth:2,neccessari:[2,7],config:[1,3],drop:2,datastructur:6,separ:4,exampl:[0,1,2,3,4,5,6,7],each:[4,2,3,7],found:6,stock:2,mean:[2,3],harm:3,michael:1,individu:5,idea:1,realli:[4,2,3],backport:0,facter:[1,2,3,7],our:4,happen:[2,3],event:2,out:[1,2,3,4,6,7],variabl:[2,3,7],network:1,space:[1,2],reboot:7,content:[0,1],rel:2,internet:1,print:6,correct:[4,1,3],red:[1,7],painless:1,insid:3,advanc:6,ntp:7,given:[2,7],pub:7,base:[1,3],lab:1,dictionari:4,put:[0,7],org:0,bash:[0,7],basi:3,pyyaml:0,could:[6,3],fqdn:7,thing:[1,3],place:1,isn:1,assign:[1,3],first:[7,0,2,3,1],origin:1,softwar:[1,2,7],rang:1,notifi:[1,3,7],directli:[2,3,7],onc:[2,3],number:2,yourself:0,hook:2,instruct:0,alreadi:[0,2,3],puppet:1,construct:6,extend:1,massiv:1,differ:[7,0,3,1],convent:2,script:[1,6,7],associ:4,top:[2,3],mkdir:3,system:[0,1,2,3,5,7],messag:6,inventori:[1,2,3,5],too:1,statement:[1,3],john:4,"final":4,iptabl:3,shell:[1,2,7],option:[4,6,3,8,7],tool:[1,6,2,7],copi:[1,2,7],specifi:[4,2,7],retyp:0,sha:2,"short":1,kept:3,than:[0,2,3,7],silli:3,target:[1,5],remot:[0,2,3,7],structur:4,banana:4,project:[0,7,1],reus:3,architect:1,were:3,tion:4,uses_cv:4,pre:0,sai:3,runner:6,explicit:2,ani:[1,6,2,3,7],have:[0,3,1],need:[4,0,2,3,7],seek:2,paramiko:0,imagin:3,engin:7,built:0,note:[5,2,3,7],also:[0,1,2,3,4,5,6,7],client:1,build:[0,6],indic:2,datacent:3,divers:1,begin:4,unless:2,distribut:[0,1],deploy:[0,1,2,3,5,7],track:7,discov:3,most:[4,2],plai:[2,3],regular:3,deploi:[1,2,3,7],pair:2,why:1,don:2,doc:1,later:7,cover:7,doe:[1,2,5],likes_emac:4,snapshot:2,wildcard:5,databas:3,awesom:[1,3],show:[3,7],verbos:2,syntax:[4,3],bring:3,raleigh:1,particularli:3,playbook:[0,1,2,3,4,5,6,7],hack:1,radic:1,trivial:[1,2],rotat:3,involv:1,absolut:2,onli:[0,2,3,7],explicitli:3,locat:2,just:[7,0,2,3,1],pretti:6,configur:[0,1,2,3,4,5,7],apach:[3,7],behind:2,should:[4,2],somevar:3,freenod:1,local:2,yml:3,long_running_oper:7,contribut:1,get:[4,0,3,7,1],express:[4,1,6,3],stop:[2,3],repo:[2,7],next:3,obviou:1,ssh:[0,7],requir:[0,2,1],uvh:0,bar:5,provid:4,stuff:7,common:3,contain:[2,3],through:[0,2,1],where:[1,2,3],view:[1,8],set:[0,2,3],see:[0,1,2,3,4,5,7],result:[6,2],fail:[6,3],charact:4,ntp_server:7,best:3,planet:1,statu:7,manpag:[0,8],pattern:[1,6,3,5],someth:[1,2,7],discoveri:2,restart:[2,3,7],state:[2,3,7],won:7,between:[4,3],"import":6,irc:1,altern:7,kei:[4,0,2,3],style:2,extens:1,job:[4,7],entir:3,aserv:0,webapp:7,asdescrib:3,timmi:3,addit:[4,1,3],delimit:2,goal:1,against:[1,3,5],etc:[7,0,5,3,1],instanc:3,logic:3,mani:[3,7],com:[0,6,3,5],assur:3,simpli:[2,3],author:1,overview:4,header:5,written:[1,2,3,7],colon:3,shutdown:2,linux:[1,3],poll:[1,3,7],rpm:[0,1],three:5,multiplay:1,compos:3,been:1,json:[1,6,2],much:[1,2],basic:[4,0,5,2,1],quickli:[4,1],indenta:4,fire:1,rubi:[4,2,7],argument:2,func:1,atlanta:[3,7],those:[4,2],emploi:4,authorized_kei:0,multi:[1,3],look:[5,3,7],replac:3,hoc:[1,3,7],servic:[1,2,3,7],md5sum:2,defin:3,"while":3,facter_hostnam:3,cobbler:1,dehaan:1,motd:[3,7],max_client:3,stdout:6,non:1,itself:6,myapp:7,module_nam:6,sever:4,http_port:3,develop:[4,0,1],welcom:1,minim:0,make:[0,2,3,7],ohai:[1,2,3,7],same:[4,5,7],member:4,python:[0,1,2,4,6,7],complex:[1,3],success:2,document:[0,6,3,7],ansibl:[0,1,2,3,4,5,6,7,8],complet:3,http:2,hostnam:[6,3],again:3,nest:2,permit:4,effect:3,fruit:4,user:3,php:7,distutil:[0,1],typic:7,squar:4,task:[1,3,7],off:1,scenario:2,mention:3,setenforc:3,well:[0,2,3],hypothet:3,contact:[0,6,2],command:[0,1,2,3,5,6,7,8],thi:[0,1,2,3,4,5,7],choos:2,programm:6,dereferenc:3,usual:3,protocol:2,execut:[1,6,2,3],less:[0,1],excel:1,kill:7,skill:4,simultan:7,languag:[4,0,5,2,1],web:[6,7],versu:1,easi:[1,2],mix:5,trigger:2,except:3,littl:1,add:[0,7],els:1,unlik:3,hat:1,match:3,take:2,bin:[0,6,2,3,7],applic:[6,3],which:[4,0,5,3,1],format:[1,2,3,4,5,7],read:[4,0,6],fast:1,dark:6,game:1,know:[4,2,3],background:[1,7],world:0,bit:2,password:0,daemon:1,motorola:1,like:[4,5,2,3,7],specif:[5,6,3,7],signal:3,integ:2,noth:3,edit:0,api:[1,6,2],either:2,lose:7,popular:1,output:3,manag:[0,1,2,3,4,5,7],webserv:[5,3,7],some:[0,2],back:3,dead:1,server:[1,2,3,7],tmp:[3,7],render:2,assum:3,avoid:[0,2],though:1,definit:3,per:6,tracker:1,exit:6,foo:[5,7],complic:1,refer:7,machin:[0,2,3,7],core:1,run:[0,6,2,3,7],power:[1,6],usag:[2,7],devop:1,web2:6,host:[0,1,2,3,5,6,7],web1:6,repositori:0,"super":1,simpler:7,src:[2,3,7],sbin:[2,3,7],actual:2,othervar:3,surround:4,page:[4,0,8,1],srv:[3,7],done:3,industri:1,own:[1,2,3],real:0,bounc:2,within:2,tag:[0,2],automat:2,upgrad:7,down:6,ensur:[3,7],chang:[2,3,7],perl:7,bserver:0,your:[0,1,2,3,4,5,7],git:[0,2,7,1],type:6,fabric:1,wai:[4,0,3,7],transfer:[1,7],support:[2,7],question:1,"long":[1,2,7],happi:1,avail:[0,2,3,6,7,8],start:[0,1,2,3,4,7],appl:4,wordpress:3,includ:[1,3],lot:[1,3,7],suit:3,"var":[1,3],fork:6,head:[2,7],simplejson:0,lint:4,yeah:3,taken:3,line:[0,1,2,3,4,5,6,7,8],"true":[4,2,3],congratul:0,info:3,strawberri:4,made:[2,7],possibl:[5,3,7],whether:6,wish:[4,0,6,5],caller:2,until:0,asynchron:[1,3],record:4,limit:[1,7],rerun:3,otherwis:2,similar:2,chip:1,curv:1,featur:3,tasti:4,creat:1,certain:3,doesn:1,repres:4,exist:[1,3],file:[0,1,2,3,4,5,7],bob:3,ship:2,check:[2,7],bracket:[4,5],echo:0,denot:5,googl:1,dbserver:[5,3],when:[2,3,7],detail:[1,6],"default":[1,5],other:[7,0,2,3,1],futur:0,test:[0,2],you:[0,1,2,3,4,5,7],node:[0,2,7,1],sequenc:1,"class":[1,3],asciidoc:0,push:3,log:3,deferenc:3,"60k":1,sphinx:0,directori:[2,3],portion:5,emerg:1,potenti:3,time:[0,1,2,3,5,7],far:1,hello:0},objtypes:{},titles:["Getting Started","Ansible","Ansible Modules","Playbooks: Ansible for Deployment, Configuration Management, and Orchestration","YAML Format","The Inventory File, Patterns, and Groups","Using the Python API","Command Line Examples","Man Pages"],objnames:{},filenames:["gettingstarted","index","modules","playbooks","YAMLScripts","patterns","api","examples","man"]})
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In dignissim
placerat nibh, non feugiat risus varius vitae. Donec eu libero
lectus. Ut non orci felis, eget mattis mauris. Etiam ut tellus in
magna porta venenatis. Quisque scelerisque, sem non ultrices bibendum,
dolor diam rutrum lectus, sed luctus neque neque vitae eros. Vivamus
mattis, ipsum ut bibendum gravida, lectus arcu venenatis elit, vitae
luctus diam leo sit amet ligula. Nunc egestas justo in nulla sagittis
ut suscipit sapien gravida. Morbi id dui nibh. Nullam diam massa,
rhoncus a dignissim non, adipiscing vel arcu. Quisque ultricies
tincidunt purus ut sodales. Quisque scelerisque dapibus purus quis
egestas. Maecenas sagittis porttitor adipiscing. Duis eu magna
sem. Donec arcu felis, faucibus et malesuada non, blandit vitae
metus. Fusce nec sapien dolor.
Examples 2
``````````
Aenean ac fermentum nisl. Integer leo sem, rutrum nec dictum at,
pretium quis sapien. Duis felis metus, sodales sit amet gravida in,
pretium ut arcu. Nulla ligula quam, aliquam sit amet sollicitudin
eget, molestie tincidunt ipsum. Nulla leo nunc, mattis sed auctor at,
suscipit ut metus. Suspendisse hendrerit, justo sagittis malesuada
molestie, nisi nunc placerat libero, vel vulputate elit tellus et
augue. Phasellus tempor lectus ac nisi aliquam faucibus. Donec feugiat
egestas nibh id mattis. In hac habitasse platea dictumst. Ut accumsan
lorem eget leo dictum viverra.
Examples 3
``````````
Quisque egestas lorem sit amet felis tincidunt adipiscing. Aenean
ornare fermentum accumsan. Aenean eu mauris arcu, id pulvinar
quam. Suspendisse nec massa vel augue laoreet ultricies in convallis
dolor. Mauris sodales porta enim, non ultricies dolor luctus
in. Phasellus eu tortor lectus, vel porttitor nulla. Mauris vulputate,
erat id scelerisque lobortis, nibh ipsum tristique elit, ac viverra
arcu sem a ante. Praesent nec metus vestibulum augue eleifend
suscipit. In feugiat, sem nec dignissim consequat, velit tortor
scelerisque metus, sit amet mollis nisl sem eu nibh. Quisque in nibh
turpis. Proin ac nisi ligula, a pretium augue.
Examples 3
``````````
In nibh eros, laoreet id interdum vel, sodales sed tortor. Sed
ullamcorper, sem vel mattis consectetur, nibh turpis molestie nisl,
eget lobortis mi magna sed metus. Cras justo est, tempus quis
adipiscing ut, hendrerit convallis sem. Mauris ullamcorper, sapien et
luctus iaculis, urna elit egestas ipsum, et tristique enim risus vitae
nunc. Vivamus aliquet lorem eu urna pulvinar hendrerit malesuada nunc
sollicitudin. Cras in mi rhoncus quam egestas dignissim vel sit amet
lacus. Maecenas interdum viverra laoreet. Quisque elementum
sollicitudin ullamcorper.
Examples 4
``````````
Pellentesque mauris sem, malesuada at lobortis in, porta eget
urna. Duis aliquet quam eget risus elementum quis auctor ligula
gravida. Phasellus et ullamcorper libero. Nam elementum ultricies
tellus, in sagittis magna aliquet quis. Ut sit amet tellus id erat
tristique lobortis. Suspendisse est enim, tristique eu convallis id,
rutrum nec lacus. Fusce iaculis diam non felis rutrum lobortis. Proin
hendrerit mi tincidunt dui fermentum placerat.
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::
:doc:`modules`
A list of available modules
:doc:`playbooks`
Alternative ways to use ansible
Parallelism and Shell Commands
``````````````````````````````
Let's use ansible's command line tool to reboot all web servers in Atlanta, 10 at a time::
ssh-agent bash
ssh-add ~/.ssh/id_rsa.pub
ansible atlanta -a "/sbin/reboot" -f 10
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'.
File Transfer & Templating
``````````````````````````
Ansible can SCP lots of files to multiple machines in parallel, and optionally use them as template sources.
To just transfer a file directly to many different servers::
ansible atlanta copy -a "/etc/hosts /tmp/hosts"
To use templating, first run the setup module to put the template variables you would like to use on the remote host. Then use the template module to write the files using the templates. Templates are written in Jinja2 format. Playbooks (covered elsewhere in the documentation) will run the setup module for you, making this even simpler.::
ansible webservers -m setup -a "favcolor=red ntp_server=192.168.1.1"
ansible webservers -m template -a "src=/srv/motd.j2 dest=/etc/motd"
ansible webservers -m template -a "src=/srv/ntp.j2 dest=/etc/ntp.conf"
Need something like the fqdn in a template? If facter or ohai are installed, data from these projects will also be made available to the template engine, using 'facter' and 'ohai' prefixes for each.
Deploying From Source Control
`````````````````````````````
Deploy your webapp straight from git::
ansible webservers -m git -a "repo=git://foo dest=/srv/myapp version=HEAD"
Since ansible modules can notify change handlers (see 'Playbooks') it is possible to tell ansible to run specific tasks when the code is updated, such as deploying Perl/Python/PHP/Ruby directly from git and then restarting apache.
Managing Services
`````````````````
Ensure a service is started on all webservers::
ansible webservers -m service name=httpd state=started
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.
Ansible is a extra-simple tool/API for doing 'parallel remote things'
over SSH -- whether executing commands, running "modules", or
executing larger 'playbooks' that can serve as a configuration
management or deployment system.
While `Func installation <http://fedorahosted.org/func>`_ which I
co-wrote, aspired to avoid using SSH and have it's own daemon
infrastructure, Ansible aspires to be quite different and more
minimal, but still able to grow more modularly over time. This is
based on talking to a lot of users of various tools and wishing to
eliminate problems with connectivity and long running daemons, or not
picking tool `X` because they preferred to code in `Y`. Further,
playbooks take things a whole step further, building the config and
deployment system I always wanted to build.
Why use Ansible versus something else? (Fabric, Capistrano,
mCollective, Func, SaltStack, etc?) It will have far less code, it
will be more correct, and it will be the easiest thing to hack on and
Ansible is a radically simple deployment, configuration, and command execution framework.
Other tools in this space have been too complicated for too long, require too much bootstrapping,
and have too much learning curve. Ansible is dead simple and painless to extend. For comparison, Puppet and Chef have about 60k lines of code. Ansible's core is a little over 1000 lines.
Ansible isn't just for configuration -- it's also great for Ad-Hoc tasks,
quickly firing off commands against nodes. Where Ansible excels though, is expressing complex multi-node deployment processes, executing complex sequences of commands on different hosts through "playbooks".
Extending ansible does not require programming in any particular language -- you can write modules
as scripts or programs that return simple JSON. It's also trivially easy to just execute
useful shell commands.
Why use Ansible versus something else? (Puppet, Chef, Fabric, Capistrano,
mCollective, Func, SaltStack, etc?) Ansible will have far less code, it
will be (by extension) more correct, and it will be the easiest thing to hack on and
use you'll ever see -- regardless of your favorite language of choice.
Want to only code plugins in bash or clojure? Ansible doesn't care.
The docs will fit on one page and the source will be blindingly
obvious.
Systems management doesn't have to be complicated. Ansible's docs will remain
short & simple, and the source will be blindingly obvious.
Design Principles
`````````````````
Design Goals
````````````
* Dead simple setup
* Super fast & parallel by default
* No server or client daemons; use existing SSHd
* No server or client daemons; use existing SSHd out of the box
* No additional software required on client boxes
* Modules can be written in ANY language
* Awesome API for creating very powerful distributed scripts
* Be usable as non-root
* Be very usable as non-root
* Create the easiest config management system to use, ever.
Communicate and Get Involved
````````````````````````````
Requirements
````````````
Requirements are extremely minimal.
If you are running python 2.6 on the **overlord** machine, you will
need:
* ``paramiko``
* ``PyYAML``
* ``python-jinja2`` (for playbooks)
* ``Asciidoc`` (for building documentation)
If you are running less than Python 2.6, you will also need:
* The Python 2.4 or 2.5 backport of the ``multiprocessing`` module
- `Installation and Testing Instructions <http://code.google.com/p/python-multiprocessing/wiki/Install>`_
* ``simplejson``
On the managed nodes, to use templating, you will need:
* ``python-jinja2`` (you can install this with ansible)
Getting Ansible
```````````````
Tagged releases are available as tar.gz files from the Ansible github
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In dignissim
placerat nibh, non feugiat risus varius vitae. Donec eu libero
lectus. Ut non orci felis, eget mattis mauris. Etiam ut tellus in
magna porta venenatis. Quisque scelerisque, sem non ultrices bibendum,
dolor diam rutrum lectus, sed luctus neque neque vitae eros. Vivamus
mattis, ipsum ut bibendum gravida, lectus arcu venenatis elit, vitae
luctus diam leo sit amet ligula. Nunc egestas justo in nulla sagittis
ut suscipit sapien gravida. Morbi id dui nibh. Nullam diam massa,
rhoncus a dignissim non, adipiscing vel arcu. Quisque ultricies
tincidunt purus ut sodales. Quisque scelerisque dapibus purus quis
egestas. Maecenas sagittis porttitor adipiscing. Duis eu magna
sem. Donec arcu felis, faucibus et malesuada non, blandit vitae
metus. Fusce nec sapien dolor.
Aenean ac fermentum nisl. Integer leo sem, rutrum nec dictum at,
pretium quis sapien. Duis felis metus, sodales sit amet gravida in,
pretium ut arcu. Nulla ligula quam, aliquam sit amet sollicitudin
eget, molestie tincidunt ipsum. Nulla leo nunc, mattis sed auctor at,
suscipit ut metus. Suspendisse hendrerit, justo sagittis malesuada
molestie, nisi nunc placerat libero, vel vulputate elit tellus et
augue. Phasellus tempor lectus ac nisi aliquam faucibus. Donec feugiat
egestas nibh id mattis. In hac habitasse platea dictumst. Ut accumsan
lorem eget leo dictum viverra.
Quisque egestas lorem sit amet felis tincidunt adipiscing. Aenean
ornare fermentum accumsan. Aenean eu mauris arcu, id pulvinar
quam. Suspendisse nec massa vel augue laoreet ultricies in convallis
dolor. Mauris sodales porta enim, non ultricies dolor luctus
in. Phasellus eu tortor lectus, vel porttitor nulla. Mauris vulputate,
erat id scelerisque lobortis, nibh ipsum tristique elit, ac viverra
arcu sem a ante. Praesent nec metus vestibulum augue eleifend
suscipit. In feugiat, sem nec dignissim consequat, velit tortor
scelerisque metus, sit amet mollis nisl sem eu nibh. Quisque in nibh
turpis. Proin ac nisi ligula, a pretium augue.
In nibh eros, laoreet id interdum vel, sodales sed tortor. Sed
ullamcorper, sem vel mattis consectetur, nibh turpis molestie nisl,
eget lobortis mi magna sed metus. Cras justo est, tempus quis
adipiscing ut, hendrerit convallis sem. Mauris ullamcorper, sapien et
luctus iaculis, urna elit egestas ipsum, et tristique enim risus vitae
nunc. Vivamus aliquet lorem eu urna pulvinar hendrerit malesuada nunc
sollicitudin. Cras in mi rhoncus quam egestas dignissim vel sit amet
lacus. Maecenas interdum viverra laoreet. Quisque elementum
sollicitudin ullamcorper.
Pellentesque mauris sem, malesuada at lobortis in, porta eget
urna. Duis aliquet quam eget risus elementum quis auctor ligula
gravida. Phasellus et ullamcorper libero. Nam elementum ultricies
tellus, in sagittis magna aliquet quis. Ut sit amet tellus id erat
tristique lobortis. Suspendisse est enim, tristique eu convallis id,
rutrum nec lacus. Fusce iaculis diam non felis rutrum lobortis. Proin
hendrerit mi tincidunt dui fermentum placerat.
Ansible Modules
===============
Ansible ships with a number of modules that can be executed directly on remote hosts or through
ansible playbooks.
.. seealso::
:doc:`examples`
Examples of using modules in /usr/bin/ansible
:doc:`playbooks`
Examples of using modules with /usr/bin/ansible-playbook
:doc:`api`
Examples of using modules with the Python API
Nearly all modules take key=value parameters. Some modules take no parameters, and the command
module just takes arguments for the command you want to run.
All modules return JSON format data, thoug if you are using the command line or playbooks, you
don't really need to know much about that.
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. Unless otherwise noted, all modules support change hooks.
Stock modules:
command
```````
The command module takes the command name followed by a list of arguments, space delimited.
This is the only module that does not use key=value style parameters.
Example usage::
/sbin/shutdown -t now
The given shell command will be executed on all selected nodes.
This module does not support change hooks and returns the return code from the program as well as timing information about how long the command was running for.
copy
````
The copy module moves a file on the local box to remote locations.
*src*::
Local path to a file to copy to the remote server. This can be an absolute or relative path.
*dest*::
Remote absolute path where the file should end up.
This module also returns md5sum information about the resultant file.
facter
``````
Runs the discovery program 'facter' on the remote system, returning
JSON data that can be useful for inventory purposes.
Requires that 'facter' and 'ruby-json' be installed on the remote end.
This module is informative only - it takes no parameters & does not support change hooks,
nor does it make any changes on the system. Playbooks do not actually use
this module, they use the 'setup' module behind the scenes.
git
```
Deploys software (or files) from git checkouts.
*repo*::
git or http protocol address of the repo to checkout
*dest*::
where to check it out, an absolute directory path
*version*::
what version to check out -- either the git SHA, the literal string 'HEAD', or a tag name
ohai
````
Similar to the facter module, this returns JSON inventory data. Ohai
data is a bit more verbose and nested than facter.
Requires that 'ohai' be installed on the remote end.
This module is information only - it takes no parameters & does not
support change hooks, nor does it make any changes on the system.
Playbooks should not call the ohai module, playbooks call the 'setup'
module behind the scenes instead.
ping
````
A trivial test module, this module always returns the integer '1' on
successful contact.
This module does not support change hooks and is informative only - it takes no parameters & does not
support change hooks, nor does it make any changes on the system.
service
```````
Controls services on remote machines.
*state*
Values are 'started', 'stopped', or 'restarted'. Started/stopped
are idempotent actions that will not run commands unless neccessary.
'restarted' will always bounce the service
*name*
The name of the service
setup
`````
Writes a JSON file containing key/value data, for use in templating.
Call this once before using the template modules. Playbooks will
execute this module automatically as the first step in each play using
the variables section, so it is unneccessary to make explicit calls to
setup within a playbook.
If facter or ohai are installed, variables from these programs will also
be snapshotted into the JSON file for usage in templating. These variables
are prefixed with 'facter_' and 'ohai_" so it's easy to tell their source.
All variables are then bubbled up to the caller.
*anything*
any other parameters can be named basically anything, and set a key=value
pair in the JSON file for use in templating.
template
````````
Templates a file out to a remote server. Call the setup module prior to usage.
*src*
path of a Jinja2 formatted template on the local server. This can be a relative
or absolute path.
*dest*
location to render the template on the remote server
This module also returns md5sum information about the resultant file.
Writing your own modules
````````````````````````
To write your own modules, simply follow the convention of those already available in
/usr/share/ansible. Modules must return JSON but can be written in any language.
Modules should return hashes, but hashes can be nested.
To support change hooks, modules should return hashes with a changed: True/False
element at the top level::
{
'changed' : True,
'something' : 42
}
Modules can also choose to indicate a failure scenario by returning a top level 'failure'
element with a True value, and a 'msg' element describing the nature of the failure.
Other return values are up to the module.
{
'failure' : True,
'msg' : "here is what happened..."
}
When shipping modules, drop them in /usr/share/ansible, or specify the module path to the
command line tool or API. It is easy to test modules by running them directly on
the command line, passing them arguments just like they would be passed with ansible.
Learn about available modules and writing your own
:doc:`patterns`
Learn about how to select hosts
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.
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
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
````````````
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