<h2>Parallelism and Shell Commands<aclass="headerlink"href="#parallelism-and-shell-commands"title="Permalink to this headline">¶</a></h2>
<h2>Parallelism and Shell Commands<aclass="headerlink"href="#parallelism-and-shell-commands"title="Permalink to this headline">¶</a></h2>
<p>Let’s use ansible’s command line tool to reboot all web servers in Atlanta, 10 at a time:</p>
<p>Let’s use ansible’s command line tool to reboot all web servers in Atlanta, 10 at a time. First, let’s
set up SSH-agent so it can remember our credentials:</p>
<divclass="highlight-python"><pre>ssh-agent bash
<divclass="highlight-python"><pre>ssh-agent bash
ssh-add ~/.ssh/id_rsa.pub
ssh-add ~/.ssh/id_rsa.pub</pre>
</div>
ansible atlanta -a "/sbin/reboot" -f 10</pre>
<p>Now to run the command on all servers in a group, in this case, ‘atlanta’:</p>
</div>
<divclass="highlight-python"><pre>ansible atlanta -a "/sbin/reboot" -f 10</pre>
<p>The -f 10 specifies the usage of 10 simultaneous processes.</p>
</div>
<divclass="admonition note">
<p>If you didn’t read about patterns and groups yet, go back and read <aclass="reference internal"href="patterns.html"><em>The Inventory File, Patterns, and Groups</em></a>.</p>
<pclass="first admonition-title">Note</p>
<p>The -f 10 in the above specifies the usage of 10 simultaneous processes. Normally commands also take
<pclass="last">-m does not always have to be specified to /usr/bin/ansible because ‘command’ is the default ansible module</p>
a <cite>-m</cite> for module name, but the default module name is ‘command’, so we didn’t need to specify that
</div>
here. We’ll use <cite>-m</cite> later to run some other <aclass="reference internal"href="modules.html"><em>Ansible Modules</em></a>.</p>
<p>If we want to execute a module using the shell, we can avoid using absolute paths, and can also include
<p>The command module requires absolute paths and does not support shell variables. If we want to
pipe and redirection operators. Read more about the differences on the <aclass="reference internal"href="modules.html"><em>Ansible Modules</em></a> page. The shell
execute a module using the shell, we can do those things, and also use pipe and redirection operators.
Read more about the differences on the <aclass="reference internal"href="modules.html"><em>Ansible Modules</em></a> page. The shell
module looks like this:</p>
module looks like this:</p>
<divclass="highlight-python"><pre>ansible raleigh -m shell -a "echo \\$TERM"</pre>
<divclass="highlight-python"><pre>ansible raleigh -m shell -a "echo \\$TERM"</pre>
</div>
</div>
<divclass="admonition note">
<p>When running any command with the ansible “ad hoc” CLI (as opposed to playbooks), pay particular attention
<pclass="first admonition-title">Note</p>
to shell quoting rules, so the shell doesn’t eat a variable before it gets passed to Ansible.</p>
<pclass="last">When using ansible to run commands, and in particular the shell module, be careful of shell quoting rules.</p>
<p>So far we’ve been demoing simple command execution, but most ansible modules usually do not work like
</div>
simple scripts. They make the remote system look like you state, and run the commands necessary to
<divclass="admonition note">
get it there. This is commonly referred to as ‘idempotence’, and is a core design goal of ansible.
<pclass="first admonition-title">Note</p>
However, we also recognize that running ad-hoc commands is equally imporant, so Ansible easily supports both.</p>
<pclass="last">Note that other than the command <aclass="reference internal"href="modules.html"><em>Ansible Modules</em></a>, ansible modules usually do
not work like simple scripts. They make the remote system look like
you state, and run the commands necessary to get it there. This
is commonly referred to as ‘idempotence’, and is a core design goal of ansible. However, we also
recognize that running ad-hoc commands is equally imporant, so Ansible easily supports both.</p>
</div>
</div>
</div>
<divclass="section"id="file-transfer-templating">
<divclass="section"id="file-transfer-templating">
<h2>File Transfer & Templating<aclass="headerlink"href="#file-transfer-templating"title="Permalink to this headline">¶</a></h2>
<h2>File Transfer & Templating<aclass="headerlink"href="#file-transfer-templating"title="Permalink to this headline">¶</a></h2>
<p>Here’s another use case for the <cite>/usr/bin/ansible</cite> command line.</p>
<p>Ansible can SCP lots of files to multiple machines in parallel, and
<p>Ansible can SCP lots of files to multiple machines in parallel, and
optionally use them as template sources.</p>
optionally use them as template sources.</p>
<p>To just transfer a file directly to many different servers:</p>
<p>To just transfer a file directly to many different servers:</p>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"/><title>ansible-playbook</title><linkrel="stylesheet"href="./docbook-xsl.css"type="text/css"/><metaname="generator"content="DocBook XSL Stylesheets V1.75.2"/></head><body><divxml:lang="en"class="refentry"title="ansible-playbook"lang="en"><aid="id554898"></a><divclass="titlepage"></div><divclass="refnamediv"><h2>Name</h2><p>ansible-playbook — run an ansible playbook</p></div><divclass="refsynopsisdiv"title="Synopsis"><aid="_synopsis"></a><h2>Synopsis</h2><p>ansible-playbook <filename.yml> … [options]</p></div><divclass="refsect1"title="DESCRIPTION"><aid="_description"></a><h2>DESCRIPTION</h2><p><spanclass="strong"><strong>Ansible playbooks</strong></span> are a configuration and multinode deployment system. Ansible-playbook is the tool
<htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"/><title>ansible-playbook</title><linkrel="stylesheet"href="./docbook-xsl.css"type="text/css"/><metaname="generator"content="DocBook XSL Stylesheets V1.75.2"/></head><body><divxml:lang="en"class="refentry"title="ansible-playbook"lang="en"><aid="id330881"></a><divclass="titlepage"></div><divclass="refnamediv"><h2>Name</h2><p>ansible-playbook — run an ansible playbook</p></div><divclass="refsynopsisdiv"title="Synopsis"><aid="_synopsis"></a><h2>Synopsis</h2><p>ansible-playbook <filename.yml> … [options]</p></div><divclass="refsect1"title="DESCRIPTION"><aid="_description"></a><h2>DESCRIPTION</h2><p><spanclass="strong"><strong>Ansible playbooks</strong></span> are a configuration and multinode deployment system. Ansible-playbook is the tool
used to run them. See the project home page (link below) for more information.</p></div><divclass="refsect1"title="ARGUMENTS"><aid="_arguments"></a><h2>ARGUMENTS</h2><divclass="variablelist"><dl><dt><spanclass="term">
used to run them. See the project home page (link below) for more information.</p></div><divclass="refsect1"title="ARGUMENTS"><aid="_arguments"></a><h2>ARGUMENTS</h2><divclass="variablelist"><dl><dt><spanclass="term">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"/><title>ansible</title><linkrel="stylesheet"href="./docbook-xsl.css"type="text/css"/><metaname="generator"content="DocBook XSL Stylesheets V1.75.2"/></head><body><divxml:lang="en"class="refentry"title="ansible"lang="en"><aid="id575958"></a><divclass="titlepage"></div><divclass="refnamediv"><h2>Name</h2><p>ansible — run a command somewhere else</p></div><divclass="refsynopsisdiv"title="Synopsis"><aid="_synopsis"></a><h2>Synopsis</h2><p>ansible <host-pattern> [-f forks] [-m module_name] [-a args]</p></div><divclass="refsect1"title="DESCRIPTION"><aid="_description"></a><h2>DESCRIPTION</h2><p><spanclass="strong"><strong>Ansible</strong></span> is an extra-simple tool/framework/API for doing 'remote things' over
<htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"/><title>ansible</title><linkrel="stylesheet"href="./docbook-xsl.css"type="text/css"/><metaname="generator"content="DocBook XSL Stylesheets V1.75.2"/></head><body><divxml:lang="en"class="refentry"title="ansible"lang="en"><aid="id372046"></a><divclass="titlepage"></div><divclass="refnamediv"><h2>Name</h2><p>ansible — run a command somewhere else</p></div><divclass="refsynopsisdiv"title="Synopsis"><aid="_synopsis"></a><h2>Synopsis</h2><p>ansible <host-pattern> [-f forks] [-m module_name] [-a args]</p></div><divclass="refsect1"title="DESCRIPTION"><aid="_description"></a><h2>DESCRIPTION</h2><p><spanclass="strong"><strong>Ansible</strong></span> is an extra-simple tool/framework/API for doing 'remote things' over