www.nico.schottelius.org/software/cdist/man/beta/cdist-preos.html

434 lines
19 KiB
HTML
Raw Normal View History

2016-11-27 15:32:05 +00:00
<!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">
2017-07-20 19:22:04 +00:00
<title>19. PreOS &mdash; cdist 4.5.0 documentation</title>
2016-11-27 15:32:05 +00:00
2017-06-13 20:40:23 +00:00
2016-11-27 15:32:05 +00:00
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="index" title="Index"
href="genindex.html"/>
<link rel="search" title="Search" href="search.html"/>
2017-07-20 19:22:04 +00:00
<link rel="top" title="cdist 4.5.0 documentation" href="index.html"/>
<link rel="next" title="20. Reference" href="cdist-reference.html"/>
<link rel="prev" title="18. Trigger" href="cdist-trigger.html"/>
2016-11-27 15:32:05 +00:00
<script src="_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
2017-06-13 20:40:23 +00:00
2016-11-27 15:32:05 +00:00
<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">
2017-07-20 19:22:04 +00:00
4.5.0
2016-11-27 15:32:05 +00:00
</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">
2017-06-13 20:40:23 +00:00
<ul class="current">
2016-11-27 15:32:05 +00:00
<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="man1/cdist.html">9. cdist(1)</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-bootstrap.html">10. Bootstrap</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-manifest.html">11. Manifest</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-type.html">12. cdist type</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-types.html">13. cdist types</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-explorer.html">14. Explorer</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-messaging.html">15. Messaging</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-parallelization.html">16. Parallelization</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-inventory.html">17. Inventory</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-trigger.html">18. Trigger</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">19. PreOS</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#description">19.1. Description</a></li>
<li class="toctree-l2"><a class="reference internal" href="#preos-creation">19.2. PreOS creation</a></li>
<li class="toctree-l2"><a class="reference internal" href="#implementing-new-preos-sub-command">19.3. Implementing new PreOS sub-command</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#example-writing-new-dummy-preos-sub-command">19.3.1. Example writing new dummy preos sub-command</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#module-based-preos">19.3.1.1. Module based preos:</a></li>
<li class="toctree-l4"><a class="reference internal" href="#class-based-preos">19.3.1.2. Class based preos:</a></li>
2016-11-27 15:32:05 +00:00
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#simple-tipical-use-case-for-using-preos-and-trigger">19.4. Simple tipical use case for using PreOS and trigger</a></li>
2016-11-27 15:32:05 +00:00
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="cdist-reference.html">20. Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-best-practice.html">21. Best practice</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-stages.html">22. Execution stages</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-remote-exec-copy.html">23. Remote exec and copy commands</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-hacker.html">24. Hacking</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-troubleshooting.html">25. Troubleshooting</a></li>
2016-11-27 15:32:05 +00:00
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
2017-06-13 20:40:23 +00:00
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">cdist</a>
2016-11-27 15:32:05 +00:00
</nav>
<div class="wy-nav-content">
<div class="rst-content">
2017-06-13 20:40:23 +00:00
2016-11-27 15:32:05 +00:00
<div role="navigation" aria-label="breadcrumbs navigation">
2017-06-13 20:40:23 +00:00
2016-11-27 15:32:05 +00:00
<ul class="wy-breadcrumbs">
2017-06-13 20:40:23 +00:00
<li><a href="index.html">Docs</a> &raquo;</li>
<li>19. PreOS</li>
2016-11-27 15:32:05 +00:00
<li class="wy-breadcrumbs-aside">
2017-06-13 20:40:23 +00:00
<a href="_sources/cdist-preos.rst.txt" rel="nofollow"> View page source</a>
2016-11-27 15:32:05 +00:00
</li>
2017-06-13 20:40:23 +00:00
2016-11-27 15:32:05 +00:00
</ul>
2017-06-13 20:40:23 +00:00
2016-11-27 15:32:05 +00:00
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="preos">
<h1>19. PreOS<a class="headerlink" href="#preos" title="Permalink to this headline"></a></h1>
2016-11-27 15:32:05 +00:00
<div class="section" id="description">
<h2>19.1. Description<a class="headerlink" href="#description" title="Permalink to this headline"></a></h2>
2016-11-27 15:32:05 +00:00
<p>With cdist you can install and configure new machines. You can use cdist to
create PreOS, minimal OS which purpose is to boot new machine.
After PreOS is booted machine is ready for installing desired OS and
then it is ready for configuration.</p>
</div>
<div class="section" id="preos-creation">
<h2>19.2. PreOS creation<a class="headerlink" href="#preos-creation" title="Permalink to this headline"></a></h2>
2016-11-27 15:32:05 +00:00
<p>With cdist you can create PreOS.
Currently supported PreOS-es include:</p>
<ul class="simple">
<li>debian</li>
2017-06-16 11:14:22 +00:00
<li>ubuntu</li>
<li>devuan.</li>
2016-11-27 15:32:05 +00:00
</ul>
<p>PreOS is created using cdist preos command. preos command has subcommands that
create the desired PreOS.</p>
<p>For example, to create ubuntu PreOS:</p>
<div class="highlight-sh"><div class="highlight"><pre><span></span>$ cdist preos ubuntu /preos/preos-ubuntu -b -C <span class="se">\</span>
-k ~/.ssh/id_rsa.pub -p /preos/pxe-ubuntu <span class="se">\</span>
-t <span class="s2">&quot;/usr/bin/curl 192.168.111.5:3000/install/&quot;</span>
</pre></div>
</div>
<p>For more info about available options see cdist manual page.</p>
<p>This will bootstrap (<code class="docutils literal"><span class="pre">-b</span></code>) ubuntu PreOS in <code class="docutils literal"><span class="pre">/preos/preos-ubuntu</span></code> directory, it
will be configured (<code class="docutils literal"><span class="pre">-C</span></code>) using default built-in initial manifest and with
specified ssh authorized key (<code class="docutils literal"><span class="pre">-k</span></code>) and with specified trigger command (<code class="docutils literal"><span class="pre">-t</span></code>).
After bootstrapping and configuration PXE
boot directory will be created (<code class="docutils literal"><span class="pre">-p</span></code>) in <code class="docutils literal"><span class="pre">/preos/pxe-ubuntu</span></code>.</p>
<p>After PreOS is created new machines can be booted using created PXE (after
proper dhcp, tftp setting).</p>
<p>Since PreOS is configured with ssh authorized key it can be accessed throguh
ssh, i.e. it can be further installed and configured with cdist.</p>
<p>When installing and configuring new machines using cdist's PreOS concept
cdist can use triggering for host installation/configuration, which is described
in the previous chapter.</p>
2016-11-27 15:32:05 +00:00
<p>When new machine is booted with PreOS then trigger command is executed.
Machine will connect to cdist trigger server. If the request is, for example,
for installation then cdist trigger server will start install command for the
client host using parameters specified at trigger server startup.</p>
2016-11-27 15:32:05 +00:00
</div>
<div class="section" id="implementing-new-preos-sub-command">
<h2>19.3. Implementing new PreOS sub-command<a class="headerlink" href="#implementing-new-preos-sub-command" title="Permalink to this headline"></a></h2>
2016-11-27 15:32:05 +00:00
<p>preos command is implemented as a plugin system. This plugin system scans for
preos subcommands in <code class="docutils literal"><span class="pre">cdist/preos/</span></code> distribution directory and also in
<code class="docutils literal"><span class="pre">~/.cdist/preos/</span></code> directory if it exists.</p>
<p>preos subcommand is a module or a class that satisfies the following:</p>
<ul class="simple">
<li>it has attribute <code class="docutils literal"><span class="pre">_cdist_preos</span></code> set to <code class="docutils literal"><span class="pre">True</span></code></li>
<li>it has function/method <code class="docutils literal"><span class="pre">commandline</span></code>.</li>
</ul>
<p>For a module based preos subcommand <code class="docutils literal"><span class="pre">commandline</span></code> function accepts a module
object as its first argument and the list of command line
arguments (<code class="docutils literal"><span class="pre">sys.argv[2:]</span></code>).</p>
<p>For a class preos subcommand <code class="docutils literal"><span class="pre">commandline</span></code> method should be staticmethod and
it accepts a class object as its first argument and the list of command line
arguments(<code class="docutils literal"><span class="pre">sys.argv[2:]</span></code>).</p>
<p>If preos scanning finds a module/class that has <code class="docutils literal"><span class="pre">_cdist_preos</span></code> set
to <code class="docutils literal"><span class="pre">True</span></code> and it has function/method <code class="docutils literal"><span class="pre">commandline</span></code> then this module/class is
registered to preos subcommands. The name of the command is set to <code class="docutils literal"><span class="pre">_preos_name</span></code>
attribute if it exists, otherwise it is set to the module/class name, lowercase.
When registered preos subcommand is specified as preos command then <code class="docutils literal"><span class="pre">commandline</span></code>
will be called with first argument set to module/class object and second argument
set to <code class="docutils literal"><span class="pre">sys.argv[2:]</span></code>.</p>
<div class="section" id="example-writing-new-dummy-preos-sub-command">
<h3>19.3.1. Example writing new dummy preos sub-command<a class="headerlink" href="#example-writing-new-dummy-preos-sub-command" title="Permalink to this headline"></a></h3>
2016-11-27 15:32:05 +00:00
<div class="section" id="module-based-preos">
<h4>19.3.1.1. Module based preos:<a class="headerlink" href="#module-based-preos" title="Permalink to this headline"></a></h4>
2016-11-27 15:32:05 +00:00
<ol class="arabic simple">
<li>Create directory <code class="docutils literal"><span class="pre">~/.cdist/preos/</span></code> if it does not exist</li>
<li>Create <code class="docutils literal"><span class="pre">~/.cdist/preos/netbsd.py</span></code> with the following contents:</li>
</ol>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">_preos_name</span> <span class="o">=</span> <span class="s1">&#39;netbsd&#39;</span>
<span class="n">_cdist_preos</span> <span class="o">=</span> <span class="bp">True</span>
2017-06-13 20:40:23 +00:00
<span class="k">def</span> <span class="nf">commandline</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">args</span><span class="p">):</span>
2016-11-27 15:32:05 +00:00
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;NetBSD PreOS: {}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">args</span><span class="p">))</span>
</pre></div>
</div>
<p>When you try to run this new preos you will get:</p>
<div class="highlight-sh"><div class="highlight"><pre><span></span>$ cdist preos -h
usage: cdist preos <span class="o">[</span>-h<span class="o">]</span> preos
Create PreOS
positional arguments:
preos PreOS to create, one of: <span class="o">{</span><span class="s1">&#39;netbsd&#39;</span>, <span class="s1">&#39;debian&#39;</span>, <span class="s1">&#39;ubuntu&#39;</span><span class="o">}</span>
optional arguments:
-h, --help show this <span class="nb">help</span> message and <span class="nb">exit</span>
$ cdist preos netbsd
NetBSD PreOS: <span class="o">[]</span>
</pre></div>
</div>
</div>
<div class="section" id="class-based-preos">
<h4>19.3.1.2. Class based preos:<a class="headerlink" href="#class-based-preos" title="Permalink to this headline"></a></h4>
2016-11-27 15:32:05 +00:00
<ol class="arabic simple">
<li>Create directory <code class="docutils literal"><span class="pre">~/.cdist/preos/</span></code> if it does not exist</li>
<li>Create <code class="docutils literal"><span class="pre">~/.cdist/preos/freebsd.py</span></code> with the following contents:</li>
</ol>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">FreeBSD</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="n">_cdist_preos</span> <span class="o">=</span> <span class="bp">True</span>
<span class="nd">@classmethod</span>
2017-06-13 20:40:23 +00:00
<span class="k">def</span> <span class="nf">commandline</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">args</span><span class="p">):</span>
2016-11-27 15:32:05 +00:00
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;FreeBSD dummy preos: {}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">args</span><span class="p">))</span>
</pre></div>
</div>
<p>When you try to run this new preos you will get:</p>
<div class="highlight-sh"><div class="highlight"><pre><span></span>$ cdist preos -h
usage: cdist preos <span class="o">[</span>-h<span class="o">]</span> preos
Create PreOS
positional arguments:
preos PreOS to create, one of: <span class="o">{</span><span class="s1">&#39;freebsd&#39;</span>, <span class="s1">&#39;debian&#39;</span>, <span class="s1">&#39;ubuntu&#39;</span><span class="o">}</span>
optional arguments:
-h, --help show this <span class="nb">help</span> message and <span class="nb">exit</span>
$ cdist preos freebsd
FreeBSD dummy preos: <span class="o">[]</span>
</pre></div>
</div>
<p>In the <code class="docutils literal"><span class="pre">commandline</span></code> function/method you have all the freedom to actually create
PreOS.</p>
</div>
</div>
</div>
<div class="section" id="simple-tipical-use-case-for-using-preos-and-trigger">
<h2>19.4. Simple tipical use case for using PreOS and trigger<a class="headerlink" href="#simple-tipical-use-case-for-using-preos-and-trigger" title="Permalink to this headline"></a></h2>
2016-11-27 15:32:05 +00:00
<p>Tipical use case for using PreOS and trigger command include the following steps.</p>
<ol class="arabic">
<li><p class="first">Create PreOS PXE with ssh key and trigger command for installation.</p>
<blockquote>
<div><div class="highlight-sh"><div class="highlight"><pre><span></span>$ cdist preos ubuntu /preos/ubuntu -b -C <span class="se">\</span>
-k ~/.ssh/id_rsa.pub -p /preos/pxe <span class="se">\</span>
-t <span class="s2">&quot;/usr/bin/curl 192.168.111.5:3000/install/&quot;</span>
</pre></div>
</div>
</div></blockquote>
</li>
<li><p class="first">Configure dhcp server and tftp server.</p>
</li>
<li><p class="first">On cdist host (192.168.111.5 from above) start trigger command (it will use
default init manifest for installation).</p>
<blockquote>
<div><div class="highlight-sh"><div class="highlight"><pre><span></span>$ cdist trigger -b -v
</pre></div>
</div>
</div></blockquote>
</li>
<li><p class="first">After all is set up start new machines (PXE boot).</p>
</li>
<li><p class="first">New machine boots and executes trigger command, i.e. triggers installation.</p>
</li>
<li><p class="first">Cdist trigger server starts installing host that has triggered it.</p>
</li>
<li><p class="first">After cdist install is finished new host is installed.</p>
</li>
</ol>
</div>
</div>
2017-06-13 20:40:23 +00:00
</div>
<div class="articleComments">
2016-11-27 15:32:05 +00:00
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
2017-06-13 20:40:23 +00:00
<a href="cdist-reference.html" class="btn btn-neutral float-right" title="20. Reference" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
2016-11-27 15:32:05 +00:00
2017-06-13 20:40:23 +00:00
<a href="cdist-trigger.html" class="btn btn-neutral" title="18. Trigger" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
2016-11-27 15:32:05 +00:00
</div>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright .
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/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">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'./',
2017-07-20 19:22:04 +00:00
VERSION:'4.5.0',
2016-11-27 15:32:05 +00:00
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
2017-06-13 20:40:23 +00:00
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
2016-11-27 15:32:05 +00:00
};
</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 type="text/javascript" src="_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
</body>
</html>