169 lines
No EOL
8.4 KiB
HTML
169 lines
No EOL
8.4 KiB
HTML
|
|
|
|
<!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>Examples — 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="API" href="api.html" />
|
|
<link rel="prev" title="Playbooks: Ansible for Deployment, Configuration Management, and Orchestration" href="playbooks.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="api.html" title="API"
|
|
accesskey="N">next</a> |</li>
|
|
<li class="right" >
|
|
<a href="playbooks.html" title="Playbooks: Ansible for Deployment, Configuration Management, and Orchestration"
|
|
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="examples">
|
|
<h1>Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h1>
|
|
<div class="admonition-see-also admonition seealso">
|
|
<p class="first admonition-title">See also</p>
|
|
<dl class="last docutils">
|
|
<dt><a class="reference internal" href="modules.html"><em>Ansible Modules</em></a></dt>
|
|
<dd>A list of available modules</dd>
|
|
<dt><a class="reference internal" href="playbooks.html"><em>Playbooks: Ansible for Deployment, Configuration Management, and Orchestration</em></a></dt>
|
|
<dd>Alternative ways to use ansible</dd>
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="parallelism-and-shell-commands">
|
|
<h2>Parallelism and Shell Commands<a class="headerlink" href="#parallelism-and-shell-commands" title="Permalink to this headline">¶</a></h2>
|
|
<p>Reboot all web servers in Atlanta, 10 at a time:</p>
|
|
<div class="highlight-python"><pre>ssh-agent bash
|
|
ssh-add ~/.ssh/id_rsa.pub
|
|
|
|
ansible atlanta -a "/sbin/reboot" -f 10</pre>
|
|
</div>
|
|
<p>The -f 10 specifies the usage of 10 simultaneous processes.</p>
|
|
<p>Note that other than the command module, ansible modules do not work like simple scripts. They make the remote system look like you state, and run the commands neccessary to get it there.</p>
|
|
</div>
|
|
<div class="section" id="example-2-time-limited-background-operations">
|
|
<h2>Example 2: Time Limited Background Operations<a class="headerlink" href="#example-2-time-limited-background-operations" title="Permalink to this headline">¶</a></h2>
|
|
<p>Long running operations can be backgrounded, and their status can be checked on later. The same job ID is given to the same task on all hosts, so you won’t lose track. Polling support is pending in the command line.:</p>
|
|
<div class="highlight-python"><pre>ansible all -B 3600 -a "/usr/bin/long_running_operation --do-stuff"
|
|
ansible all -n job_status -a jid=123456789</pre>
|
|
</div>
|
|
<p>Any module other than ‘copy’ or ‘template’ can be backgrounded.</p>
|
|
</div>
|
|
<div class="section" id="examples-3-file-transfer-templating">
|
|
<h2>Examples 3: File Transfer & Templating<a class="headerlink" href="#examples-3-file-transfer-templating" title="Permalink to this headline">¶</a></h2>
|
|
<p>Ansible can SCP lots of files to multiple machines in parallel, and optionally use them as template sources.</p>
|
|
<p>To just transfer a file directly to many different servers:</p>
|
|
<div class="highlight-python"><pre>ansible atlanta copy -a "/etc/hosts /tmp/hosts"</pre>
|
|
</div>
|
|
<p>To use templating, first run the setup module to put the template variables you would like to use on the remote host. Then use the template module to write the files using the templates. Templates are written in Jinja2 format. Playbooks (covered below) will run the setup module for you, making this even simpler.:</p>
|
|
<div class="highlight-python"><pre>ansible webservers -m setup -a "favcolor=red ntp_server=192.168.1.1"
|
|
ansible webservers -m template -a "src=/srv/motd.j2 dest=/etc/motd"
|
|
ansible webservers -m template -a "src=/srv/ntp.j2 dest=/etc/ntp.conf"</pre>
|
|
</div>
|
|
<p>Need something like the fqdn in a template? If facter or ohai are installed, data from these projects will also be made available to the template engine, using ‘facter’ and ‘ohai’ prefixes for each.</p>
|
|
</div>
|
|
<div class="section" id="examples-3-deploying-from-source-control">
|
|
<h2>Examples 3: Deploying From Source Control<a class="headerlink" href="#examples-3-deploying-from-source-control" title="Permalink to this headline">¶</a></h2>
|
|
<p>Deploy your webapp straight from git:</p>
|
|
<div class="highlight-python"><pre>ansible webservers -m git -a "repo=git://foo dest=/srv/myapp version=HEAD"</pre>
|
|
</div>
|
|
<p>Since ansible modules can notify change handlers (see ‘Playbooks’) it is possible to tell ansible to run specific tasks when the code is updated, such as deploying Perl/Python/PHP/Ruby directly from git and then restarting apache.</p>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="sphinxsidebar">
|
|
<div class="sphinxsidebarwrapper">
|
|
<h3><a href="index.html">Table Of Contents</a></h3>
|
|
<ul>
|
|
<li><a class="reference internal" href="#">Examples</a><ul>
|
|
<li><a class="reference internal" href="#parallelism-and-shell-commands">Parallelism and Shell Commands</a></li>
|
|
<li><a class="reference internal" href="#example-2-time-limited-background-operations">Example 2: Time Limited Background Operations</a></li>
|
|
<li><a class="reference internal" href="#examples-3-file-transfer-templating">Examples 3: File Transfer & Templating</a></li>
|
|
<li><a class="reference internal" href="#examples-3-deploying-from-source-control">Examples 3: Deploying From Source Control</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
|
|
<h4>Previous topic</h4>
|
|
<p class="topless"><a href="playbooks.html"
|
|
title="previous chapter">Playbooks: Ansible for Deployment, Configuration Management, and Orchestration</a></p>
|
|
<h4>Next topic</h4>
|
|
<p class="topless"><a href="api.html"
|
|
title="next chapter">API</a></p>
|
|
<h3>This Page</h3>
|
|
<ul class="this-page-menu">
|
|
<li><a href="_sources/examples.txt"
|
|
rel="nofollow">Show Source</a></li>
|
|
</ul>
|
|
<div id="searchbox" style="display: none">
|
|
<h3>Quick search</h3>
|
|
<form class="search" action="search.html" method="get">
|
|
<input type="text" name="q" />
|
|
<input type="submit" value="Go" />
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
<input type="hidden" name="area" value="default" />
|
|
</form>
|
|
<p class="searchtip" style="font-size: 90%">
|
|
Enter search terms or a module, class or function name.
|
|
</p>
|
|
</div>
|
|
<script type="text/javascript">$('#searchbox').show(0);</script>
|
|
</div>
|
|
</div>
|
|
<div class="clearer"></div>
|
|
</div>
|
|
<div class="related">
|
|
<h3>Navigation</h3>
|
|
<ul>
|
|
<li class="right" style="margin-right: 10px">
|
|
<a href="genindex.html" title="General Index"
|
|
>index</a></li>
|
|
<li class="right" >
|
|
<a href="api.html" title="API"
|
|
>next</a> |</li>
|
|
<li class="right" >
|
|
<a href="playbooks.html" title="Playbooks: Ansible for Deployment, Configuration Management, and Orchestration"
|
|
>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 08, 2012.
|
|
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.8.
|
|
</div>
|
|
</body>
|
|
</html> |