<h2>Bundling Ansible Modules With Playbooks<aclass="headerlink"href="#bundling-ansible-modules-with-playbooks"title="Permalink to this headline">¶</a></h2>
<p>In version 0.5 and later, if a playbook has a ”./library” directory relative to it’s YAML file, this directory can be used to add ansible modules that will automatically be in the ansible module path. This is a great way to keep modules that
go with a playbook together.</p>
</div>
<divclass="section"id="miscellaneous-tips">
<divclass="section"id="miscellaneous-tips">
<h2>Miscellaneous Tips<aclass="headerlink"href="#miscellaneous-tips"title="Permalink to this headline">¶</a></h2>
<h2>Miscellaneous Tips<aclass="headerlink"href="#miscellaneous-tips"title="Permalink to this headline">¶</a></h2>
<p>When you can do something simply, do something simply. Do not reach to use every feature of Ansible together, all
<p>When you can do something simply, do something simply. Do not reach to use every feature of Ansible together, all
...
@@ -289,7 +297,7 @@ This way you have an audit trail describing when and why you changed the rules a
...
@@ -289,7 +297,7 @@ This way you have an audit trail describing when and why you changed the rules a
<h3>Are transports other than SSH supported?<aclass="headerlink"href="#are-transports-other-than-ssh-supported"title="Permalink to this headline">¶</a></h3>
<h3>Are transports other than SSH supported?<aclass="headerlink"href="#are-transports-other-than-ssh-supported"title="Permalink to this headline">¶</a></h3>
<p>Currently SSH and local connections are supported. In 0.5, we’ll also be including
<p>Currently SSH (you can choose between paramiko or the openssh binaries)
a faster SSH transport. The interface is actually pluggable so a
and local connections are supported. The interface is actually pluggable so a
small patch could bring transport over message bus or XMPP as an option.</p>
small patch could bring transport over message bus or XMPP as an option.</p>
<p>Stop by the mailing list if you have ideas. The connection-specific parts of Ansible
<p>Stop by the mailing list if you have ideas. The connection-specific parts of Ansible
are all abstracted away from the core implementation so it is very easy to extend.</p>
are all abstracted away from the core implementation so it is very easy to extend.</p>
...
@@ -386,7 +388,7 @@ tasks – whether for a QA sytem, build system, or anything you can think of
...
@@ -386,7 +388,7 @@ tasks – whether for a QA sytem, build system, or anything you can think of
<p>NOTE: Ansible 0.4 will have ways to remote bootstrap this, using Ansible itself. Stay tuned.</p>
<p>(Note that even that’s not quite true. Ansible’s “raw” module (for executing commands in a quick and dirty way) and the copy module – some of the most basic features in ansible don’t even need that. So technically, you can use Ansible to install python-simplejson using the raw module, which then allows you to use everything else. That’s jumping ahead though.)</p>
<h2>Python 2.6 EPEL instructions for RHEL and CentOS 5<aclass="headerlink"href="#python-2-6-epel-instructions-for-rhel-and-centos-5"title="Permalink to this headline">¶</a></h2>
<h2>Python 2.6 EPEL instructions for RHEL and CentOS 5<aclass="headerlink"href="#python-2-6-epel-instructions-for-rhel-and-centos-5"title="Permalink to this headline">¶</a></h2>
<h2>Choosing Between Paramiko and Native SSH<aclass="headerlink"href="#choosing-between-paramiko-and-native-ssh"title="Permalink to this headline">¶</a></h2>
<p>By default, ansible uses paramiko to talk to managed nodes over SSH. Paramiko is fast, works
very transparently, requires no configuration, and is a good choice for most users.
However, it does not support some advanced SSH features that folks will want to use.</p>
<p>Starting in version 0.5, if you want to leverage more advanced SSH features (such as Kerberized SSH or jump hosts),
pass the flag “–connection=ssh” to any ansible command, or set the
ANSIBLE_TRANSPORT environment variable to ‘ssh’. This will cause Ansible to use openssh
tools instead.</p>
<p>If ANSIBLE_SSH_ARGS are not set, ansible will try to use some sensible ControlMaster options
by default. You are free to override this environment variable, but should still pass ControlMaster
options to ensure performance of this transport. With ControlMaster in use, both transports
are roughly the same speed. Without CM, the binary ssh transport is signficantly slower.</p>
<p>If none of this makes sense to you, the default paramiko option is probably fine.</p>
</div>
<divclass="section"id="your-first-commands">
<divclass="section"id="your-first-commands">
<h2>Your first commands<aclass="headerlink"href="#your-first-commands"title="Permalink to this headline">¶</a></h2>
<h2>Your first commands<aclass="headerlink"href="#your-first-commands"title="Permalink to this headline">¶</a></h2>
<p>Now that you’ve installed Ansible, it’s time to test it.</p>
<p>Now that you’ve installed Ansible, it’s time to test it.</p>
...
@@ -306,9 +322,21 @@ bserver.example.org</pre>
...
@@ -306,9 +322,21 @@ bserver.example.org</pre>
<divclass="highlight-python"><pre>ssh-agent bash
<divclass="highlight-python"><pre>ssh-agent bash
ssh-add ~/.ssh/id_rsa</pre>
ssh-add ~/.ssh/id_rsa</pre>
</div>
</div>
<p>(Depending on your setup, you may wish to ansible’s –private-key-file option to specify a pem file instead)</p>
<p>Now ping all your nodes:</p>
<p>Now ping all your nodes:</p>
<divclass="highlight-python"><pre>ansible all -m ping</pre>
<divclass="highlight-python"><pre>ansible all -m ping</pre>
</div>
</div>
<p>If you want to access machines remotely as a different user than root, you will want to
specify the ‘-u’ option to ansible. If you would like to access sudo mode, there are also flags to do that:</p>
<divclass="highlight-python"><pre># as bruce
ansible all -m ping -u bruce
# as bruce, sudoing to root
ansible all -m ping -u bruce --sudo
# as bruce, sudoing to batman
ansible all -m ping -u bruce --sudo --sudo-user batman</pre>
</div>
<p>Now run a live command on all of your nodes:</p>
<p>Now run a live command on all of your nodes:</p>
<divclass="highlight-python"><pre>ansible all -a "/bin/echo hello"</pre>
<divclass="highlight-python"><pre>ansible all -a "/bin/echo hello"</pre>
</div>
</div>
...
@@ -349,7 +377,7 @@ explore, but you already have a fully working infrastructure!</p>
...
@@ -349,7 +377,7 @@ explore, but you already have a fully working infrastructure!</p>
<liclass="toctree-l2"><aclass="reference internal"href="gettingstarted.html#choosing-between-paramiko-and-native-ssh">Choosing Between Paramiko and Native SSH</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="gettingstarted.html#your-first-commands">Your first commands</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="gettingstarted.html#your-first-commands">Your first commands</a></li>
<li><aclass="reference internal"href="#running-operations-on-change">Running Operations On Change</a></li>
<li><aclass="reference internal"href="#running-operations-on-change">Running Operations On Change</a></li>
<li><aclass="reference internal"href="#include-files-and-reuse">Include Files And Reuse</a></li>
<li><aclass="reference internal"href="#include-files-and-reuse">Include Files And Reuse</a></li>
<li><aclass="reference internal"href="#executing-a-playbook">Executing A Playbook</a></li>
<li><aclass="reference internal"href="#executing-a-playbook">Executing A Playbook</a></li>
<li><aclass="reference internal"href="#tips-and-tricks">Tips and Tricks</a></li>
</ul>
</ul>
</li>
</li>
</ul>
</ul>
...
@@ -271,7 +272,7 @@ Just <cite>Control-C</cite> to kill it and run it again with <cite>-K</cite>.</p
...
@@ -271,7 +272,7 @@ Just <cite>Control-C</cite> to kill it and run it again with <cite>-K</cite>.</p
<divclass="highlight-python"><pre>$varname or ${varname}</pre>
<divclass="highlight-python"><pre>$varname or ${varname}</pre>
</div>
</div>
<p>The later is useful in the event you need to do something like ${other}_concatenated_value.</p>
<p>The later is useful in the event you need to do something like ${other}_concatenated_value.</p>
<p>In templates, the full power of the Jinja2 templating language is also available, which looks like this:</p>
<p>The full power of the Jinja2 templating language is also available (note: in 0.4, this is only true inside of templates), which looks like this:</p>
@@ -222,13 +222,20 @@ want to reference data from must be included in either the current play or any p
...
@@ -222,13 +222,20 @@ want to reference data from must be included in either the current play or any p
<divclass="section"id="magic-variables">
<divclass="section"id="magic-variables">
<h2>Magic Variables<aclass="headerlink"href="#magic-variables"title="Permalink to this headline">¶</a></h2>
<h2>Magic Variables<aclass="headerlink"href="#magic-variables"title="Permalink to this headline">¶</a></h2>
<p>Some variables made available to hosts don’t come from definitions in a playbook, the inventory file, or discovery from the system. There are only two of these, and are used in special cases that many users won’t need.</p>
<p>Some variables made available to hosts don’t come from definitions in a playbook, the inventory file, or discovery from the system. There are only two of these, and are used in special cases that many users won’t need.</p>
<p><cite>groups</cite> is a list (array) of all the groups the current host is in. This can be used in templates using Jinja2
<p><em>group_names</em> is a list (array) of all the groups the current host is in. This can be used in templates using Jinja2
syntax to make template source files that vary based on the group membership (or role) of the host:</p>
syntax to make template source files that vary based on the group membership (or role) of the host:</p>
<divclass="highlight-python"><pre>{% if 'webserver' in groups %}
<divclass="highlight-python"><pre>{% if 'webserver' in group_names %}
# some part of a configuration file that only applies to webservers
# some part of a configuration file that only applies to webservers
{% endif %}</pre>
{% endif %}</pre>
</div>
</div>
<p><cite>inventory_hostname</cite> is the name of the hostname as configured in Ansible’s inventory host file. This can
<p><em>groups</em> is a list of all the groups (and hosts) in the inventory. This can be used to enumerate all hosts within a group.
For example:</p>
<divclass="highlight-python"><pre>{% for host in groups['app_servers'] %}
# something that applies to all app servers.
{% endfor %}</pre>
</div>
<p>Use cases include pointing a frontend proxy server to all of the app servers, setting up the correct firewall rules between servers, etc.</p>
<p><em>inventory_hostname</em> is the name of the hostname as configured in Ansible’s inventory host file. This can
be useful for when you don’t want to rely on the discovered hostname <cite>ansible_hostname</cite> or for other mysterious
be useful for when you don’t want to rely on the discovered hostname <cite>ansible_hostname</cite> or for other mysterious
reasons. Don’t worry about it unless you think you need it.</p>
reasons. Don’t worry about it unless you think you need it.</p>
</div>
</div>
...
@@ -501,7 +508,7 @@ logs from ansible-pull runs would be an excellent way to gather and analyze remo
...
@@ -501,7 +508,7 @@ logs from ansible-pull runs would be an excellent way to gather and analyze remo