1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/html/examples.html

169 lines
8.1 KiB
HTML
Raw Normal View History

2012-03-07 17:35:18 +01:00
<!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 &mdash; Ansible v0.0.1 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '0.0.1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Ansible v0.0.1 documentation" href="index.html" />
<link rel="next" title="API" href="api.html" />
<link rel="prev" title="Playbooks" href="playbooks.html" />
2012-03-07 17:35:18 +01:00
</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"
2012-03-07 17:35:18 +01:00
accesskey="N">next</a> |</li>
<li class="right" >
<a href="playbooks.html" title="Playbooks"
2012-03-07 17:35:18 +01:00
accesskey="P">previous</a> |</li>
<li><a href="index.html">Ansible v0.0.1 documentation</a> &raquo;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="examples">
<h1>Examples<a class="headerlink" href="#examples" title="Permalink to this headline"></a></h1>
2012-03-08 19:36:47 +01:00
<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</em></a></dt>
<dd>Alternative ways to use ansible</dd>
</dl>
2012-03-07 17:35:18 +01:00
</div>
2012-03-08 19:36:47 +01:00
<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&#8217;t lose track. Polling support is pending in the command line.:</p>
<div class="highlight-python"><pre>ansible all -B 3600 -a "/usr/bin/long_running_operation --do-stuff"
ansible all -n job_status -a jid=123456789</pre>
</div>
<p>Any module other than &#8216;copy&#8217; or &#8216;template&#8217; can be backgrounded.</p>
</div>
<div class="section" id="examples-3-file-transfer-templating">
<h2>Examples 3: File Transfer &amp; 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>
2012-03-07 17:35:18 +01:00
</div>
2012-03-08 19:36:47 +01:00
<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 &#8216;facter&#8217; and &#8216;ohai&#8217; prefixes for each.</p>
2012-03-07 17:35:18 +01:00
</div>
2012-03-08 19:36:47 +01:00
<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>
2012-03-07 17:35:18 +01:00
</div>
2012-03-08 19:36:47 +01:00
<p>Since ansible modules can notify change handlers (see &#8216;Playbooks&#8217;) 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>
2012-03-07 17:35:18 +01:00
</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>
2012-03-08 19:36:47 +01:00
<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 &amp; Templating</a></li>
<li><a class="reference internal" href="#examples-3-deploying-from-source-control">Examples 3: Deploying From Source Control</a></li>
2012-03-07 17:35:18 +01:00
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="playbooks.html"
title="previous chapter">Playbooks</a></p>
2012-03-07 17:35:18 +01:00
<h4>Next topic</h4>
<p class="topless"><a href="api.html"
title="next chapter">API</a></p>
2012-03-07 17:35:18 +01:00
<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">
2012-03-08 19:36:47 +01:00
<input type="text" name="q" />
2012-03-07 17:35:18 +01:00
<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"
2012-03-07 17:35:18 +01:00
>next</a> |</li>
<li class="right" >
<a href="playbooks.html" title="Playbooks"
2012-03-07 17:35:18 +01:00
>previous</a> |</li>
<li><a href="index.html">Ansible v0.0.1 documentation</a> &raquo;</li>
</ul>
</div>
<div class="footer">
&copy; Copyright 2012 Michael DeHaan.
2012-03-08 19:36:47 +01:00
Last updated on Mar 08, 2012.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.8.
2012-03-07 17:35:18 +01:00
</div>
</body>
</html>