<p>Here are some tips for making the most of Ansible.</p>
<divclass="section"id="group-by-roles">
<h2>Group By Roles<aclass="headerlink"href="#group-by-roles"title="Permalink to this headline">¶</a></h2>
<p>A system can be in multiple groups. See ref:<cite>patterns</cite>. Having groups named after things like
<p>A system can be in multiple groups. See <aclass="reference internal"href="patterns.html"><em>Inventory & Patterns</em></a>. Having groups named after things like
‘webservers’ and ‘dbservers’ is repeated in the examples because it’s a very powerful concept.</p>
<p>This allows playbooks to target machines based on role, as well as to assign role specific variables
using the group variable system.</p>
...
...
@@ -232,17 +232,17 @@ will require <cite>handlers</cite>, <cite>tasks</cite>, and <cite>templates</cit
</div>
<p>The tasks are individually broken out in ‘acme/tasks/setup.yml’, and handlers, which are common to all task files,
are contained in ‘acme/handlers/main.yml’. As a reminder, handlers are mostly just used to notify services to restart
when things change, and these are described in ref:<cite>playbooks</cite>.</p>
when things change, and these are described in <aclass="reference internal"href="playbooks.html"><em>Playbooks</em></a>.</p>
<p>Including more than one setup file or more than one handlers file is of course legal.</p>
<p>Having playbooks be able to include other playbooks is coming in release 0.5.</p>
<p>Until then, to manage your entire site, simply execute all of your playbooks together, in the order desired.
You don’t have to do this though, it’s fine to select sections of your infrastructure to manage at a single time.
You don’t have to do this though. It’s fine to select sections of your infrastructure to manage at a single time.
You may wish to construct simple shell scripts to wrap calls to ansible-playbook.</p>
</div>
<divclass="section"id="miscellaneous-tips">
<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
at once. Use what works for you. For example, you should probably not need ‘vars’, ‘vars_files’, ‘vars_prompt’ and ‘–extra-vars’ all at once, while also using an external inventory file.</p>
at once. Use what works for you. For example, you should probably not need <ttclass="docutils literal"><spanclass="pre">vars</span></tt>, <ttclass="docutils literal"><spanclass="pre">vars_files</span></tt>, <ttclass="docutils literal"><spanclass="pre">vars_prompt</span></tt> and <ttclass="docutils literal"><spanclass="pre">--extra-vars</span></tt> all at once, while also using an external inventory file.</p>
<p>Optimize for readability. Whitespace between sections of YAML documents and in between tasks is strongly encouraged,
as is usage of YAML comments, which start with “#”. It is also useful to comment at the top of each file the purpose of the individual file and the author, including email address.</p>
<p>It is possible to leave off the “name” for a given task, though it is recommended to provide
...
...
@@ -289,7 +289,7 @@ This way you have an audit trail describing when and why you changed the rules a
<p>You can optionally specify an inventory file (see doc:<cite>patterns</cite>) other than /etc/ansible/hosts:</p>
<p>You can optionally specify an inventory file (see <aclass="reference internal"href="patterns.html"><em>Inventory & Patterns</em></a>) other than /etc/ansible/hosts:</p>
@@ -465,17 +465,18 @@ using the ‘shell’ or ‘command’ module is much more appro
only output is returned. There is no error detection or change handler support
for this module.</p>
<p>Example from <cite>/usr/bin/ansible</cite> to bootstrap a legacy python 2.4 host:</p>
<blockquote>
<div>ansible newhost.example.com raw -a “yum install python-simplejson”</div></blockquote>
<divclass="highlight-python"><pre>ansible newhost.example.com raw -a "yum install python-simplejson"</pre>
</div>
</div>
<divclass="section"id="id9">
<h2>service<aclass="headerlink"href="#id9"title="Permalink to this headline">¶</a></h2>
<p>Controls services on remote machines.</p>
<p><em>state</em>:</p>
<ulclass="simple">
<li>Values are <ttclass="docutils literal"><spanclass="pre">started</span></tt>, <ttclass="docutils literal"><spanclass="pre">stopped</span></tt>, or <ttclass="docutils literal"><spanclass="pre">restarted</span></tt>.
<li>Values are <ttclass="docutils literal"><spanclass="pre">started</span></tt>, <ttclass="docutils literal"><spanclass="pre">stopped</span></tt>, <ttclass="docutils literal"><spanclass="pre">reloaded</span></tt>, or <ttclass="docutils literal"><spanclass="pre">restarted</span></tt>.
Started/stopped are idempotent actions that will not run commands
unless necessary. <ttclass="docutils literal"><spanclass="pre">restarted</span></tt> will always bounce the service.</li>
unless necessary. <ttclass="docutils literal"><spanclass="pre">restarted</span></tt> will always bounce the service, <ttclass="docutils literal"><spanclass="pre">reloaded</span></tt>
will always issue a reload.</li>
</ul>
<p><em>enabled</em>:</p>
<ulclass="simple">
...
...
@@ -493,7 +494,8 @@ Uses chkconfig or updates-rc.d as appropriate.</li>
<p>Example action from Ansible <aclass="reference internal"href="playbooks.html"><em>Playbooks</em></a>:</p>