mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
371 lines
No EOL
15 KiB
HTML
371 lines
No EOL
15 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>Inventory & Patterns — Ansible - SSH-Based Configuration Management & Deployment</title>
|
|
<link rel="stylesheet" href="_static/default.css" type="text/css" />
|
|
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
|
<link rel="stylesheet" href="_static/bootstrap.css" type="text/css" />
|
|
<link rel="stylesheet" href="_static/bootstrap-sphinx.css" type="text/css" />
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT: '',
|
|
VERSION: '0.01',
|
|
COLLAPSE_INDEX: false,
|
|
FILE_SUFFIX: '.html',
|
|
HAS_SOURCE: false
|
|
};
|
|
</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>
|
|
<script type="text/javascript" src="_static/bootstrap-dropdown.js"></script>
|
|
<script type="text/javascript" src="_static/bootstrap-scrollspy.js"></script>
|
|
<link rel="shortcut icon" href="_static/favicon.ico"/>
|
|
<link rel="top" title="Ansible - SSH-Based Configuration Management & Deployment" href="index.html" />
|
|
<link rel="next" title="Command Line" href="examples.html" />
|
|
<link rel="prev" title="Getting Started" href="gettingstarted.html" />
|
|
<script type="text/javascript">
|
|
(function () {
|
|
/**
|
|
* Patch TOC list.
|
|
*
|
|
* Will mutate the underlying span to have a correct ul for nav.
|
|
*
|
|
* @param $span: Span containing nested UL's to mutate.
|
|
* @param minLevel: Starting level for nested lists. (1: global, 2: local).
|
|
*/
|
|
var patchToc = function ($span, minLevel) {
|
|
var $tocList = $("<ul/>").attr('class', "dropdown-menu"),
|
|
findA;
|
|
|
|
// Find all a "internal" tags, traversing recursively.
|
|
findA = function ($elem, level) {
|
|
var level = level || 0,
|
|
$items = $elem.find("> li > a.internal, > ul, > li > ul");
|
|
|
|
// Iterate everything in order.
|
|
$items.each(function (index, item) {
|
|
var $item = $(item),
|
|
tag = item.tagName.toLowerCase(),
|
|
pad = 10 + ((level - minLevel) * 10);
|
|
|
|
if (tag === 'a' && level >= minLevel) {
|
|
// Add to existing padding.
|
|
$item.css('padding-left', pad + "px");
|
|
// Add list element.
|
|
$tocList.append($("<li/>").append($item));
|
|
} else if (tag === 'ul') {
|
|
// Recurse.
|
|
findA($item, level + 1);
|
|
}
|
|
});
|
|
};
|
|
|
|
// Start construction and return.
|
|
findA($span);
|
|
|
|
// Wipe out old list and patch in new one.
|
|
return $span.empty("ul").append($tocList);
|
|
};
|
|
|
|
$(document).ready(function () {
|
|
// Patch the global and local TOC's to be bootstrap-compliant.
|
|
patchToc($("span.globaltoc"), 1);
|
|
patchToc($("span.localtoc"), 2);
|
|
|
|
// Activate.
|
|
$('#topbar').dropdown();
|
|
});
|
|
}());
|
|
</script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
var _gaq = _gaq || [];
|
|
_gaq.push(['_setAccount', 'UA-29861888-1']);
|
|
_gaq.push(['_trackPageview']);
|
|
|
|
(function() {
|
|
var ga = document.createElement('script'); ga.type =
|
|
'text/javascript'; ga.async = true;
|
|
ga.src = ('https:' == document.location.protocol ? 'https://ssl' :
|
|
'http://www') + '.google-analytics.com/ga.js';
|
|
var s = document.getElementsByTagName('script')[0];
|
|
s.parentNode.insertBefore(ga, s);
|
|
})();
|
|
|
|
</script>
|
|
|
|
<script type="text/javascript">
|
|
(function() {
|
|
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
|
|
po.src = 'https://apis.google.com/js/plusone.js';
|
|
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
|
|
})();
|
|
</script>
|
|
|
|
<script>(function(d, s, id) {
|
|
var js, fjs = d.getElementsByTagName(s)[0];
|
|
if (d.getElementById(id)) return;
|
|
js = d.createElement(s); js.id = id;
|
|
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
|
|
fjs.parentNode.insertBefore(js, fjs);
|
|
}(document, 'script', 'facebook-jssdk'));</script>
|
|
|
|
</head>
|
|
<body>
|
|
<div class="topbar" data-scrollspy="scrollspy" >
|
|
<div class="topbar-inner">
|
|
<div class="container">
|
|
<!-- <a class="brand" href="index.html">Ansible</a> -->
|
|
<ul class="nav">
|
|
|
|
<li class="dropdown" data-dropdown="dropdown">
|
|
<a href="index.html"
|
|
class="dropdown-toggle">Chapter</a>
|
|
<span class="globaltoc"><ul class="current">
|
|
<li class="toctree-l1"><a class="reference internal" href="gettingstarted.html">Getting Started</a></li>
|
|
<li class="toctree-l1 current"><a class="current reference internal" href="">Inventory & Patterns</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="examples.html">Command Line</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="modules.html">Ansible Modules</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="YAMLSyntax.html">YAML Syntax</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="playbooks.html">Playbooks</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="playbooks2.html">Advanced Playbooks</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="bestpractices.html">Best Practices</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="api.html">API & Integrations</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="moduledev.html">Module Development</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="faq.html">FAQ</a></li>
|
|
</ul>
|
|
</span>
|
|
</li>
|
|
<li class="dropdown" data-dropdown="dropdown">
|
|
<a href="#"
|
|
class="dropdown-toggle">Page</a>
|
|
<span class="localtoc"><ul>
|
|
<li><a class="reference internal" href="#">Inventory & Patterns</a><ul>
|
|
<li><a class="reference internal" href="#hosts-and-groups">Hosts and Groups</a></li>
|
|
<li><a class="reference internal" href="#selecting-targets">Selecting Targets</a></li>
|
|
<li><a class="reference internal" href="#host-variables">Host Variables</a></li>
|
|
<li><a class="reference internal" href="#group-variables">Group Variables</a></li>
|
|
<li><a class="reference internal" href="#groups-of-groups-and-group-variables">Groups of Groups, and Group Variables</a></li>
|
|
<li><a class="reference internal" href="#yaml-inventory-format">YAML Inventory Format</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</span>
|
|
</li>
|
|
|
|
</ul>
|
|
<ul class="nav secondary-nav">
|
|
|
|
|
|
<form class="pull-left" action="search.html" method="get">
|
|
<input type="text" name="q" placeholder="Search" />
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
<input type="hidden" name="area" value="default" />
|
|
</form>
|
|
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<a href="http://github.com/ansible/ansible"><img style="position: absolute; right: 0; border: 0;" src="http://ansible.github.com/github.png" alt="Fork me on GitHub"></a>
|
|
|
|
|
|
<div class="container">
|
|
<a href="http://ansible.github.com"><img src="http://ansible.github.com/ansible-logo.png" alt="Ansible"/></a><br/>
|
|
<br/>
|
|
|
|
<div class="section" id="inventory-patterns">
|
|
<span id="patterns"></span><h1>Inventory & Patterns<a class="headerlink" href="#inventory-patterns" title="Permalink to this headline">¶</a></h1>
|
|
<p>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.</p>
|
|
<div class="section" id="hosts-and-groups">
|
|
<span id="inventoryformat"></span><h2>Hosts and Groups<a class="headerlink" href="#hosts-and-groups" title="Permalink to this headline">¶</a></h2>
|
|
<p>The format for /etc/ansible/hosts is an INI format and looks like this:</p>
|
|
<div class="highlight-python"><div class="highlight"><pre><span class="n">mail</span><span class="o">.</span><span class="n">example</span><span class="o">.</span><span class="n">com</span>
|
|
|
|
<span class="p">[</span><span class="n">webservers</span><span class="p">]</span>
|
|
<span class="n">foo</span><span class="o">.</span><span class="n">example</span><span class="o">.</span><span class="n">com</span>
|
|
<span class="n">bar</span><span class="o">.</span><span class="n">example</span><span class="o">.</span><span class="n">com</span>
|
|
|
|
<span class="p">[</span><span class="n">dbservers</span><span class="p">]</span>
|
|
<span class="n">one</span><span class="o">.</span><span class="n">example</span><span class="o">.</span><span class="n">com</span>
|
|
<span class="n">two</span><span class="o">.</span><span class="n">example</span><span class="o">.</span><span class="n">com</span>
|
|
<span class="n">three</span><span class="o">.</span><span class="n">example</span><span class="o">.</span><span class="n">com</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>The things in brackets are group names. You don’t have to have them,
|
|
but they are useful.</p>
|
|
<p>If you have hosts that run on non-standard SSH ports you can put the port number
|
|
after the hostname with a colon.</p>
|
|
<blockquote>
|
|
<div>four.example.com:5309</div></blockquote>
|
|
</div>
|
|
<div class="section" id="selecting-targets">
|
|
<h2>Selecting Targets<a class="headerlink" href="#selecting-targets" title="Permalink to this headline">¶</a></h2>
|
|
<p>We’ll go over how to use the command line in <a class="reference internal" href="examples.html"><em>Command Line</em></a> section, however, basically it looks like this:</p>
|
|
<div class="highlight-python"><pre>ansible <pattern_goes_here> -m <module_name> -a <arguments></pre>
|
|
</div>
|
|
<p>Such as:</p>
|
|
<div class="highlight-python"><pre>ansible webservers -m service -a "name=httpd state=restarted"</pre>
|
|
</div>
|
|
<p>Within <a class="reference internal" href="playbooks.html"><em>Playbooks</em></a>, these patterns can be used for even greater purposes.</p>
|
|
<p>Anyway, to use Ansible, you’ll first need to know how to tell Ansible which hosts in your inventory file to talk to.
|
|
This is done by designating particular host names or groups of hosts.</p>
|
|
<p>The following patterns target all hosts in the inventory file:</p>
|
|
<div class="highlight-python"><pre>all
|
|
*</pre>
|
|
</div>
|
|
<p>Basically ‘all’ is an alias for ‘*’. It is also possible to address a specific host or hosts:</p>
|
|
<div class="highlight-python"><pre>one.example.com
|
|
one.example.com:two.example.com
|
|
192.168.1.50
|
|
192.168.1.*</pre>
|
|
</div>
|
|
<p>The following patterns address one or more groups, which are denoted
|
|
with the aforementioned bracket headers in the inventory file:</p>
|
|
<div class="highlight-python"><pre>webservers
|
|
webservers:dbservers</pre>
|
|
</div>
|
|
<p>Individual host names (or IPs), but not groups, can also be referenced using
|
|
wildcards:</p>
|
|
<div class="highlight-python"><pre>*.example.com
|
|
*.com</pre>
|
|
</div>
|
|
<p>It’s also ok to mix wildcard patterns and groups at the same time:</p>
|
|
<div class="highlight-python"><pre>one*.com:dbservers</pre>
|
|
</div>
|
|
<p>Easy enough. See <a class="reference internal" href="examples.html"><em>Command Line</em></a> and then <a class="reference internal" href="playbooks.html"><em>Playbooks</em></a> for how to do things to selected hosts.</p>
|
|
</div>
|
|
<div class="section" id="host-variables">
|
|
<h2>Host Variables<a class="headerlink" href="#host-variables" title="Permalink to this headline">¶</a></h2>
|
|
<p>Using the 0.4 branch of Ansible, it is easy to assign variables to hosts that will be used
|
|
later in playbooks:</p>
|
|
<div class="highlight-python"><pre>[atlanta]
|
|
host1 http_port=80 maxRequestsPerChild=808
|
|
host2 http_port=303 maxRequestsPerChild=909</pre>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="group-variables">
|
|
<h2>Group Variables<a class="headerlink" href="#group-variables" title="Permalink to this headline">¶</a></h2>
|
|
<p>Using the 0.4 branch of Ansible, variables can also be applied to an entire group at once:</p>
|
|
<div class="highlight-python"><pre>[atlanta]
|
|
host1
|
|
host2
|
|
|
|
[atlanta:vars]
|
|
ntp_server=ntp.atlanta.example.com
|
|
proxy=proxy.atlanta.example.com</pre>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="groups-of-groups-and-group-variables">
|
|
<h2>Groups of Groups, and Group Variables<a class="headerlink" href="#groups-of-groups-and-group-variables" title="Permalink to this headline">¶</a></h2>
|
|
<p>Using Ansible 0.4, it is possible to make groups of groups and assign
|
|
variables to groups. These variables can be used by /usr/bin/ansible-playbook, but not
|
|
/usr/bin/ansible.</p>
|
|
<blockquote>
|
|
<div><p>[atlanta]
|
|
host1
|
|
host2</p>
|
|
<p>[raleigh]
|
|
host2
|
|
host3</p>
|
|
<p>[southeast:children]
|
|
atlanta
|
|
raleigh</p>
|
|
<p>[southeast:vars]
|
|
some_server=foo.southeast.example.com
|
|
halon_system_timeout=30
|
|
self_destruct_countdown=60
|
|
escape_pods=2</p>
|
|
<p>[usa:children]
|
|
southeast
|
|
northeast
|
|
southwest
|
|
southeast</p>
|
|
</div></blockquote>
|
|
</div>
|
|
<div class="section" id="yaml-inventory-format">
|
|
<h2>YAML Inventory Format<a class="headerlink" href="#yaml-inventory-format" title="Permalink to this headline">¶</a></h2>
|
|
<p>For people using 0.3, or those that prefer to use it, the inventory file can also be expressed in
|
|
YAML:</p>
|
|
<div class="highlight-python"><pre>---
|
|
|
|
# some ungrouped hosts, either use the short string form or the "host: " prefix
|
|
- host: jupiter
|
|
- mars
|
|
|
|
# variables can be assigned like this...
|
|
- host: saturn
|
|
vars:
|
|
- moon: titan
|
|
|
|
# groups can also set variables to all hosts in the group
|
|
# here are a bunch of hosts using a non-standard SSH port
|
|
# and also defining a variable 'ntpserver'
|
|
- group: greek
|
|
hosts:
|
|
- zeus
|
|
- hera
|
|
- poseidon
|
|
vars:
|
|
- ansible_ssh_port: 3000
|
|
- ntp_server: olympus.example.com
|
|
|
|
# individual hosts can still set variables inside of groups too
|
|
# so you aren't limited to just group variables and host variables.
|
|
- group: norse
|
|
hosts:
|
|
- host: thor
|
|
vars:
|
|
- hammer: True
|
|
- odin
|
|
- loki
|
|
vars:
|
|
- asdf: 1234</pre>
|
|
</div>
|
|
<p>Tip: Be sure to start your YAML file with the YAML record designator <tt class="docutils literal"><span class="pre">---</span></tt>.</p>
|
|
<div class="admonition-see-also admonition seealso">
|
|
<p class="first admonition-title">See also</p>
|
|
<dl class="last docutils">
|
|
<dt><a class="reference internal" href="examples.html"><em>Command Line</em></a></dt>
|
|
<dd>Examples of basic commands</dd>
|
|
<dt><a class="reference internal" href="playbooks.html"><em>Playbooks</em></a></dt>
|
|
<dd>Learning ansible’s configuration management language</dd>
|
|
<dt><a class="reference external" href="http://groups.google.com/group/ansible-project">Mailing List</a></dt>
|
|
<dd>Questions? Help? Ideas? Stop by the list on Google Groups</dd>
|
|
<dt><a class="reference external" href="http://irc.freenode.net">irc.freenode.net</a></dt>
|
|
<dd>#ansible IRC chat channel</dd>
|
|
</dl>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<br/>
|
|
</div>
|
|
<footer class="footer">
|
|
|
|
<div class="container">
|
|
<div id="fb-root"></div>
|
|
<p>
|
|
<a href="https://twitter.com/share" class="twitter-share-button" data-text="ansible.github.com">Share On Twitter</a>
|
|
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
|
|
<g:plusone annotation="inline"></g:plusone>
|
|
<div class="fb-like" data-href="http://ansible.github.com" data-send="true" data-width="450" data-show-faces="false"></div>
|
|
</p>
|
|
<p>
|
|
© Copyright 2012 Michael DeHaan.<br/>
|
|
Last updated on May 13, 2012.<br/>
|
|
</p>
|
|
</div>
|
|
</footer>
|
|
</body>
|
|
</html> |