<divclass="highlight-python"><divclass="highlight"><pre><spanclass="k">print</span><spanclass="s">"some status message"</span>
</pre></div>
</div>
<p>Because the output is supposed to be valid JSON. Except that’s not quite true,
but we’ll get to that later.</p>
<divclass="section"id="conventions">
<h3>Conventions<aclass="headerlink"href="#conventions"title="Permalink to this headline">¶</a></h3>
<p>As a reminder from the example code above, here are some basic conventions
and guidelines:</p>
<ulclass="simple">
<li>Include a minimum of dependencies if possible. If there are dependencies, document them at the top of the module file</li>
<li>Modules must be self contained in one file to be auto-transferred by ansible</li>
<li>If packaging modules in an RPM, they only need to be installed on the control machine and should be dropped into /usr/share/ansible. This is entirely optional.</li>
<li>Modules should return JSON or key=value results all on one line. JSON is best if you can do JSON. All return types must be hashes (dictionaries) although they can be nested.</li>
<li>In the event of failure, a key of ‘failed’ should be included, along with a string explanation in ‘msg’. Modules that raise tracebacks (stacktraces) are generally considered ‘poor’ modules, though Ansible can deal with these returns and will automatically convert anything unparseable into a failed result.</li>
<li>Return codes are actually not signficant, but continue on with 0=success and non-zero=failure for reasons of future proofing.</li>
<li>As results from many hosts will be aggregrated at once, modules should return only relevant output. Returning the entire contents of a log file is generally bad form.</li>
</ul>
</div>
<divclass="section"id="shorthand-vs-json">
<h3>Shorthand Vs JSON<aclass="headerlink"href="#shorthand-vs-json"title="Permalink to this headline">¶</a></h3>
<p>To make it easier to write modules in bash and in cases where a JSON
module might not be available, it is acceptable for a module to return
key=value output all on one line, like this. The Ansible parser