mirror of https://github.com/ansible/ansible.git
Merge branch 'master' of https://github.com/ansible/ansible.github.com
commit
26800d5db8
@ -1,55 +1,73 @@
|
||||
API
|
||||
===
|
||||
|
||||
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.
|
||||
Using the Python API
|
||||
====================
|
||||
|
||||
The Python API is very powerful, and is how the ansible CLI and ansible-playbook
|
||||
are implemented.
|
||||
|
||||
It's pretty simple::
|
||||
|
||||
import ansible.runner
|
||||
|
||||
runner = ansible.runner.Runner(
|
||||
module_name='ping',
|
||||
module_args='',
|
||||
pattern='web*',
|
||||
forks=10
|
||||
)
|
||||
datastructure = runner.run()
|
||||
|
||||
The run method returns results per host, grouped by whether they
|
||||
could be contacted or not. Return types are module specific, as
|
||||
expressed in the 'ansible-modules' documentation.::
|
||||
|
||||
{
|
||||
"dark" : {
|
||||
"web1.example.com" : "failure message"
|
||||
}
|
||||
"contacted" : {
|
||||
"web2.example.com" : 1
|
||||
}
|
||||
}
|
||||
|
||||
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``.
|
||||
|
||||
|
||||
|
@ -1,71 +1,81 @@
|
||||
Examples
|
||||
========
|
||||
|
||||
Examples 1
|
||||
``````````
|
||||
|
||||
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.
|
||||
|
||||
|
||||
|
@ -1,67 +1,104 @@
|
||||
Getting Started
|
||||
===============
|
||||
|
||||
How to ansible
|
||||
|
||||
How to download ansible and get started using it
|
||||
|
||||
.. seealso::
|
||||
|
||||
:doc:`YAMLScripts`
|
||||
Complete documentation of the YAML syntax `ansible` understands.
|
||||
|
||||
|
||||
What you need
|
||||
-------------
|
||||
|
||||
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.
|
||||
:doc:`examples`
|
||||
Examples of basic commands
|
||||
:doc:`playbooks`
|
||||
Learning ansible's configuration management language
|
||||
|
||||
Requirements
|
||||
````````````
|
||||
|
||||
Requirements for Ansible are extremely minimal.
|
||||
|
||||
If you are running python 2.6 on the **overlord** machine (the machine that you'll be talking to the other machines from), you will need:
|
||||
|
||||
* ``paramiko``
|
||||
* ``PyYAML``
|
||||
* ``python-jinja2`` (for playbooks)
|
||||
|
||||
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)
|
||||
|
||||
Developer Requirements
|
||||
``````````````````````
|
||||
|
||||
For developers, you may wish to have:
|
||||
|
||||
* ``asciidoc`` (for building manpage documentation)
|
||||
* ``python-sphinx`` (for building content for the ansible.github.com project only)
|
||||
|
||||
|
||||
Getting Ansible
|
||||
```````````````
|
||||
|
||||
Tagged releases are available as tar.gz files from the Ansible github
|
||||
project page:
|
||||
|
||||
* `Ansible/downloads <https://github.com/ansible/ansible/downloads>`_
|
||||
|
||||
You can also clone the git repository yourself and install Ansible in
|
||||
one of two ways:
|
||||
|
||||
|
||||
Python Distutils
|
||||
++++++++++++++++
|
||||
|
||||
You can also install Ansible using Python Distutils::
|
||||
|
||||
$ git clone git://github.com/ansible/ansible.git
|
||||
$ cd ./ansible
|
||||
$ sudo make install
|
||||
|
||||
Via RPM
|
||||
+++++++
|
||||
|
||||
In the near future, pre-built RPMs will be available through your distribution. Until that time you
|
||||
can use the ``make rpm`` command::
|
||||
|
||||
$ git clone git://github.com/ansible/ansible.git
|
||||
$ cd ./ansible
|
||||
$ make rpm
|
||||
$ sudo rpm -Uvh ~/rpmbuild/RPMS/noarch/ansible-1.0-1.noarch.rpm
|
||||
|
||||
Your first commands
|
||||
```````````````````
|
||||
|
||||
Edit /etc/ansible/hosts and put one or more remote systems in it, for which you have your SSH
|
||||
key in ``authorized_keys``::
|
||||
|
||||
192.168.1.50
|
||||
aserver.example.org
|
||||
bserver.example.org
|
||||
|
||||
Set up SSH agent to avoid retyping passwords::
|
||||
|
||||
ssh-agent bash
|
||||
ssh-add ~/.ssh/id_rsa
|
||||
|
||||
Now ping all your nodes::
|
||||
|
||||
ansible all -m ping
|
||||
|
||||
Now run a live command on all of your nodes::
|
||||
|
||||
ansible all /bin/echo hello
|
||||
|
||||
Congratulations. You've just contacted your nodes with Ansible. It's now time to read some
|
||||
of the more real-world examples, and explore what you can do with different modules, as well
|
||||
as the Ansible playbooks language. Ansible is not just about running commands, but you already
|
||||
have a working infrastructure!
|
||||
|
||||
|
@ -1,55 +1,199 @@
|
||||
Modules
|
||||
=======
|
||||
|
||||
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.
|
||||
|
||||
|
||||
|
@ -1,55 +1,63 @@
|
||||
Patterns
|
||||
========
|
||||
|
||||
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.
|
||||
The Inventory File, Patterns, and Groups
|
||||
========================================
|
||||
|
||||
How to select hosts you wish to manage
|
||||
|
||||
.. seealso::
|
||||
|
||||
:doc:`examples`
|
||||
Examples of basic commands
|
||||
:doc:`playbooks`
|
||||
Learning ansible's configuration management language
|
||||
|
||||
Inventory File Format
|
||||
+++++++++++++++++++++
|
||||
|
||||
Ansible works against multiple systems in your infrastructure at the
|
||||
same time. It does this by selecting portions of systems listed in Ansible's inventory file,
|
||||
which defaults to /etc/ansible/hosts, and looks like this::
|
||||
|
||||
mail.example.com
|
||||
|
||||
[webservers]
|
||||
foo.example.com
|
||||
bar.example.com
|
||||
|
||||
[dbservers]
|
||||
one.example.com
|
||||
two.example.com
|
||||
three.example.com
|
||||
|
||||
|
||||
Selecting Targets
|
||||
+++++++++++++++++
|
||||
|
||||
These patterns target all hosts in the inventory file::
|
||||
|
||||
all
|
||||
*
|
||||
|
||||
It is also possible to address specific hosts::
|
||||
|
||||
one.example.com
|
||||
one.example.com:two.example.com
|
||||
|
||||
|
||||
The following patterns address one or more groups, which are denoted with the bracket
|
||||
headers in the inventory file::
|
||||
|
||||
webservers
|
||||
webservers:dbservers
|
||||
|
||||
Individual hosts, but not groups, can also be referenced using wildcards:
|
||||
|
||||
*.example.com
|
||||
*.com
|
||||
|
||||
It's also ok to mix wildcard patterns and groups at the same time::
|
||||
|
||||
one*.com:dbservers
|
||||
|
||||
NOTE: It is not possible to target a host not in the inventory file.
|
||||
|
||||
|
||||
|
@ -1,55 +1,205 @@
|
||||
Playbooks
|
||||
=========
|
||||
|
||||
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.
|
||||
Playbooks: Ansible for Deployment, Configuration Management, and Orchestration
|
||||
==============================================================================
|
||||
|
||||
.. seealso::
|
||||
|
||||
:doc:`YAMLScripts`
|
||||
Learn about YAML syntax
|
||||
:doc:`modules`
|
||||
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
|
||||
back on the webservers group, etc::
|
||||
|
||||
---
|
||||
- hosts: webservers
|
||||
vars:
|
||||
http_port: 80
|
||||
max_clients: 200
|
||||
user: root
|
||||
tasks:
|
||||
- include: base.yml somevar=3 othervar=4
|
||||
- name: write the apache config file
|
||||
action: template src=/srv/httpd.j2 dest=/etc/httpd.conf
|
||||
notify:
|
||||
- restart apache
|
||||
- name: ensure apache is running
|
||||
action: service name=httpd state=started
|
||||
handlers:
|
||||
- include: handlers.yml
|
||||
|
||||
Hosts line
|
||||
``````````
|
||||
|
||||
The hosts line is a list of one or more groups or host patterns, seperated by colons, asdescribed in the 'patterns' documentation. This is just like the first parameter to /usr/bin/ansible.
|
||||
|
||||
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
|
||||
hostname into the /etc/motd file, I could say::
|
||||
|
||||
- name: write the motd
|
||||
- action: template src=/srv/templates/motd.j2 dest=/etc/motd
|
||||
|
||||
And in /srv/templates/motd.j2::
|
||||
|
||||
You are logged into {{ facter_hostname }}
|
||||
|
||||
But we're getting ahead of ourselves. Let's talk about tasks.
|
||||
|
||||
Tasks list
|
||||
``````````
|
||||
|
||||
Each play contains a list of tasks. Tasks are executed in order, one at a time, against
|
||||
all machines matched by the play's host pattern, before moving on to the next task.
|
||||
|
||||
Hosts with failed tasks are taken out of the rotation for the entire playbook. If things fail,
|
||||
simply correct the playbook file and rerun.
|
||||
|
||||
Modules other than command are idempotent, meaning if you run them again, they will make the
|
||||
changes they are told to make to bring the system to the desired state.
|
||||
|
||||
Task name and action
|
||||
`````````````````````
|
||||
|
||||
Every task must have a name, which is included in the output from running the playbook.
|
||||
|
||||
The action line is the name of an ansible module followed by parameters. Usually these
|
||||
are expressed in key=value form, except for the command module, which looks just like a Linux/Unix
|
||||
command line. See the module documentation for more info.
|
||||
|
||||
Variables, as mentioned above, can be used in action lines. So if, hypothetically, you wanted
|
||||
to make a directory on each system named after the hostname ... yeah, that's I know silly ... you could
|
||||
do it like so::
|
||||
|
||||
- name: make a directory
|
||||
- action: mkdir /tmp/{{ facter_hostname }}
|
||||
|
||||
Notify statements
|
||||
`````````````````
|
||||
|
||||
Nearly all modules are written to be 'idempotent' and can signal when they have affected a change
|
||||
on the remote system. If a notify statement is used, the named handler will be run against
|
||||
each system where a change was effected, but NOT on systems where no change occurred. This happens
|
||||
after all of the tasks are run. For example, if notifying Apache and potentially replacing lots of
|
||||
configuration files, you could have Apache restart just once, at the end of a run. If you need
|
||||
Apache restarted in the middle of a run, you could just make a task for it, no harm done. Notifiers
|
||||
are optional.
|
||||
|
||||
Handlers
|
||||
````````
|
||||
|
||||
Handlers are lists of tasks, not really any different from regular tasks, that are referenced
|
||||
by name. Handlers are what notifiers notify. If nothing notifies a handler, it will not run.
|
||||
Regardless of how many things notify a handler, it will run only once, after all of the tasks
|
||||
complete in a particular play.
|
||||
|
||||
Includes
|
||||
````````
|
||||
|
||||
Not all tasks have to be listed directly in the main file. An include file can contain
|
||||
a list of tasks (in YAML) as well, optionally passing extra variables into the file.
|
||||
Variables passed in can be deferenced like this (assume a variable named 'user')::
|
||||
|
||||
{{ user }}
|
||||
|
||||
For instance, if deploying multiple wordpress instances, I could contain all of my tasks
|
||||
in a wordpress.yml file, and use it like so::
|
||||
|
||||
- tasks:
|
||||
- include: wordpress.yml user=timmy
|
||||
- include: wordpress.yml user=alice
|
||||
- include: wordpress.yml user=bob
|
||||
|
||||
In addition to the explicitly passed in parameters, all variables from the vars section
|
||||
are also available.
|
||||
|
||||
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
|
||||
````````````````````````````````
|
||||
|
||||
(Information on this feature is pending)
|
||||
|
||||
Executing A Playbook
|
||||
````````````````````
|
||||
|
||||
To run a playbook::
|
||||
|
||||
ansible-playbook playbook.yml
|
||||
|
||||
|
@ -1,158 +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 — 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> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body">
|
||||
|
||||
<div class="section" id="communicate">
|
||||
<h1>Communicate<a class="headerlink" href="#communicate" title="Permalink to this headline">¶</a></h1>
|
||||
<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>
|
||||
</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" size="18" />
|
||||
<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> »</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer">
|
||||
© Copyright 2012 Michael DeHaan.
|
||||
Last updated on Mar 07, 2012.
|
||||
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
File diff suppressed because one or more lines are too long
@ -1,55 +1,73 @@
|
||||
API
|
||||
===
|
||||
|
||||
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.
|
||||
Using the Python API
|
||||
====================
|
||||
|
||||
The Python API is very powerful, and is how the ansible CLI and ansible-playbook
|
||||
are implemented.
|
||||
|
||||
It's pretty simple::
|
||||
|
||||
import ansible.runner
|
||||
|
||||
runner = ansible.runner.Runner(
|
||||
module_name='ping',
|
||||
module_args='',
|
||||
pattern='web*',
|
||||
forks=10
|
||||
)
|
||||
datastructure = runner.run()
|
||||
|
||||
The run method returns results per host, grouped by whether they
|
||||
could be contacted or not. Return types are module specific, as
|
||||
expressed in the 'ansible-modules' documentation.::
|
||||
|
||||
{
|
||||
"dark" : {
|
||||
"web1.example.com" : "failure message"
|
||||
}
|
||||
"contacted" : {
|
||||
"web2.example.com" : 1
|
||||
}
|
||||
}
|
||||
|
||||
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``.
|
||||
|
||||
|
||||
|
@ -1,55 +0,0 @@
|
||||
Communicate
|
||||
===========
|
||||
|
||||
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.
|
@ -1,71 +1,81 @@
|
||||
Examples
|
||||
========
|
||||
|
||||
Examples 1
|
||||
``````````
|
||||
|
||||
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.
|
||||
|
||||
|
||||
|
@ -1,67 +1,104 @@
|
||||
Getting Started
|
||||
===============
|
||||
|
||||
How to ansible
|
||||
|
||||
How to download ansible and get started using it
|
||||
|
||||
.. seealso::
|
||||
|
||||
:doc:`YAMLScripts`
|
||||
Complete documentation of the YAML syntax `ansible` understands.
|
||||
|
||||
|
||||
What you need
|
||||
-------------
|
||||
|
||||
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.
|
||||
:doc:`examples`
|
||||
Examples of basic commands
|
||||
:doc:`playbooks`
|
||||
Learning ansible's configuration management language
|
||||
|
||||
Requirements
|
||||
````````````
|
||||
|
||||
Requirements for Ansible are extremely minimal.
|
||||
|
||||
If you are running python 2.6 on the **overlord** machine (the machine that you'll be talking to the other machines from), you will need:
|
||||
|
||||
* ``paramiko``
|
||||
* ``PyYAML``
|
||||
* ``python-jinja2`` (for playbooks)
|
||||
|
||||
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)
|
||||
|
||||
Developer Requirements
|
||||
``````````````````````
|
||||
|
||||
For developers, you may wish to have:
|
||||
|
||||
* ``asciidoc`` (for building manpage documentation)
|
||||
* ``python-sphinx`` (for building content for the ansible.github.com project only)
|
||||
|
||||
|
||||
Getting Ansible
|
||||
```````````````
|
||||
|
||||
Tagged releases are available as tar.gz files from the Ansible github
|
||||
project page:
|
||||
|
||||
* `Ansible/downloads <https://github.com/ansible/ansible/downloads>`_
|
||||
|
||||
You can also clone the git repository yourself and install Ansible in
|
||||
one of two ways:
|
||||
|
||||
|
||||
Python Distutils
|
||||
++++++++++++++++
|
||||
|
||||
You can also install Ansible using Python Distutils::
|
||||
|
||||
$ git clone git://github.com/ansible/ansible.git
|
||||
$ cd ./ansible
|
||||
$ sudo make install
|
||||
|
||||
Via RPM
|
||||
+++++++
|
||||
|
||||
In the near future, pre-built RPMs will be available through your distribution. Until that time you
|
||||
can use the ``make rpm`` command::
|
||||
|
||||
$ git clone git://github.com/ansible/ansible.git
|
||||
$ cd ./ansible
|
||||
$ make rpm
|
||||
$ sudo rpm -Uvh ~/rpmbuild/RPMS/noarch/ansible-1.0-1.noarch.rpm
|
||||
|
||||
Your first commands
|
||||
```````````````````
|
||||
|
||||
Edit /etc/ansible/hosts and put one or more remote systems in it, for which you have your SSH
|
||||
key in ``authorized_keys``::
|
||||
|
||||
192.168.1.50
|
||||
aserver.example.org
|
||||
bserver.example.org
|
||||
|
||||
Set up SSH agent to avoid retyping passwords::
|
||||
|
||||
ssh-agent bash
|
||||
ssh-add ~/.ssh/id_rsa
|
||||
|
||||
Now ping all your nodes::
|
||||
|
||||
ansible all -m ping
|
||||
|
||||
Now run a live command on all of your nodes::
|
||||
|
||||
ansible all /bin/echo hello
|
||||
|
||||
Congratulations. You've just contacted your nodes with Ansible. It's now time to read some
|
||||
of the more real-world examples, and explore what you can do with different modules, as well
|
||||
as the Ansible playbooks language. Ansible is not just about running commands, but you already
|
||||
have a working infrastructure!
|
||||
|
||||
|
@ -1,55 +1,199 @@
|
||||
Modules
|
||||
=======
|
||||
|
||||
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.
|
||||
|
||||
|
||||
|
@ -1,55 +1,63 @@
|
||||
Patterns
|
||||
========
|
||||
|
||||
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.
|
||||
The Inventory File, Patterns, and Groups
|
||||
========================================
|
||||
|
||||
How to select hosts you wish to manage
|
||||
|
||||
.. seealso::
|
||||
|
||||
:doc:`examples`
|
||||
Examples of basic commands
|
||||
:doc:`playbooks`
|
||||
Learning ansible's configuration management language
|
||||
|
||||
Inventory File Format
|
||||
+++++++++++++++++++++
|
||||
|
||||
Ansible works against multiple systems in your infrastructure at the
|
||||
same time. It does this by selecting portions of systems listed in Ansible's inventory file,
|
||||
which defaults to /etc/ansible/hosts, and looks like this::
|
||||
|
||||
mail.example.com
|
||||
|
||||
[webservers]
|
||||
foo.example.com
|
||||
bar.example.com
|
||||
|
||||
[dbservers]
|
||||
one.example.com
|
||||
two.example.com
|
||||
three.example.com
|
||||
|
||||
|
||||
Selecting Targets
|
||||
+++++++++++++++++
|
||||
|
||||
These patterns target all hosts in the inventory file::
|
||||
|
||||
all
|
||||
*
|
||||
|
||||
It is also possible to address specific hosts::
|
||||
|
||||
one.example.com
|
||||
one.example.com:two.example.com
|
||||
|
||||
|
||||
The following patterns address one or more groups, which are denoted with the bracket
|
||||
headers in the inventory file::
|
||||
|
||||
webservers
|
||||
webservers:dbservers
|
||||
|
||||
Individual hosts, but not groups, can also be referenced using wildcards:
|
||||
|
||||
*.example.com
|
||||
*.com
|
||||
|
||||
It's also ok to mix wildcard patterns and groups at the same time::
|
||||
|
||||
one*.com:dbservers
|
||||
|
||||
NOTE: It is not possible to target a host not in the inventory file.
|
||||
|
||||
|
||||
|
@ -1,55 +1,205 @@
|
||||
Playbooks
|
||||
=========
|
||||
|
||||
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.
|
||||
Playbooks: Ansible for Deployment, Configuration Management, and Orchestration
|
||||
==============================================================================
|
||||
|
||||
.. seealso::
|
||||
|
||||
:doc:`YAMLScripts`
|
||||
Learn about YAML syntax
|
||||
:doc:`modules`
|
||||
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
|
||||
back on the webservers group, etc::
|
||||
|
||||
---
|
||||
- hosts: webservers
|
||||
vars:
|
||||
http_port: 80
|
||||
max_clients: 200
|
||||
user: root
|
||||
tasks:
|
||||
- include: base.yml somevar=3 othervar=4
|
||||
- name: write the apache config file
|
||||
action: template src=/srv/httpd.j2 dest=/etc/httpd.conf
|
||||
notify:
|
||||
- restart apache
|
||||
- name: ensure apache is running
|
||||
action: service name=httpd state=started
|
||||
handlers:
|
||||
- include: handlers.yml
|
||||
|
||||
Hosts line
|
||||
``````````
|
||||
|
||||
The hosts line is a list of one or more groups or host patterns, seperated by colons, asdescribed in the 'patterns' documentation. This is just like the first parameter to /usr/bin/ansible.
|
||||
|
||||
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
|
||||
hostname into the /etc/motd file, I could say::
|
||||
|
||||
- name: write the motd
|
||||
- action: template src=/srv/templates/motd.j2 dest=/etc/motd
|
||||
|
||||
And in /srv/templates/motd.j2::
|
||||
|
||||
You are logged into {{ facter_hostname }}
|
||||
|
||||
But we're getting ahead of ourselves. Let's talk about tasks.
|
||||
|
||||
Tasks list
|
||||
``````````
|
||||
|
||||
Each play contains a list of tasks. Tasks are executed in order, one at a time, against
|
||||
all machines matched by the play's host pattern, before moving on to the next task.
|
||||
|
||||
Hosts with failed tasks are taken out of the rotation for the entire playbook. If things fail,
|
||||
simply correct the playbook file and rerun.
|
||||
|
||||
Modules other than command are idempotent, meaning if you run them again, they will make the
|
||||
changes they are told to make to bring the system to the desired state.
|
||||
|
||||
Task name and action
|
||||
`````````````````````
|
||||
|
||||
Every task must have a name, which is included in the output from running the playbook.
|
||||
|
||||
The action line is the name of an ansible module followed by parameters. Usually these
|
||||
are expressed in key=value form, except for the command module, which looks just like a Linux/Unix
|
||||
command line. See the module documentation for more info.
|
||||
|
||||
Variables, as mentioned above, can be used in action lines. So if, hypothetically, you wanted
|
||||
to make a directory on each system named after the hostname ... yeah, that's I know silly ... you could
|
||||
do it like so::
|
||||
|
||||
- name: make a directory
|
||||
- action: mkdir /tmp/{{ facter_hostname }}
|
||||
|
||||
Notify statements
|
||||
`````````````````
|
||||
|
||||
Nearly all modules are written to be 'idempotent' and can signal when they have affected a change
|
||||
on the remote system. If a notify statement is used, the named handler will be run against
|
||||
each system where a change was effected, but NOT on systems where no change occurred. This happens
|
||||
after all of the tasks are run. For example, if notifying Apache and potentially replacing lots of
|
||||
configuration files, you could have Apache restart just once, at the end of a run. If you need
|
||||
Apache restarted in the middle of a run, you could just make a task for it, no harm done. Notifiers
|
||||
are optional.
|
||||
|
||||
Handlers
|
||||
````````
|
||||
|
||||
Handlers are lists of tasks, not really any different from regular tasks, that are referenced
|
||||
by name. Handlers are what notifiers notify. If nothing notifies a handler, it will not run.
|
||||
Regardless of how many things notify a handler, it will run only once, after all of the tasks
|
||||
complete in a particular play.
|
||||
|
||||
Includes
|
||||
````````
|
||||
|
||||
Not all tasks have to be listed directly in the main file. An include file can contain
|
||||
a list of tasks (in YAML) as well, optionally passing extra variables into the file.
|
||||
Variables passed in can be deferenced like this (assume a variable named 'user')::
|
||||
|
||||
{{ user }}
|
||||
|
||||
For instance, if deploying multiple wordpress instances, I could contain all of my tasks
|
||||
in a wordpress.yml file, and use it like so::
|
||||
|
||||
- tasks:
|
||||
- include: wordpress.yml user=timmy
|
||||
- include: wordpress.yml user=alice
|
||||
- include: wordpress.yml user=bob
|
||||
|
||||
In addition to the explicitly passed in parameters, all variables from the vars section
|
||||
are also available.
|
||||
|
||||
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
|
||||
````````````````````````````````
|
||||
|
||||
(Information on this feature is pending)
|
||||
|
||||
Executing A Playbook
|
||||
````````````````````
|
||||
|
||||
To run a playbook::
|
||||
|
||||
ansible-playbook playbook.yml
|
||||
|
||||
|
Loading…
Reference in New Issue