<h1>Command Line Examples And Next Steps<aclass="headerlink"href="#command-line-examples-and-next-steps"title="Permalink to this headline">¶</a></h1>
<p>The following examples show how to use <cite>/usr/bin/ansible</cite> for running
ad hoc tasks. Start here.</p>
<p>For configuration management and deployments, you’ll want to pick up on
...
...
@@ -255,19 +256,17 @@ simple scripts. They make the remote system look like you state, and run the com
get it there. This is commonly referred to as ‘idempotence’, and is a core design goal of ansible.
However, we also recognize that running <em>ad hoc</em> commands is equally important, so Ansible easily supports both.</p>
</div>
<divclass="section"id="file-transfer-templating">
<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
optionally use them as template sources.</p>
<divclass="section"id="file-transfer">
<h2>File Transfer<aclass="headerlink"href="#file-transfer"title="Permalink to this headline">¶</a></h2>
<p>Here’s another use case for the <cite>/usr/bin/ansible</cite> command line. Ansible can SCP lots of files to multiple machines in parallel.</p>
<p>To transfer a file directly to many different servers:</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>If you use playbooks, you can also take advantage of the template module,
which takes this another step further.</p>
<p>If you use playbooks, you can also take advantage of the <ttclass="docutils literal"><spanclass="pre">template</span></tt> module,
which takes this another step further. (See module and playbook documentation).</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>
same options can be passed directly to the <ttclass="docutils literal"><spanclass="pre">copy</span></tt>module 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>
</pre></div>
...
...
@@ -280,7 +279,6 @@ same options can be passed directly to the <tt class="docutils literal"><span cl
<divclass="highlight-bash"><divclass="highlight"><pre><spanclass="nv">$ </span>ansible webservers -m file -a <spanclass="s2">"dest=/path/to/c state=absent"</span>
</pre></div>
</div>
<p>The mode, owner, and group arguments can also be used on the copy or template lines.</p>
</div>
<divclass="section"id="managing-packages">
<h2>Managing Packages<aclass="headerlink"href="#managing-packages"title="Permalink to this headline">¶</a></h2>
...
...
@@ -368,10 +366,8 @@ poll for status (<tt class="docutils literal"><span class="pre">-P</span></tt>)
Be sure to use a high enough <ttclass="docutils literal"><spanclass="pre">--forks</span></tt> value if you want to get all of your jobs started
very quickly. After the time limit (in seconds) runs out (<ttclass="docutils literal"><spanclass="pre">-B</span></tt>), the process on
the remote nodes will be terminated.</p>
<p>Any module other than <ttclass="docutils literal"><spanclass="pre">copy</span></tt> or <ttclass="docutils literal"><spanclass="pre">template</span></tt> can be
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>
<p>Typically you’ll be only be backgrounding long-running
shell commands or software upgrades only. Backgrounding the copy module does not do a background file transfer. <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>
...
...
@@ -396,6 +392,12 @@ also works with <tt class="docutils literal"><span class="pre">ansible-playbook<
<p>This will select the first 100, then the second 100, host entries in the webservers group. (It does not matter
what their names or IP addresses are).</p>
<p>Both of these methods can be used at the same time, and ranges can also be passed to the –limit parameter.</p>
</div>
<divclass="section"id="configuration-defaults">
<h2>Configuration & Defaults<aclass="headerlink"href="#configuration-defaults"title="Permalink to this headline">¶</a></h2>
<pclass="versionadded">
<spanclass="versionmodified">New in version 0.7.</span></p>
<p>Ansible has an optional configuration file that can be used to tune settings and also eliminate the need to pass various command line flags. The config file location is controlled by the ANSIBLE_CONFIG environment variable, if set, otherwise ~/ansible.cfg or /etc/ansible/ansible.cfg will be loaded, whichever comes first. For those running from source, a sample configuration file lives in the examples/ directory. The RPM will install configuration into /etc/ansible/ansible.cfg automatically.</p>
@@ -361,7 +361,7 @@ like to access sudo mode, there are also flags to do that:</p>
</pre></div>
</div>
<p>Congratulations. You’ve just contacted your nodes with Ansible. It’s
now time to read some of the more real-world <aclass="reference internal"href="examples.html"><em>Command Line</em></a>, and explore
now time to read some of the more real-world <aclass="reference internal"href="examples.html"><em>Command Line Examples And Next Steps</em></a>, and explore
what you can do with different modules, as well as the Ansible
<aclass="reference internal"href="playbooks.html"><em>Playbooks</em></a> language. Ansible is not just about running commands, it
also has powerful configuration management and deployment features. There’s more to
...
...
@@ -369,7 +369,7 @@ explore, but you already have a fully working infrastructure!</p>
@@ -218,7 +218,7 @@ after the hostname with a colon.</p>
</div>
<divclass="section"id="selecting-targets">
<h2>Selecting Targets<aclass="headerlink"href="#selecting-targets"title="Permalink to this headline">¶</a></h2>
<p>We’ll go over how to use the command line in <aclass="reference internal"href="examples.html"><em>Command Line</em></a> section, however, basically it looks like this:</p>
<p>We’ll go over how to use the command line in <aclass="reference internal"href="examples.html"><em>Command Line Examples And Next Steps</em></a> section, however, basically it looks like this:</p>
<divclass="highlight-python"><pre>ansible <pattern_goes_here> -m <module_name> -a <arguments></pre>
</div>
<p>Such as:</p>
...
...
@@ -253,7 +253,7 @@ wildcards:</p>
<p>It’s also ok to mix wildcard patterns and groups at the same time:</p>
<p>Easy enough. See <aclass="reference internal"href="examples.html"><em>Command Line</em></a> and then <aclass="reference internal"href="playbooks.html"><em>Playbooks</em></a> for how to do things to selected hosts.</p>
<p>Easy enough. See <aclass="reference internal"href="examples.html"><em>Command Line Examples And Next Steps</em></a> and then <aclass="reference internal"href="playbooks.html"><em>Playbooks</em></a> for how to do things to selected hosts.</p>
</div>
<divclass="section"id="host-variables">
<h2>Host Variables<aclass="headerlink"href="#host-variables"title="Permalink to this headline">¶</a></h2>
...
...
@@ -351,7 +351,7 @@ Ansible 0.7. Ansible 0.6 includes a <a class="reference external" href="https:/
<h1>Playbooks<aclass="headerlink"href="#playbooks"title="Permalink to this headline">¶</a></h1>
<p>Playbooks are a completely different way to use ansible than in task execution mode, and are
particularly awesome. Simply put, playbooks are the basis for a really simple
particularly powerful. Simply put, playbooks are the basis for a really simple
configuration management and multi-machine deployment system,
unlike any that already exist, and one that is very well suited to deploying complex applications.</p>
<p>Playbooks can declare configurations, but they can also orchestrate steps of
...
...
@@ -295,7 +295,7 @@ parameters.</p>
<divclass="highlight-python"><pre>$varname or ${varname}</pre>
</div>
<p>The later is useful in the event you need to do something like ${other}_some_string.</p>
<p>The full power of the <aclass="reference external"href="http://jinja.pocoo.org/docs/">Jinja2</a> templating language is also available, which looks like this:</p>
<p>Inside templates, the full power of the <aclass="reference external"href="http://jinja.pocoo.org/docs/">Jinja2</a> templating language is also available, which looks like this:</p>
@@ -81,23 +81,20 @@ get it there. This is commonly referred to as 'idempotence', and is a core desi
However, we also recognize that running *ad hoc* commands is equally important, so Ansible easily supports both.
File Transfer & Templating
``````````````````````````
File Transfer
`````````````
Here's another use case for the `/usr/bin/ansible` command line.
Ansible can SCP lots of files to multiple machines in parallel, and
optionally use them as template sources.
Here's another use case for the `/usr/bin/ansible` command line. Ansible can SCP lots of files to multiple machines in parallel.
To transfer a file directly to many different servers::
$ ansible atlanta -m copy -a "src=/etc/hosts dest=/tmp/hosts"
If you use playbooks, you can also take advantage of the template module,
which takes this another step further.
If you use playbooks, you can also take advantage of the ``template`` module,
which takes this another step further. (See module and playbook documentation).
The ``file`` module allows changing ownership and permissions on files. These
same options can be passed directly to the ``copy`` or ``template`` modules as well::
same options can be passed directly to the ``copy`` module as well::
$ ansible webservers -m file -a "dest=/srv/foo/a.txt mode=600"
$ ansible webservers -m file -a "dest=/srv/foo/b.txt mode=600 owner=mdehaan group=mdehaan"
...
...
@@ -110,8 +107,6 @@ As well as delete directories (recursively) and delete files::
$ ansible webservers -m file -a "dest=/path/to/c state=absent"
The mode, owner, and group arguments can also be used on the copy or template lines.
Managing Packages
`````````````````
...
...
@@ -206,10 +201,8 @@ Be sure to use a high enough ``--forks`` value if you want to get all of your jo
very quickly. After the time limit (in seconds) runs out (``-B``), the process on
the remote nodes will be terminated.
Any module other than ``copy`` or ``template`` can be
backgrounded. Typically you'll be backgrounding long-running
shell commands or software upgrades only. :doc:`playbooks` also support polling, and have
a simplified syntax for this.
Typically you'll be only be backgrounding long-running
shell commands or software upgrades only. Backgrounding the copy module does not do a background file transfer. :doc:`playbooks` also support polling, and have a simplified syntax for this.
Limiting Selected Hosts
```````````````````````
...
...
@@ -221,7 +214,7 @@ by using 'batch' (or 'range') selectors.
As mentioned above, patterns can be strung together to select hosts in more than one group::
$ ansible webservers:dbservers -m command -a "/bin/foo xyz"
$ ansible webservers:dbservers -m command -a "/bin/foo xyz"
This is an "or" condition. If you want to further constrain the selection, use --limit, which
also works with ``ansible-playbook``::
...
...
@@ -236,8 +229,14 @@ Now let's talk about range selection. Suppose you have 1000 servers in group '
This will select the first 100, then the second 100, host entries in the webservers group. (It does not matter
what their names or IP addresses are).
Both of these methods can be used at the same time, and ranges can also be passed to the --limit parameter.
Both of these methods can be used at the same time, and ranges can also be passed to the --limit parameter.
Configuration & Defaults
````````````````````````
.. versionadded:: 0.7
Ansible has an optional configuration file that can be used to tune settings and also eliminate the need to pass various command line flags. The config file location is controlled by the ANSIBLE_CONFIG environment variable, if set, otherwise ~/ansible.cfg or /etc/ansible/ansible.cfg will be loaded, whichever comes first. For those running from source, a sample configuration file lives in the examples/ directory. The RPM will install configuration into /etc/ansible/ansible.cfg automatically.