@@ -261,32 +261,8 @@ optionally use them as template sources.</p>
<divclass="highlight-bash"><divclass="highlight"><pre><spanclass="nv">$ </span>ansible atlanta -m copy -a <spanclass="s2">"src=/etc/hosts dest=/tmp/hosts"</span>
</pre></div>
</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 those templates.</p>
<p>Templates are written in <aclass="reference external"href="http://jinja.pocoo.org/docs/">Jinja2</a>
format. <aclass="reference internal"href="playbooks.html"><em>Playbooks</em></a> will run the setup module for you, making
this even simpler:</p>
<divclass="highlight-bash"><divclass="highlight"><pre><spanclass="nv">$ </span>ansible webservers -m setup -a <spanclass="s2">"favcolor=red ntp_server=192.168.1.1"</span>
<spanclass="nv">$ </span>ansible webservers -m template -a <spanclass="s2">"src=/srv/motd.j2 dest=/etc/motd"</span>
<spanclass="nv">$ </span>ansible webservers -m template -a <spanclass="s2">"src=/srv/ntp.j2 dest=/etc/ntp.conf"</span>
</pre></div>
</div>
<p>Ansible variables are used in templates by using the name surrounded
by double curly-braces. Ansible provides some <em>facts</em> about the
system being managed automatically in playbooks or when the setup
module is run manually. If facter or ohai were installed on the
remote machine, variables from those programs can be accessed too,
using the appropriate prefix:</p>
<divclass="highlight-django"><divclass="highlight"><pre><spanclass="x">This is an Ansible variable: </span><spanclass="cp">{{</span><spanclass="nv">favcolor</span><spanclass="cp">}}</span><spanclass="x"></span>
<spanclass="x">This is an Ansible fact: </span><spanclass="cp">{{</span><spanclass="nv">ansible_hostname</span><spanclass="cp">}}</span><spanclass="x"></span>
<spanclass="x">This is a facter fact: </span><spanclass="cp">{{</span><spanclass="nv">facter_hostname</span><spanclass="cp">}}</span><spanclass="x"></span>
<spanclass="x">This is an ohai fact: </span><spanclass="cp">{{</span><spanclass="nv">ohai_foo</span><spanclass="cp">}}</span><spanclass="x"></span>
</pre></div>
</div>
<p>Using the Ansible facts is generally preferred as that way you can avoid a dependency
on ruby. If you want to use facter instead, you will also need rubygem-json because
the facter packages may forget this as a dependency.</p>
<p>If you use playbooks, you can also take advantage of the template module,
which takes this another step further.</p>
<p>The <ttclass="docutils literal"><spanclass="pre">file</span></tt> module allows changing ownership and permissions on files. These
same options can be passed directly to the <ttclass="docutils literal"><spanclass="pre">copy</span></tt> or <ttclass="docutils literal"><spanclass="pre">template</span></tt> modules as well:</p>
<divclass="highlight-bash"><divclass="highlight"><pre><spanclass="nv">$ </span>ansible webservers -m file -a <spanclass="s2">"dest=/srv/foo/a.txt mode=600"</span>
...
...
@@ -393,6 +369,28 @@ the remote nodes will be terminated.</p>
backgrounded. Typically you’ll be backgrounding long-running
shell commands or software upgrades only. <aclass="reference internal"href="playbooks.html"><em>Playbooks</em></a> also support polling, and have
a simplified syntax for this.</p>
</div>
<divclass="section"id="limiting-selected-hosts">
<h2>Limiting Selected Hosts<aclass="headerlink"href="#limiting-selected-hosts"title="Permalink to this headline">¶</a></h2>
<pclass="versionadded">
<spanclass="versionmodified">New in version 0.7.</span></p>
<p>What hosts you select to manage can be additionally constrained by using the ‘–limit’ parameter or
by using ‘batch’ (or ‘range’) selectors.</p>
<p>As mentioned above, patterns can be strung together to select hosts in more than one group:</p>
<divclass="highlight-bash"><divclass="highlight"><pre><spanclass="nv">$ </span>ansible webservers:dbservers -m <spanclass="nb">command</span> -a <spanclass="s2">"/bin/foo xyz"</span>
</pre></div>
</div>
<p>This is an “or” condition. If you want to further constrain the selection, use –limit, which
also works with <ttclass="docutils literal"><spanclass="pre">ansible-playbook</span></tt>:</p>
<divclass="highlight-bash"><divclass="highlight"><pre><spanclass="nv">$ </span>ansible webservers:dbservers -m <spanclass="nb">command</span> -a <spanclass="s2">"/bin/foo xyz"</span> region
</pre></div>
</div>
<p>Now let’s talk about range selection. Suppose you have 1000 servers in group ‘datacenter’, but only want to target one at a time. This is also easy:</p>
<divclass="highlight-bash"><divclass="highlight"><pre><spanclass="nv">$ </span>ansible webservers<spanclass="o">[</span>0-100<spanclass="o">]</span> -m <spanclass="nb">command</span> -a <spanclass="s2">"/bin/foo xyz"</span>
<spanclass="nv">$ </span>ansible webservers<spanclass="o">[</span>101-200<spanclass="o">]</span> -m <spanclass="nb">command</span> -a <spanclass="s2">"/bin/foo xyz"</span>
</pre></div>
</div>
<p>Both of these methods can be used at the same time, and ranges can also be passed to the –limit parameter.</p>