605 lines
33 KiB
HTML
605 lines
33 KiB
HTML
|
|
||
|
|
||
|
<!DOCTYPE html>
|
||
|
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
|
||
|
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
|
||
|
<head>
|
||
|
<meta charset="utf-8">
|
||
|
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
|
||
|
<title>15. cdist type — cdist 4.11.0 documentation</title>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<script type="text/javascript" src="_static/js/modernizr.min.js"></script>
|
||
|
|
||
|
|
||
|
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
|
||
|
<script type="text/javascript" src="_static/jquery.js"></script>
|
||
|
<script type="text/javascript" src="_static/underscore.js"></script>
|
||
|
<script type="text/javascript" src="_static/doctools.js"></script>
|
||
|
<script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
|
||
|
|
||
|
<script type="text/javascript" src="_static/js/theme.js"></script>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
|
||
|
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||
|
<link rel="index" title="Index" href="genindex.html" />
|
||
|
<link rel="search" title="Search" href="search.html" />
|
||
|
<link rel="next" title="16. cdist types" href="cdist-types.html" />
|
||
|
<link rel="prev" title="14. Manifest" href="cdist-manifest.html" />
|
||
|
</head>
|
||
|
|
||
|
<body class="wy-body-for-nav">
|
||
|
|
||
|
|
||
|
<div class="wy-grid-for-nav">
|
||
|
|
||
|
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
|
||
|
<div class="wy-side-scroll">
|
||
|
<div class="wy-side-nav-search" >
|
||
|
|
||
|
|
||
|
|
||
|
<a href="index.html" class="icon icon-home"> cdist
|
||
|
|
||
|
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<div class="version">
|
||
|
4.11.0
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<div role="search">
|
||
|
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
|
||
|
<input type="text" name="q" placeholder="Search docs" />
|
||
|
<input type="hidden" name="check_keywords" value="yes" />
|
||
|
<input type="hidden" name="area" value="default" />
|
||
|
</form>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
</div>
|
||
|
|
||
|
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<ul class="current">
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-intro.html">1. cdist - usable configuration management</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-why.html">2. Why should I use cdist?</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-os.html">3. Supported Operating Systems</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-install.html">4. How to install cdist</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-update.html">5. How to update cdist</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-support.html">6. Support</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-features.html">7. Features</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-quickstart.html">8. Quickstart</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-real-world.html">9. Dive into real world cdist</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="man1/cdist.html">10. cdist(1)</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="man1/cdist-dump.html">11. cdist-dump(1)</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-bootstrap.html">12. Bootstrap</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-configuration.html">13. Configuration</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-manifest.html">14. Manifest</a></li>
|
||
|
<li class="toctree-l1 current"><a class="current reference internal" href="#">15. cdist type</a><ul>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#description">15.1. Description</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#synopsis">15.2. Synopsis</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#how-to-use-a-type">15.3. How to use a type</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#singleton-types">15.4. Singleton types</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#config-types">15.5. Config types</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#install-types">15.6. Install types</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#nonparallel-types">15.7. Nonparallel types</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#how-to-write-a-new-type">15.8. How to write a new type</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#defining-parameters">15.9. Defining parameters</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#using-parameters">15.10. Using parameters</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#input-from-stdin">15.11. Input from stdin</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#writing-the-manifest">15.12. Writing the manifest</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#singleton-one-instance-only">15.13. Singleton - one instance only</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#install-type-with-install-command">15.14. Install - type with install command</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#nonparallel-only-one-instance-can-be-run-at-a-time">15.15. Nonparallel - only one instance can be run at a time</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#the-type-explorers">15.16. The type explorers</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#writing-the-gencode-script">15.17. Writing the gencode script</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#variable-access-from-the-generated-scripts">15.18. Variable access from the generated scripts</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#environment-variable-usage-idiom">15.19. Environment variable usage idiom</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#log-level-in-types">15.20. Log level in types</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#hints-for-typewriters">15.21. Hints for typewriters</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#how-to-include-a-type-into-upstream-cdist">15.22. How to include a type into upstream cdist</a></li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-types.html">16. cdist types</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-explorer.html">17. Explorer</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-messaging.html">18. Messaging</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-parallelization.html">19. Parallelization</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-inventory.html">20. Inventory</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-integration.html">21. cdist integration / using cdist as library</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-reference.html">22. Reference</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-best-practice.html">23. Best practice</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-stages.html">24. Execution stages</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-cache.html">25. Local cache overview</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-saving-output-streams.html">26. Saving output streams</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-remote-exec-copy.html">27. Remote exec and copy commands</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-hacker.html">28. Hacking</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-troubleshooting.html">29. Troubleshooting</a></li>
|
||
|
</ul>
|
||
|
|
||
|
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
</nav>
|
||
|
|
||
|
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
|
||
|
|
||
|
|
||
|
<nav class="wy-nav-top" aria-label="top navigation">
|
||
|
|
||
|
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
||
|
<a href="index.html">cdist</a>
|
||
|
|
||
|
</nav>
|
||
|
|
||
|
|
||
|
<div class="wy-nav-content">
|
||
|
|
||
|
<div class="rst-content">
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<div role="navigation" aria-label="breadcrumbs navigation">
|
||
|
|
||
|
<ul class="wy-breadcrumbs">
|
||
|
|
||
|
<li><a href="index.html">Docs</a> »</li>
|
||
|
|
||
|
<li>15. cdist type</li>
|
||
|
|
||
|
|
||
|
<li class="wy-breadcrumbs-aside">
|
||
|
|
||
|
|
||
|
<a href="_sources/cdist-type.rst.txt" rel="nofollow"> View page source</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
|
||
|
<hr/>
|
||
|
</div>
|
||
|
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
|
||
|
<div itemprop="articleBody">
|
||
|
|
||
|
<div class="section" id="cdist-type">
|
||
|
<h1>15. cdist type<a class="headerlink" href="#cdist-type" title="Permalink to this headline">¶</a></h1>
|
||
|
<div class="section" id="description">
|
||
|
<h2>15.1. Description<a class="headerlink" href="#description" title="Permalink to this headline">¶</a></h2>
|
||
|
<p>Types are the main component of cdist and define functionality. If you
|
||
|
use cdist, you'll write a type for every functionality you would like
|
||
|
to use.</p>
|
||
|
</div>
|
||
|
<div class="section" id="synopsis">
|
||
|
<h2>15.2. Synopsis<a class="headerlink" href="#synopsis" title="Permalink to this headline">¶</a></h2>
|
||
|
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>__TYPE ID --parameter value <span class="o">[</span>--parameter value ...<span class="o">]</span>
|
||
|
__TYPE --parameter value <span class="o">[</span>--parameter value ...<span class="o">]</span> <span class="o">(</span><span class="k">for</span> singletons<span class="o">)</span>
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="section" id="how-to-use-a-type">
|
||
|
<h2>15.3. How to use a type<a class="headerlink" href="#how-to-use-a-type" title="Permalink to this headline">¶</a></h2>
|
||
|
<p>You can use types from the initial manifest or the type manifest like a
|
||
|
normal shell command:</p>
|
||
|
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="c1"># Creates empty file /etc/cdist-configured</span>
|
||
|
__file /etc/cdist-configured --type file
|
||
|
|
||
|
<span class="c1"># Ensure tree is installed</span>
|
||
|
__package tree --state installed
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
<p>A list of supported types can be found in the <a class="reference external" href="cdist-reference.html">cdist reference</a> manpage.</p>
|
||
|
</div>
|
||
|
<div class="section" id="singleton-types">
|
||
|
<h2>15.4. Singleton types<a class="headerlink" href="#singleton-types" title="Permalink to this headline">¶</a></h2>
|
||
|
<p>If a type is flagged as a singleton, it may be used only
|
||
|
once per host. This is useful for types which can be used only once on a
|
||
|
system. Singleton types do not take an object name as argument.</p>
|
||
|
<p>Example:</p>
|
||
|
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="c1"># __issue type manages /etc/issue</span>
|
||
|
__issue
|
||
|
|
||
|
<span class="c1"># Probably your own type - singletons may use parameters</span>
|
||
|
__myfancysingleton --colour green
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="section" id="config-types">
|
||
|
<h2>15.5. Config types<a class="headerlink" href="#config-types" title="Permalink to this headline">¶</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>
|
||
|
</div>
|
||
|
<div class="section" id="install-types">
|
||
|
<h2>15.6. Install types<a class="headerlink" href="#install-types" title="Permalink to this headline">¶</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>
|
||
|
</div>
|
||
|
<div class="section" id="nonparallel-types">
|
||
|
<h2>15.7. Nonparallel types<a class="headerlink" href="#nonparallel-types" title="Permalink to this headline">¶</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>
|
||
|
</div>
|
||
|
<div class="section" id="how-to-write-a-new-type">
|
||
|
<h2>15.8. How to write a new type<a class="headerlink" href="#how-to-write-a-new-type" title="Permalink to this headline">¶</a></h2>
|
||
|
<p>A type consists of</p>
|
||
|
<ul class="simple">
|
||
|
<li>parameter (optional)</li>
|
||
|
<li>manifest (optional)</li>
|
||
|
<li>singleton (optional)</li>
|
||
|
<li>explorer (optional)</li>
|
||
|
<li>gencode (optional)</li>
|
||
|
<li>nonparallel (optional)</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>
|
||
|
</div>
|
||
|
<div class="section" id="defining-parameters">
|
||
|
<h2>15.9. Defining parameters<a class="headerlink" href="#defining-parameters" title="Permalink to this headline">¶</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>,
|
||
|
<strong>parameter/required_multiple</strong>, <strong>parameter/optional</strong>,
|
||
|
<strong>parameter/optional_multiple</strong> and <strong>parameter/boolean</strong>.
|
||
|
Parameters which are allowed multiple times should be listed in
|
||
|
required_multiple or optional_multiple respectively. All other parameters
|
||
|
follow the standard unix behaviour "the last given wins".
|
||
|
If either is missing, the type will have no required, no optional, no boolean
|
||
|
or no parameters at all.</p>
|
||
|
<p>Default values for optional parameters can be predefined in
|
||
|
<strong>parameter/default/<name></strong>.</p>
|
||
|
<p>Example:</p>
|
||
|
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="nb">echo</span> servername >> cdist/conf/type/__nginx_vhost/parameter/required
|
||
|
<span class="nb">echo</span> logdirectory >> cdist/conf/type/__nginx_vhost/parameter/optional
|
||
|
<span class="nb">echo</span> loglevel >> cdist/conf/type/__nginx_vhost/parameter/optional
|
||
|
mkdir cdist/conf/type/__nginx_vhost/parameter/default
|
||
|
<span class="nb">echo</span> warning > cdist/conf/type/__nginx_vhost/parameter/default/loglevel
|
||
|
<span class="nb">echo</span> server_alias >> cdist/conf/type/__nginx_vhost/parameter/optional_multiple
|
||
|
<span class="nb">echo</span> use_ssl >> cdist/conf/type/__nginx_vhost/parameter/boolean
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="section" id="using-parameters">
|
||
|
<h2>15.10. Using parameters<a class="headerlink" href="#using-parameters" title="Permalink to this headline">¶</a></h2>
|
||
|
<p>The parameters given to a type can be accessed and used in all type scripts
|
||
|
(e.g manifest, gencode, explorer). Note that boolean parameters are
|
||
|
represented by file existence. File exists -> True,
|
||
|
file does not exist -> False</p>
|
||
|
<p>Example: (e.g. in cdist/conf/type/__nginx_vhost/manifest)</p>
|
||
|
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="c1"># required parameter</span>
|
||
|
<span class="nv">servername</span><span class="o">=</span><span class="s2">"</span><span class="k">$(</span>cat <span class="s2">"</span><span class="nv">$__object</span><span class="s2">/parameter/servername"</span><span class="k">)</span><span class="s2">"</span>
|
||
|
|
||
|
<span class="c1"># optional parameter</span>
|
||
|
<span class="k">if</span> <span class="o">[</span> -f <span class="s2">"</span><span class="nv">$__object</span><span class="s2">/parameter/logdirectory"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
|
||
|
<span class="nv">logdirectory</span><span class="o">=</span><span class="s2">"</span><span class="k">$(</span>cat <span class="s2">"</span><span class="nv">$__object</span><span class="s2">/parameter/logdirectory"</span><span class="k">)</span><span class="s2">"</span>
|
||
|
<span class="k">fi</span>
|
||
|
|
||
|
<span class="c1"># optional parameter with predefined default</span>
|
||
|
<span class="nv">loglevel</span><span class="o">=</span><span class="s2">"</span><span class="k">$(</span>cat <span class="s2">"</span><span class="nv">$__object</span><span class="s2">/parameter/loglevel"</span><span class="k">)</span><span class="s2">"</span>
|
||
|
|
||
|
<span class="c1"># boolean parameter</span>
|
||
|
<span class="k">if</span> <span class="o">[</span> -f <span class="s2">"</span><span class="nv">$__object</span><span class="s2">/parameter/use_ssl"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
|
||
|
<span class="c1"># file exists -> True</span>
|
||
|
<span class="c1"># do some fancy ssl stuff</span>
|
||
|
<span class="k">fi</span>
|
||
|
|
||
|
<span class="c1"># parameter with multiple values</span>
|
||
|
<span class="k">if</span> <span class="o">[</span> -f <span class="s2">"</span><span class="nv">$__object</span><span class="s2">/parameter/server_alias"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
|
||
|
<span class="k">for</span> <span class="nb">alias</span> in <span class="k">$(</span>cat <span class="s2">"</span><span class="nv">$__object</span><span class="s2">/parameter/server_alias"</span><span class="k">)</span><span class="p">;</span> <span class="k">do</span>
|
||
|
<span class="nb">echo</span> <span class="nv">$alias</span> > /some/where/useful
|
||
|
<span class="k">done</span>
|
||
|
<span class="k">fi</span>
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="section" id="input-from-stdin">
|
||
|
<h2>15.11. Input from stdin<a class="headerlink" href="#input-from-stdin" title="Permalink to this headline">¶</a></h2>
|
||
|
<p>Every type can access what has been written on stdin when it has been called.
|
||
|
The result is saved into the <strong>stdin</strong> file in the object directory.</p>
|
||
|
<p>Example use of a type: (e.g. in cdist/conf/type/__archlinux_hostname)</p>
|
||
|
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>__file /etc/rc.conf --source - <span class="s"><< eof</span>
|
||
|
<span class="s">...</span>
|
||
|
<span class="s">HOSTNAME="$__target_host"</span>
|
||
|
<span class="s">...</span>
|
||
|
<span class="s">eof</span>
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
<p>If you have not seen this syntax (<< eof) before, it may help you to read
|
||
|
about "here documents".</p>
|
||
|
<p>In the __file type, stdin is used as source for the file, if - is used for source:</p>
|
||
|
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="o">[</span> -f <span class="s2">"</span><span class="nv">$__object</span><span class="s2">/parameter/source"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
|
||
|
<span class="nv">source</span><span class="o">=</span><span class="s2">"</span><span class="k">$(</span>cat <span class="s2">"</span><span class="nv">$__object</span><span class="s2">/parameter/source"</span><span class="k">)</span><span class="s2">"</span>
|
||
|
<span class="k">if</span> <span class="o">[</span> <span class="s2">"</span><span class="nv">$source</span><span class="s2">"</span> <span class="o">=</span> <span class="s2">"-"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
|
||
|
<span class="nv">source</span><span class="o">=</span><span class="s2">"</span><span class="nv">$__object</span><span class="s2">/stdin"</span>
|
||
|
<span class="k">fi</span>
|
||
|
....
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="section" id="writing-the-manifest">
|
||
|
<h2>15.12. Writing the manifest<a class="headerlink" href="#writing-the-manifest" title="Permalink to this headline">¶</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
|
||
|
a shortened version looks like this:</p>
|
||
|
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="nv">os</span><span class="o">=</span><span class="s2">"</span><span class="k">$(</span>cat <span class="s2">"</span><span class="nv">$__global</span><span class="s2">/explorer/os"</span><span class="k">)</span><span class="s2">"</span>
|
||
|
<span class="k">case</span> <span class="s2">"</span><span class="nv">$os</span><span class="s2">"</span> in
|
||
|
archlinux<span class="o">)</span> <span class="nv">type</span><span class="o">=</span><span class="s2">"pacman"</span> <span class="p">;;</span>
|
||
|
debian<span class="p">|</span>ubuntu<span class="o">)</span> <span class="nv">type</span><span class="o">=</span><span class="s2">"apt"</span> <span class="p">;;</span>
|
||
|
gentoo<span class="o">)</span> <span class="nv">type</span><span class="o">=</span><span class="s2">"emerge"</span> <span class="p">;;</span>
|
||
|
*<span class="o">)</span>
|
||
|
<span class="nb">echo</span> <span class="s2">"Don't know how to manage packages on: </span><span class="nv">$os</span><span class="s2">"</span> ><span class="p">&</span><span class="m">2</span>
|
||
|
<span class="nb">exit</span> <span class="m">1</span>
|
||
|
<span class="p">;;</span>
|
||
|
<span class="k">esac</span>
|
||
|
|
||
|
__package_<span class="nv">$type</span> <span class="s2">"</span><span class="nv">$@</span><span class="s2">"</span>
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
<p>As you can see, the type can reference different environment variables,
|
||
|
which are documented in <a class="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 <a class="reference external" href="cdist-manifest.html">cdist manifest</a>.</p>
|
||
|
</div>
|
||
|
<div class="section" id="singleton-one-instance-only">
|
||
|
<h2>15.13. Singleton - one instance only<a class="headerlink" href="#singleton-one-instance-only" title="Permalink to this headline">¶</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
|
||
|
directory:</p>
|
||
|
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>touch cdist/conf/type/__NAME/singleton
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
<p>This will also change the way your type must be called:</p>
|
||
|
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>__YOURTYPE --parameter value
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
<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>
|
||
|
</div>
|
||
|
<div class="section" id="install-type-with-install-command">
|
||
|
<h2>15.14. Install - type with install command<a class="headerlink" href="#install-type-with-install-command" title="Permalink to this headline">¶</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>
|
||
|
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>touch cdist/conf/type/__install_NAME/install
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
<p>With other commands, i.e. config, it will be skipped if used.</p>
|
||
|
</div>
|
||
|
<div class="section" id="nonparallel-only-one-instance-can-be-run-at-a-time">
|
||
|
<h2>15.15. Nonparallel - only one instance can be run at a time<a class="headerlink" href="#nonparallel-only-one-instance-can-be-run-at-a-time" title="Permalink to this headline">¶</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"
|
||
|
in your type directory:</p>
|
||
|
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>touch cdist/conf/type/__NAME/nonparallel
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
<p>For example, package types are nonparallel types.</p>
|
||
|
</div>
|
||
|
<div class="section" id="the-type-explorers">
|
||
|
<h2>15.16. The type explorers<a class="headerlink" href="#the-type-explorers" title="Permalink to this headline">¶</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>
|
||
|
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="o">[</span> -f <span class="s2">"</span><span class="nv">$__object</span><span class="s2">/parameter/destination"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
|
||
|
<span class="nv">destination</span><span class="o">=</span><span class="s2">"</span><span class="k">$(</span>cat <span class="s2">"</span><span class="nv">$__object</span><span class="s2">/parameter/destination"</span><span class="k">)</span><span class="s2">"</span>
|
||
|
<span class="k">else</span>
|
||
|
<span class="nv">destination</span><span class="o">=</span><span class="s2">"/</span><span class="nv">$__object_id</span><span class="s2">"</span>
|
||
|
<span class="k">fi</span>
|
||
|
|
||
|
<span class="k">if</span> <span class="o">[</span> -e <span class="s2">"</span><span class="nv">$destination</span><span class="s2">"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
|
||
|
md5sum < <span class="s2">"</span><span class="nv">$destination</span><span class="s2">"</span>
|
||
|
<span class="k">fi</span>
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="section" id="writing-the-gencode-script">
|
||
|
<h2>15.17. Writing the gencode script<a class="headerlink" href="#writing-the-gencode-script" title="Permalink to this headline">¶</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>
|
||
|
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="c1"># Debug output to stderr</span>
|
||
|
<span class="nb">echo</span> <span class="s2">"My fancy debug line"</span> ><span class="p">&</span><span class="m">2</span>
|
||
|
|
||
|
<span class="c1"># Output to be saved by cdist for execution on the target</span>
|
||
|
<span class="nb">echo</span> <span class="s2">"touch /etc/cdist-configured"</span>
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
<p>Notice: if you use __remote_copy or __remote_exec directly in your scripts
|
||
|
then for IPv6 address with __remote_copy execution you should enclose IPv6
|
||
|
address in square brackets. The same applies to __remote_exec if it behaves
|
||
|
the same as ssh for some options where colon is a delimiter, as for -L ssh
|
||
|
option (see <strong>ssh</strong>(1) and <strong>scp</strong>(1)).</p>
|
||
|
</div>
|
||
|
<div class="section" id="variable-access-from-the-generated-scripts">
|
||
|
<h2>15.18. Variable access from the generated scripts<a class="headerlink" href="#variable-access-from-the-generated-scripts" title="Permalink to this headline">¶</a></h2>
|
||
|
<p>In the generated scripts, you have access to the following cdist variables</p>
|
||
|
<ul class="simple">
|
||
|
<li>__object</li>
|
||
|
<li>__object_id</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>
|
||
|
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="o">[</span> -f <span class="s2">"</span><span class="nv">$__object</span><span class="s2">/parameter/name"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
|
||
|
<span class="nv">name</span><span class="o">=</span><span class="s2">"</span><span class="k">$(</span>cat <span class="s2">"</span><span class="nv">$__object</span><span class="s2">/parameter/name"</span><span class="k">)</span><span class="s2">"</span>
|
||
|
<span class="k">else</span>
|
||
|
<span class="nv">name</span><span class="o">=</span><span class="s2">"</span><span class="nv">$__object_id</span><span class="s2">"</span>
|
||
|
<span class="k">fi</span>
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="section" id="environment-variable-usage-idiom">
|
||
|
<h2>15.19. Environment variable usage idiom<a class="headerlink" href="#environment-variable-usage-idiom" title="Permalink to this headline">¶</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>
|
||
|
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="nv">tempfile</span><span class="o">=</span><span class="k">$(</span>mktemp <span class="s2">"</span><span class="si">${</span><span class="nv">TMPDIR</span><span class="k">:-</span><span class="p">/tmp</span><span class="si">}</span><span class="s2">/cdist.XXXXXXXXXX"</span><span class="k">)</span>
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="section" id="log-level-in-types">
|
||
|
<h2>15.20. Log level in types<a class="headerlink" href="#log-level-in-types" title="Permalink to this headline">¶</a></h2>
|
||
|
<p>cdist log level can be accessed from __cdist_log_level variable.One of:</p>
|
||
|
<blockquote>
|
||
|
<div><table border="1" class="docutils">
|
||
|
<colgroup>
|
||
|
<col width="48%" />
|
||
|
<col width="52%" />
|
||
|
</colgroup>
|
||
|
<thead valign="bottom">
|
||
|
<tr class="row-odd"><th class="head">Log level</th>
|
||
|
<th class="head">Log level value</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody valign="top">
|
||
|
<tr class="row-even"><td>OFF</td>
|
||
|
<td>60</td>
|
||
|
</tr>
|
||
|
<tr class="row-odd"><td>ERROR</td>
|
||
|
<td>40</td>
|
||
|
</tr>
|
||
|
<tr class="row-even"><td>WARNING</td>
|
||
|
<td>30</td>
|
||
|
</tr>
|
||
|
<tr class="row-odd"><td>INFO</td>
|
||
|
<td>20</td>
|
||
|
</tr>
|
||
|
<tr class="row-even"><td>VERBOSE</td>
|
||
|
<td>15</td>
|
||
|
</tr>
|
||
|
<tr class="row-odd"><td>DEBUG</td>
|
||
|
<td>10</td>
|
||
|
</tr>
|
||
|
<tr class="row-even"><td>TRACE</td>
|
||
|
<td>5</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
</div></blockquote>
|
||
|
<p>It is available for initial manifest, explorer, type manifest,
|
||
|
type explorer, type gencode.</p>
|
||
|
</div>
|
||
|
<div class="section" id="hints-for-typewriters">
|
||
|
<h2>15.21. Hints for typewriters<a class="headerlink" href="#hints-for-typewriters" title="Permalink to this headline">¶</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
|
||
|
never ever touch this folder).</p>
|
||
|
</div>
|
||
|
<div class="section" id="how-to-include-a-type-into-upstream-cdist">
|
||
|
<h2>15.22. How to include a type into upstream cdist<a class="headerlink" href="#how-to-include-a-type-into-upstream-cdist" title="Permalink to this headline">¶</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 <a class="reference external" href="cdist-hacker.html">cdist hacking</a> on
|
||
|
how to submit it.</p>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
<footer>
|
||
|
|
||
|
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
|
||
|
|
||
|
<a href="cdist-types.html" class="btn btn-neutral float-right" title="16. cdist types" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
|
||
|
|
||
|
|
||
|
<a href="cdist-manifest.html" class="btn btn-neutral float-left" title="14. Manifest" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
|
||
|
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<hr/>
|
||
|
|
||
|
<div role="contentinfo">
|
||
|
<p>
|
||
|
© Copyright
|
||
|
|
||
|
</p>
|
||
|
</div>
|
||
|
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
|
||
|
|
||
|
</footer>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
<script type="text/javascript">
|
||
|
jQuery(function () {
|
||
|
SphinxRtdTheme.Navigation.enable(true);
|
||
|
});
|
||
|
</script>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
</body>
|
||
|
</html>
|