patterns.html 10.5 KB
Newer Older
Tim Bielawa committed
1 2 3 4 5 6 7 8

<!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" />
    
9
    <title>The Inventory File, Patterns, and Groups &mdash; Ansible - SSH-Based Configuration Management &amp; Deployment</title>
Tim Bielawa committed
10 11
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
12 13
    <link rel="stylesheet" href="_static/bootstrap.css" type="text/css" />
    <link rel="stylesheet" href="_static/bootstrap-sphinx.css" type="text/css" />
Tim Bielawa committed
14 15 16
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
17
        VERSION:     '0.01',
Tim Bielawa committed
18 19
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
Tim Bielawa committed
20
        HAS_SOURCE:  false
Tim Bielawa committed
21 22 23 24 25
      };
    </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>
26 27
    <script type="text/javascript" src="_static/bootstrap-dropdown.js"></script>
    <script type="text/javascript" src="_static/bootstrap-scrollspy.js"></script>
28
    <link rel="top" title="Ansible - SSH-Based Configuration Management &amp; Deployment" href="index.html" />
Michael DeHaan committed
29
    <link rel="next" title="Command Line Examples" href="examples.html" />
30
    <link rel="prev" title="Downloads &amp; Getting Started" href="gettingstarted.html" />
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
<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>
Michael DeHaan committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
<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>
101

Tim Bielawa committed
102 103
  </head>
  <body>
104 105 106 107 108 109 110 111 112 113
  <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">Site</a>
  <span class="globaltoc"><ul class="current">
114
<li class="toctree-l1"><a class="reference internal" href="gettingstarted.html">Downloads &amp; Getting Started</a></li>
115 116 117
<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>
118
<li class="toctree-l1"><a class="reference internal" href="YAMLSyntax.html">YAML Syntax</a></li>
119 120
<li class="toctree-l1"><a class="reference internal" href="playbooks.html">Playbooks</a></li>
<li class="toctree-l1"><a class="reference internal" href="api.html">Using the Python API</a></li>
121
<li class="toctree-l1"><a class="reference internal" href="moduledev.html">Module Development Guide</a></li>
122
<li class="toctree-l1"><a class="reference internal" href="faq.html">Frequently Asked Questions</a></li>
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
<li class="toctree-l1"><a class="reference internal" href="man.html">Man Pages</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="#">The Inventory File, Patterns, and Groups</a><ul>
<li><a class="reference internal" href="#inventory-file-format">Inventory File Format</a></li>
<li><a class="reference internal" href="#selecting-targets">Selecting Targets</a></li>
</ul>
</li>
</ul>
</span>
</li>
          
          
            
  <li><a href="gettingstarted.html"
143
         title="previous chapter">&laquo; Downloads &amp; Getting Started</a></li>
144 145 146 147
  <li><a href="examples.html"
         title="next chapter">Command Line Examples &raquo;</a></li>
          
          
Tim Bielawa committed
148
            
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
          
        </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>

165 166 167 168 169 170

<a href="https://github.com/ansible/ansible"><img
   style="position: absolute; top: 40px; right: 0; border: 0;"
   src="https://a248.e.akamai.net/assets.github.com/img/71eeaab9d563c2b3c590319b398dd35683265e85/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677261795f3664366436642e706e67"
alt="Fork me on GitHub"
   alt="Fork me on GitHub"></a>
171 172
<div class="container">
   
173
  <div class="section" id="the-inventory-file-patterns-and-groups">
174
<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>
Michael DeHaan committed
175 176 177 178
<p>How to select hosts you wish to manage</p>
<div class="admonition-see-also admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
Michael DeHaan committed
179
<dt><a class="reference internal" href="examples.html"><em>Command Line Examples</em></a></dt>
Michael DeHaan committed
180
<dd>Examples of basic commands</dd>
181
<dt><a class="reference internal" href="playbooks.html"><em>Playbooks</em></a></dt>
Michael DeHaan committed
182 183 184
<dd>Learning ansible&#8217;s configuration management language</dd>
</dl>
</div>
185
<div class="section" id="inventory-file-format">
186
<span id="inventoryformat"></span><h2>Inventory File Format<a class="headerlink" href="#inventory-file-format" title="Permalink to this headline"></a></h2>
Michael DeHaan committed
187
<p>Ansible works against multiple systems in your infrastructure at the
188 189 190
same time.  It does this by selecting portions of systems listed in
Ansible&#8217;s inventory file, which defaults to /etc/ansible/hosts, and
looks like this:</p>
Michael DeHaan committed
191 192 193 194 195 196 197 198 199 200 201 202
<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>
203 204
<p>The things in brackets are group names, you don&#8217;t have to have them,
but they are useful.</p>
Michael DeHaan committed
205
</div>
206 207 208 209 210
<div class="section" id="selecting-targets">
<h2>Selecting Targets<a class="headerlink" href="#selecting-targets" title="Permalink to this headline"></a></h2>
<p>These patterns target all hosts in the inventory file:</p>
<div class="highlight-python"><pre>all
*</pre>
Michael DeHaan committed
211
</div>
212
<p>Basically &#8216;all&#8217; is an alias for &#8216;*&#8217;.  It is also possible to address a specific host or hosts:</p>
213
<div class="highlight-python"><pre>one.example.com
214 215 216
one.example.com:two.example.com
192.168.1.50
192.168.1.*</pre>
217
</div>
218
<p>The following patterns address one or more groups, which are denoted
219
with the aforementioned bracket headers in the inventory file:</p>
220 221
<div class="highlight-python"><pre>webservers
webservers:dbservers</pre>
Michael DeHaan committed
222
</div>
223
<p>Individual host names (or IPs), but not groups, can also be referenced using
224 225 226 227
wildcards:</p>
<div class="highlight-python"><pre>*.example.com
*.com</pre>
</div>
228 229
<p>It&#8217;s also ok to mix wildcard patterns and groups at the same time:</p>
<div class="highlight-python"><pre>one*.com:dbservers</pre>
Michael DeHaan committed
230
</div>
231 232
<div class="admonition note">
<p class="first admonition-title">Note</p>
233
<p class="last">It is not possible to target a host not in the inventory file.   This is a safety feature.</p>
234
</div>
235
<p>Easy enough.  Now 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>
Michael DeHaan committed
236
</div>
Tim Bielawa committed
237 238 239 240
</div>


</div>
241 242 243 244 245
<footer class="footer">
  <div class="container">
    <p class="pull-right"><a href="#">Back to top</a></p>
    <p>
        &copy; Copyright 2012 Michael DeHaan.<br/>
246
      Last updated on Mar 15, 2012.<br/>
247
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.8.<br/>
248 249 250
    </p>
  </div>
</footer>
Tim Bielawa committed
251 252
  </body>
</html>