<liclass="toctree-l2"><aclass="reference internal"href="#input-from-stdin">15.13. Input from stdin</a><ul>
<liclass="toctree-l3"><aclass="reference internal"href="#stdin-inside-a-loop">15.13.1. Stdin inside a loop</a></li>
</ul>
</li>
<liclass="toctree-l2"><aclass="reference internal"href="#writing-the-manifest">15.14. Writing the manifest</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="#singleton-one-instance-only">15.15. Singleton - one instance only</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="#install-type-with-install-command">15.16. Install - type with install command</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="#nonparallel-only-one-instance-can-be-run-at-a-time">15.17. Nonparallel - only one instance can be run at a time</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="#the-type-explorers">15.18. The type explorers</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="#writing-the-gencode-script">15.19. Writing the gencode script</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="#variable-access-from-the-generated-scripts">15.20. Variable access from the generated scripts</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="#hints-for-typewriters">15.24. Hints for typewriters</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="#how-to-include-a-type-into-upstream-cdist">15.25. How to include a type into upstream cdist</a></li>
<h2><spanclass="section-number">15.3. </span>How to use a type<aclass="headerlink"href="#how-to-use-a-type"title="Permalink to this heading">¶</a></h2>
<p>You can use types from the initial manifest or the type manifest like a
<h2><spanclass="section-number">15.5. </span>Config types<aclass="headerlink"href="#config-types"title="Permalink to this heading">¶</a></h2>
<p>By default types are used with config command. These are types that are not
flagged by any known command flag. If a type is marked then it will be skipped
with config command.</p>
</section>
<sectionid="install-types">
<h2><spanclass="section-number">15.6. </span>Install types<aclass="headerlink"href="#install-types"title="Permalink to this heading">¶</a></h2>
<p>If a type is flagged with 'install' flag then it is used only with install command.
With other commands, i.e. config, these types are skipped if used.</p>
</section>
<sectionid="nonparallel-types">
<h2><spanclass="section-number">15.7. </span>Nonparallel types<aclass="headerlink"href="#nonparallel-types"title="Permalink to this heading">¶</a></h2>
<p>If a type is flagged with 'nonparallel' flag then its objects cannot be run in parallel
when using -j option. Example of such a type is __package_dpkg type where dpkg itself
prevents to be run in more than one instance.</p>
</section>
<sectionid="deprecated-types">
<h2><spanclass="section-number">15.8. </span>Deprecated types<aclass="headerlink"href="#deprecated-types"title="Permalink to this heading">¶</a></h2>
<p>If a type is flagged with 'deprecated' marker then it is considered deprecated.
When it is used cdist writes warning line. If 'deprecated' marker has content
then this content is printed as a deprecation messages, e.g.:</p>
<h2><spanclass="section-number">15.9. </span>How to write a new type<aclass="headerlink"href="#how-to-write-a-new-type"title="Permalink to this heading">¶</a></h2>
<p>A type consists of</p>
<ulclass="simple">
<li><p>parameter (optional)</p></li>
<li><p>manifest (optional)</p></li>
<li><p>singleton (optional)</p></li>
<li><p>explorer (optional)</p></li>
<li><p>gencode (optional)</p></li>
<li><p>nonparallel (optional)</p></li>
</ul>
<p>Types are stored below cdist/conf/type/. Their name should always be prefixed with
two underscores (__) to prevent collisions with other executables in $PATH.</p>
<p>To implement a new type, create the directory <strong>cdist/conf/type/__NAME</strong>.</p>
<p>Type manifest and gencode can be written in any language. They just need to be
executable and have a proper shebang. If they are not executable then cdist assumes
they are written in shell so they are executed using '/bin/sh -e' or 'CDIST_LOCAL_SHELL'.</p>
<p>For executable shell code it is suggested that shebang is '#!/bin/sh -e'.</p>
<p>For creating type skeleton you can use helper script
<h2><spanclass="section-number">15.10. </span>Defining parameters<aclass="headerlink"href="#defining-parameters"title="Permalink to this heading">¶</a></h2>
<p>Every type consists of required, optional and boolean parameters, which must
each be declared in a newline separated file in <strong>parameter/required</strong>,
<h2><spanclass="section-number">15.12. </span>Deprecated parameters<aclass="headerlink"href="#deprecated-parameters"title="Permalink to this heading">¶</a></h2>
<p>To deprecate type parameters one can declare a file for each deprecated
parameter under <strong>parameter/deprecated</strong> directory.</p>
<p>When such parameter is used cdist writes warning line with deprecation message.
If such file has content then this content is printed as deprecation message.
If there is no content then generic parameter deprecation message is printed.</p>
<h3><spanclass="section-number">15.13.1. </span>Stdin inside a loop<aclass="headerlink"href="#stdin-inside-a-loop"title="Permalink to this heading">¶</a></h3>
<p>Since cdist saves type's stdin content in the object as <strong>$__object/stdin</strong>,
so it can be accessed in manifest and gencode-* scripts, this can lead to
unexpected behavior. For example, suppose you have some type with the following
<h2><spanclass="section-number">15.14. </span>Writing the manifest<aclass="headerlink"href="#writing-the-manifest"title="Permalink to this heading">¶</a></h2>
<p>In the manifest of a type you can use other types, so your type extends
their functionality. A good example is the __package type, which in
<spanclass="w"></span><spanclass="nb">echo</span><spanclass="w"></span><spanclass="s2">"Don't know how to manage packages on: </span><spanclass="nv">$os</span><spanclass="s2">"</span><spanclass="w"></span>><spanclass="p">&</span><spanclass="m">2</span>
<p>As you can see, the type can reference different environment variables,
which are documented in <aclass="reference external"href="cdist-reference.html">cdist reference</a>.</p>
<p>Always ensure the manifest is executable, otherwise cdist will not be able
to execute it. For more information about manifests see <aclass="reference external"href="cdist-manifest.html">cdist manifest</a>.</p>
</section>
<sectionid="singleton-one-instance-only">
<h2><spanclass="section-number">15.15. </span>Singleton - one instance only<aclass="headerlink"href="#singleton-one-instance-only"title="Permalink to this heading">¶</a></h2>
<p>If you want to ensure that a type can only be used once per target, you can
mark it as a singleton: Just create the (empty) file "singleton" in your type
<p>As you can see, the object ID is omitted, because it does not make any sense,
if your type can be used only once.</p>
</section>
<sectionid="install-type-with-install-command">
<h2><spanclass="section-number">15.16. </span>Install - type with install command<aclass="headerlink"href="#install-type-with-install-command"title="Permalink to this heading">¶</a></h2>
<p>If you want a type to be used with install command, you must mark it as
install: create the (empty) file "install" in your type directory:</p>
<h2><spanclass="section-number">15.17. </span>Nonparallel - only one instance can be run at a time<aclass="headerlink"href="#nonparallel-only-one-instance-can-be-run-at-a-time"title="Permalink to this heading">¶</a></h2>
<p>If objects of a type must not or cannot be run in parallel when using -j
option, you must mark it as nonparallel: create the (empty) file "nonparallel"
<p>For example, package types are nonparallel types.</p>
</section>
<sectionid="the-type-explorers">
<h2><spanclass="section-number">15.18. </span>The type explorers<aclass="headerlink"href="#the-type-explorers"title="Permalink to this heading">¶</a></h2>
<p>If a type needs to explore specific details, it can provide type specific
explorers, which will be executed on the target for every created object.</p>
<p>The explorers are stored under the "explorer" directory below the type.
It could for instance contain code to check the md5sum of a file on the
client, like this (shortened version from the type __file):</p>
<h2><spanclass="section-number">15.19. </span>Writing the gencode script<aclass="headerlink"href="#writing-the-gencode-script"title="Permalink to this heading">¶</a></h2>
<p>There are two gencode scripts: <strong>gencode-local</strong> and <strong>gencode-remote</strong>.
The output of gencode-local is executed locally, whereas
the output of gencode-remote is executed on the target.
The gencode scripts can make use of the parameters, the global explorers
and the type specific explorers.</p>
<p>If the gencode scripts encounters an error, it should print diagnostic
messages to stderr and exit non-zero. If you need to debug the gencode
script, you can write to stderr:</p>
<divclass="highlight-sh notranslate"><divclass="highlight"><pre><span></span><spanclass="c1"># Debug output to stderr</span>
<h2><spanclass="section-number">15.20. </span>Variable access from the generated scripts<aclass="headerlink"href="#variable-access-from-the-generated-scripts"title="Permalink to this heading">¶</a></h2>
<p>In the generated scripts, you have access to the following cdist variables</p>
<ulclass="simple">
<li><p>__object</p></li>
<li><p>__object_id</p></li>
</ul>
<p>but only for read operations, means there is no back copy of this
files after the script execution.</p>
<p>So when you generate a script with the following content, it will work:</p>
<h2><spanclass="section-number">15.21. </span>Environment variable usage idiom<aclass="headerlink"href="#environment-variable-usage-idiom"title="Permalink to this heading">¶</a></h2>
<p>In type scripts you can support environment variables with default values if
environment variable is unset or null by using <strong>${parameter:-[word]}</strong>
parameter expansion.</p>
<p>Example using mktemp in a portable way that supports TMPDIR environment variable.</p>
<h2><spanclass="section-number">15.22. </span>Log level in types<aclass="headerlink"href="#log-level-in-types"title="Permalink to this heading">¶</a></h2>
<p>cdist log level can be accessed from __cdist_log_level variable.One of:</p>
<p>It is available for initial manifest, explorer, type manifest,
type explorer, type gencode.</p>
</section>
<sectionid="detecting-dry-run">
<h2><spanclass="section-number">15.23. </span>Detecting dry run<aclass="headerlink"href="#detecting-dry-run"title="Permalink to this heading">¶</a></h2>
<p>If <codeclass="docutils literal notranslate"><spanclass="pre">$__cdist_dry_run</span></code> environment variable is set, then it's dry run.</p>
<p>It is available for initial manifest, explorer, type manifest,
type explorer, type gencode.</p>
</section>
<sectionid="hints-for-typewriters">
<h2><spanclass="section-number">15.24. </span>Hints for typewriters<aclass="headerlink"href="#hints-for-typewriters"title="Permalink to this heading">¶</a></h2>
<p>It must be assumed that the target is pretty dumb and thus does not have high
level tools like ruby installed. If a type requires specific tools to be present
on the target, there must be another type that provides this tool and the first
type should create an object of the specific type.</p>
<p>If your type wants to save temporary data, that may be used by other types
later on (for instance __file), you can save them in the subdirectory
"files" below $__object (but you must create it yourself).
cdist will not touch this directory.</p>
<p>If your type contains static files, it's also recommended to place them in
a folder named "files" within the type (again, because cdist guarantees to
<h2><spanclass="section-number">15.25. </span>How to include a type into upstream cdist<aclass="headerlink"href="#how-to-include-a-type-into-upstream-cdist"title="Permalink to this heading">¶</a></h2>
<p>If you think your type may be useful for others, ensure it works with the
current master branch of cdist and have a look at <aclass="reference external"href="cdist-hacker.html">cdist hacking</a> on