<ahref="http://github.com/ansible/ansible"><imgstyle="position: absolute; right: 0; border: 0;"src="http://ansible.github.com/github.png"alt="Fork me on GitHub"></a>
<p>If you don’t want to use ssh-agent and want to instead SSH with a
password instead of keys, you can with <ttclass="docutils literal"><spanclass="pre">--ask-pass</span></tt> (<ttclass="docutils literal"><spanclass="pre">-k</span></tt>), but
it’s much better to just use ssh-agent.</p>
<p>Now to run the command on all servers in a group, in this case,
<em>atlanta</em>, in 10 parallel forks:</p>
<divclass="highlight-bash"><divclass="highlight"><pre><spanclass="nv">$ </span>ansible atlanta -a <spanclass="s2">"/sbin/reboot"</span> -f 10
<divclass="highlight-bash"><divclass="highlight"><pre><spanclass="nv">$ </span>ansible atlanta -a <spanclass="s2">"/usr/bin/foo"</span> -u yourname
<divclass="highlight-bash"><divclass="highlight"><pre><spanclass="nv">$ </span>ansible atlanta -a <spanclass="s2">"/usr/bin/foo"</span> -u yourname --sudo <spanclass="o">[</span>--ask-sudo-pass<spanclass="o">]</span>
<p>Use <ttclass="docutils literal"><spanclass="pre">--ask-sudo-pass</span></tt> (<ttclass="docutils literal"><spanclass="pre">-K</span></tt>) if you are not using passwordless
sudo. This will interactively prompt you for the password to use.
Use of passwordless sudo makes things easier to automate, but it’s not
required.</p>
<p>It is also possible to sudo to a user other than root using
<divclass="highlight-bash"><divclass="highlight"><pre><spanclass="nv">$ </span>ansible atlanta -a <spanclass="s2">"/usr/bin/foo"</span> -u yourname -U otheruser <spanclass="o">[</span>--ask-sudo-pass<spanclass="o">]</span>
<p>Ok, so those are basics. If you didn’t read about patterns and groups yet, go back and read <aclass="reference internal"href="patterns.html"><em>Inventory & Patterns</em></a>.</p>
<divclass="highlight-bash"><divclass="highlight"><pre><spanclass="nv">$ </span>ansible atlanta -m copy -a <spanclass="s2">"src=/etc/hosts dest=/tmp/hosts"</span>
<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>
<spanclass="nv">$ </span>ansible webservers -m file -a <spanclass="s2">"dest=/srv/foo/b.txt mode=600 owner=mdehaan group=mdehaan"</span>
<p>The <ttclass="docutils literal"><spanclass="pre">file</span></tt> module can also create directories, similar to <ttclass="docutils literal"><spanclass="pre">mkdir</span><spanclass="pre">-p</span></tt>:</p>
<p>The <aclass="reference internal"href="modules.html#user"><em>user</em></a> module allows easy creation and manipulation of
existing user accounts, as well as removal of user accounts that may
exist:</p>
<divclass="highlight-bash"><divclass="highlight"><pre><spanclass="nv">$ </span>ansible all -m user -a <spanclass="s2">"name=foo password=<crypted password here>"</span>
<divclass="highlight-bash"><divclass="highlight"><pre><spanclass="nv">$ </span>ansible webservers -m service -a <spanclass="s2">"name=httpd state=started"</span>
<divclass="highlight-bash"><divclass="highlight"><pre><spanclass="nv">$ </span>ansible webservers -m service -a <spanclass="s2">"name=httpd state=restarted"</span>
<divclass="highlight-bash"><divclass="highlight"><pre><spanclass="nv">$ </span>ansible webservers -m service -a <spanclass="s2">"name=httpd state=stopped"</span>
<divclass="highlight-bash"><divclass="highlight"><pre><spanclass="nv">$ </span>ansible all -B 3600 -a <spanclass="s2">"/usr/bin/long_running_operation --do-stuff"</span>
<divclass="highlight-bash"><divclass="highlight"><pre><spanclass="nv">$ </span>ansible all -m async_status -a <spanclass="s2">"jid=123456789"</span>
<divclass="highlight-bash"><divclass="highlight"><pre><spanclass="nv">$ </span>ansible all -B 1800 -P 60 -a <spanclass="s2">"/usr/bin/long_running_operation --do-stuff"</span>
<p>Any module other than <ttclass="docutils literal"><spanclass="pre">copy</span></tt> or <ttclass="docutils literal"><spanclass="pre">template</span></tt> can be
<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>
<inputtype="image"src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif"border="0"name="submit"alt="PayPal - The safer, easier way to pay online!">