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" / >
2012-03-13 00:13:19 +01:00
< title > The Inventory File, Patterns, and Groups — Ansible - SSH-Based Configuration Management & Deployment< / title >
2012-03-07 17:35:18 +01:00
< link rel = "stylesheet" href = "_static/default.css" type = "text/css" / >
< link rel = "stylesheet" href = "_static/pygments.css" type = "text/css" / >
2012-03-09 17:44:14 +01:00
< link rel = "stylesheet" href = "_static/bootstrap.css" type = "text/css" / >
< link rel = "stylesheet" href = "_static/bootstrap-sphinx.css" type = "text/css" / >
2012-03-07 17:35:18 +01:00
< script type = "text/javascript" >
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
2012-03-13 00:13:19 +01:00
VERSION: '0.01',
2012-03-07 17:35:18 +01:00
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
2012-03-09 17:50:07 +01:00
HAS_SOURCE: false
2012-03-07 17:35:18 +01:00
};
< / 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 >
2012-03-09 17:44:14 +01:00
< script type = "text/javascript" src = "_static/bootstrap-dropdown.js" > < / script >
< script type = "text/javascript" src = "_static/bootstrap-scrollspy.js" > < / script >
2012-04-01 04:44:02 +02:00
< link rel = "shortcut icon" href = "_static/favicon.ico" / >
2012-03-13 00:13:19 +01:00
< link rel = "top" title = "Ansible - SSH-Based Configuration Management & Deployment" href = "index.html" / >
2012-03-09 13:42:53 +01:00
< link rel = "next" title = "Command Line Examples" href = "examples.html" / >
2012-03-10 03:50:00 +01:00
< link rel = "prev" title = "Downloads & Getting Started" href = "gettingstarted.html" / >
2012-03-09 17:44:14 +01:00
< 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 >
2012-04-28 16:46:09 +02:00
2012-03-10 04:31:54 +01:00
< 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 >
2012-04-28 16:46:09 +02:00
< 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 >
2012-04-28 16:42:32 +02:00
< script > ( f u n c t i o n ( d , s , i d ) {
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 >
2012-03-09 17:44:14 +01:00
2012-03-07 17:35:18 +01:00
< / head >
< body >
2012-03-09 17:44:14 +01:00
< div class = "topbar" data-scrollspy = "scrollspy" >
< div class = "topbar-inner" >
< div class = "container" >
2012-04-18 02:47:29 +02:00
<!-- <a class="brand" href="index.html">Ansible</a> -->
2012-03-09 17:44:14 +01:00
< ul class = "nav" >
< li class = "dropdown" data-dropdown = "dropdown" >
< a href = "index.html"
2012-03-31 15:29:31 +02:00
class="dropdown-toggle">Chapter< / a >
2012-03-09 17:44:14 +01:00
< span class = "globaltoc" > < ul class = "current" >
2012-03-10 03:50:00 +01:00
< li class = "toctree-l1" > < a class = "reference internal" href = "gettingstarted.html" > Downloads & Getting Started< / a > < / li >
2012-03-09 17:44:14 +01:00
< li class = "toctree-l1 current" > < a class = "current reference internal" href = "" > The Inventory File, Patterns, and Groups< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "examples.html" > Command Line Examples< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "modules.html" > Ansible Modules< / a > < / li >
2012-03-11 20:34:21 +01:00
< li class = "toctree-l1" > < a class = "reference internal" href = "YAMLSyntax.html" > YAML Syntax< / a > < / li >
2012-03-09 17:44:14 +01:00
< li class = "toctree-l1" > < a class = "reference internal" href = "playbooks.html" > Playbooks< / a > < / li >
2012-03-31 04:28:30 +02:00
< li class = "toctree-l1" > < a class = "reference internal" href = "api.html" > API & Integrations< / a > < / li >
2012-03-14 17:50:40 +01:00
< li class = "toctree-l1" > < a class = "reference internal" href = "moduledev.html" > Module Development Guide< / a > < / li >
2012-03-10 03:50:00 +01:00
< li class = "toctree-l1" > < a class = "reference internal" href = "faq.html" > Frequently Asked Questions< / a > < / li >
2012-03-09 17:44:14 +01:00
< / ul >
< / span >
2012-03-31 15:36:37 +02:00
< / li >
< li class = "dropdown" data-dropdown = "dropdown" >
< a href = "#"
class="dropdown-toggle">Page< / a >
< span class = "localtoc" > < ul >
< li > < a class = "reference internal" href = "#" > The Inventory File, Patterns, and Groups< / a > < ul >
2012-04-19 16:45:41 +02:00
< li > < a class = "reference internal" href = "#basic-inventory-file-format" > Basic Inventory File Format< / a > < / li >
2012-03-31 15:36:37 +02:00
< li > < a class = "reference internal" href = "#selecting-targets" > Selecting Targets< / a > < / li >
2012-04-18 01:54:23 +02:00
< li > < a class = "reference internal" href = "#advanced-inventory-file-format" > Advanced Inventory File Format< / a > < / li >
2012-03-31 15:36:37 +02:00
< / ul >
< / li >
< / ul >
< / span >
2012-03-09 17:44:14 +01:00
< / 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 >
2012-04-19 15:39:50 +02:00
< a href = "http://github.com/ansible/ansible" > < img style = "position: absolute; right: 0; border: 0;" src = "https://a248.e.akamai.net/assets.github.com/img/e6bef7a091f5f3138b8cd40bc3e114258dd68ddf/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f7265645f6161303030302e706e67" alt = "Fork me on GitHub" > < / a >
2012-03-09 17:44:14 +01:00
2012-03-10 16:39:34 +01:00
2012-03-09 17:44:14 +01:00
< div class = "container" >
2012-04-19 15:24:45 +02:00
< a href = "http://ansible.github.com" > < img src = "http://ansible.github.com/ansible-logo.png" alt = "Ansible" / > < / a > < br / >
2012-04-28 16:42:32 +02:00
< br / >
2012-03-09 17:44:14 +01:00
2012-03-08 19:53:48 +01:00
< div class = "section" id = "the-inventory-file-patterns-and-groups" >
2012-03-09 17:44:14 +01:00
< span id = "patterns" > < / span > < h1 > The Inventory File, Patterns, and Groups< a class = "headerlink" href = "#the-inventory-file-patterns-and-groups" title = "Permalink to this headline" > ¶< / a > < / h1 >
2012-03-08 19:36:47 +01:00
< p > Ansible works against multiple systems in your infrastructure at the
2012-03-10 00:29:01 +01:00
same time. It does this by selecting portions of systems listed in
2012-03-31 16:38:24 +02:00
Ansible’ s inventory file, which defaults to /etc/ansible/hosts.< / p >
2012-04-19 16:45:41 +02:00
< div class = "section" id = "basic-inventory-file-format" >
< span id = "inventoryformat" > < / span > < h2 > Basic Inventory File Format< a class = "headerlink" href = "#basic-inventory-file-format" title = "Permalink to this headline" > ¶< / a > < / h2 >
2012-03-31 16:38:24 +02:00
< p > The format for /etc/ansible/hosts looks like this:< / p >
2012-03-08 19:36:47 +01:00
< 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 >
2012-03-11 20:34:21 +01:00
< p > The things in brackets are group names, you don’ t have to have them,
but they are useful.< / p >
2012-04-18 01:59:15 +02:00
< p > If you have hosts that run on non-standard SSH ports you can put the port number
after the hostname with a colon. This requires Ansible 0.3 (integration branch):< / p >
< div class = "highlight-python" > < pre > four.example.com:5309< / pre >
< / div >
2012-03-08 19:36:47 +01:00
< / div >
2012-03-08 19:53:48 +01:00
< div class = "section" id = "selecting-targets" >
< h2 > Selecting Targets< a class = "headerlink" href = "#selecting-targets" title = "Permalink to this headline" > ¶< / a > < / h2 >
2012-03-31 16:38:24 +02:00
< p > We’ ll go over how to use the command line in < a class = "reference internal" href = "examples.html" > < em > Command Line Examples< / 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 >
2012-03-31 16:40:01 +02:00
< div class = "highlight-python" > < pre > ansible webservers -m service -a "name=httpd state=restarted"< / pre >
< / div >
2012-03-31 16:38:24 +02:00
< p > Within < a class = "reference internal" href = "playbooks.html" > < em > Playbooks< / em > < / a > , these patterns can also 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 >
2012-03-08 19:53:48 +01:00
< div class = "highlight-python" > < pre > all
*< / pre >
2012-03-08 19:36:47 +01:00
< / div >
2012-03-11 20:34:21 +01:00
< p > Basically ‘ all’ is an alias for ‘ *’ . It is also possible to address a specific host or hosts:< / p >
2012-03-08 19:53:48 +01:00
< div class = "highlight-python" > < pre > one.example.com
2012-03-11 20:34:21 +01:00
one.example.com:two.example.com
192.168.1.50
192.168.1.*< / pre >
2012-03-08 19:53:48 +01:00
< / div >
2012-03-09 17:44:14 +01:00
< p > The following patterns address one or more groups, which are denoted
2012-03-11 20:34:21 +01:00
with the aforementioned bracket headers in the inventory file:< / p >
2012-03-08 19:53:48 +01:00
< div class = "highlight-python" > < pre > webservers
webservers:dbservers< / pre >
2012-03-08 19:36:47 +01:00
< / div >
2012-03-11 20:34:21 +01:00
< p > Individual host names (or IPs), but not groups, can also be referenced using
2012-03-09 17:44:14 +01:00
wildcards:< / p >
< div class = "highlight-python" > < pre > *.example.com
*.com< / pre >
< / div >
2012-03-08 19:53:48 +01:00
< 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 >
2012-03-08 19:36:47 +01:00
< / div >
2012-03-10 00:29:01 +01:00
< div class = "admonition note" >
< p class = "first admonition-title" > Note< / p >
2012-03-11 20:34:21 +01:00
< p class = "last" > It is not possible to target a host not in the inventory file. This is a safety feature.< / p >
2012-03-10 00:29:01 +01:00
< / div >
2012-04-18 01:54:23 +02:00
< p > Easy enough. See < a class = "reference internal" href = "examples.html" > < em > Command Line Examples< / 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 = "advanced-inventory-file-format" >
< h2 > Advanced Inventory File Format< a class = "headerlink" href = "#advanced-inventory-file-format" title = "Permalink to this headline" > ¶< / a > < / h2 >
< p > (This features requires the integration branch of Ansible, soon to be release 0.3)< / p >
< p > Once you read about playbooks you’ ll quickly see how useful it will be to assign particular variables
to particular hosts and groups of hosts. While the default INI-style host format doesn’ t allow this,
switching to the YAML inventory format can add some compelling capabilities. Just replace your INI
style file with a YAML one.:< / 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 “ — ” .< / p >
2012-04-27 07:39:15 +02:00
< p > NOTE: variables specified in playbooks will override variables specified
in the host file. Further, if a host is in multiple groups, currently, the
variables set by the last loaded group will win over variables set in other
groups. This behavior may be refined in future releases.< / p >
2012-03-31 15:29:31 +02: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 = "examples.html" > < em > Command Line Examples< / 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 >
2012-03-31 15:55:37 +02:00
< 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 >
2012-03-31 15:29:31 +02:00
< / dl >
< / div >
2012-03-08 19:36:47 +01:00
< / div >
2012-03-07 17:35:18 +01:00
< / div >
2012-04-28 16:42:32 +02:00
< br / >
2012-03-07 17:35:18 +01:00
< / div >
2012-04-28 16:53:15 +02:00
< footer class = "footer" >
< div class = "container" >
< div id = "fb-root" > < / div >
2012-04-28 16:50:20 +02:00
< p >
2012-04-28 16:42:32 +02:00
< 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 >
2012-04-28 16:50:20 +02:00
< / p >
< p >
2012-03-09 17:44:14 +01:00
© Copyright 2012 Michael DeHaan.< br / >
2012-04-28 16:42:32 +02:00
Last updated on Apr 28, 2012.< br / >
2012-03-09 17:44:14 +01:00
< / p >
< / div >
< / footer >
2012-03-07 17:35:18 +01:00
< / body >
< / html >