www.nico.schottelius.org/software/cdist/man/4.8.0/cdist-inventory.html

463 lines
18 KiB
HTML
Raw Normal View History

2018-02-14 19:13:16 +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">
<title>18. Inventory &mdash; cdist 4.8.0 documentation</title>
<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"/>
<link rel="top" title="cdist 4.8.0 documentation" href="index.html"/>
<link rel="next" title="19. cdist integration / using cdist as library" href="cdist-integration.html"/>
<link rel="prev" title="17. Parallelization" href="cdist-parallelization.html"/>
<script src="_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<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.8.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="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-configuration.html">11. Configuration</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-manifest.html">12. Manifest</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-type.html">13. cdist type</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-types.html">14. cdist types</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-explorer.html">15. Explorer</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-messaging.html">16. Messaging</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-parallelization.html">17. Parallelization</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">18. Inventory</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#introduction">18.1. Introduction</a></li>
<li class="toctree-l2"><a class="reference internal" href="#description">18.2. Description</a></li>
<li class="toctree-l2"><a class="reference internal" href="#cdist-inventory-interface">18.3. cdist inventory interface</a></li>
<li class="toctree-l2"><a class="reference internal" href="#configuring-hosts-using-inventory">18.4. Configuring hosts using inventory</a></li>
<li class="toctree-l2"><a class="reference internal" href="#examples">18.5. Examples</a></li>
<li class="toctree-l2"><a class="reference internal" href="#example-of-manipulating-database">18.6. Example of manipulating database</a></li>
<li class="toctree-l2"><a class="reference internal" href="#using-external-inventory">18.7. Using external inventory</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="cdist-integration.html">19. cdist integration / using cdist as library</a></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-cache.html">23. Local cache overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-saving-output-streams.html">24. Saving output streams</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-remote-exec-copy.html">25. Remote exec and copy commands</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-hacker.html">26. Hacking</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdist-troubleshooting.html">27. Troubleshooting</a></li>
</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">
<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> &raquo;</li>
<li>18. Inventory</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/cdist-inventory.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="inventory">
<h1>18. Inventory<a class="headerlink" href="#inventory" title="Permalink to this headline"></a></h1>
<div class="section" id="introduction">
<h2>18.1. Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline"></a></h2>
<p>cdist comes with simple built-in tag based inventory. It is a simple inventory
with list of hosts and a host has a list of tags.
Inventory functionality is still in <strong>beta</strong> so it can be used only if beta
command line flag is specified (-b, --beta) or setting CDIST_BETA env var.</p>
</div>
<div class="section" id="description">
<h2>18.2. Description<a class="headerlink" href="#description" title="Permalink to this headline"></a></h2>
<p>The idea is to have simple tagging inventory. There is a list of hosts and for
each host there are tags. Inventory database is a set of files under inventory
database base directory. Filename equals hostname. Each file contains tags for
hostname with each tag on its own line.</p>
<p>Using inventory you can now configure hosts by selecting them by tags.</p>
<p>Tags have no values, as tags are just tags. Tag name-value would in this
context mean that host has two tags and it is selected by specifying that both
tags are present.</p>
<p>This inventory is <strong>KISS</strong> cdist built-in inventory database. You can maintain it
using cdist inventory interface or using standard UNIX tools.</p>
</div>
<div class="section" id="cdist-inventory-interface">
<h2>18.3. cdist inventory interface<a class="headerlink" href="#cdist-inventory-interface" title="Permalink to this headline"></a></h2>
<p>With cdist inventory interface you can list host(s) and tag(s), add host(s),
add tag(s), delete host(s) and delete tag(s).</p>
</div>
<div class="section" id="configuring-hosts-using-inventory">
<h2>18.4. Configuring hosts using inventory<a class="headerlink" href="#configuring-hosts-using-inventory" title="Permalink to this headline"></a></h2>
<p>config command now has new options, <strong>-t</strong>, <strong>-a</strong> and <strong>-A</strong>.</p>
<p><strong>-A</strong> means that all hosts in tag db is selected.</p>
<p><strong>-a</strong> means that selected hosts must contain ALL specified tags.</p>
<p><strong>-t</strong> means that host specifies tag - all hosts that have specified tags are
selected.</p>
</div>
<div class="section" id="examples">
<h2>18.5. Examples<a class="headerlink" href="#examples" title="Permalink to this headline"></a></h2>
<div class="highlight-sh"><div class="highlight"><pre><span></span><span class="c1"># List inventory content</span>
$ cdist inventory list -b
<span class="c1"># List inventory for specified host localhost</span>
$ cdist inventory list -b localhost
<span class="c1"># List inventory for specified tag loadbalancer</span>
$ cdist inventory list -b -t loadbalancer
<span class="c1"># Add hosts to inventory</span>
$ cdist inventory add-host -b web1 web2 web3
<span class="c1"># Delete hosts from file old-hosts from inventory</span>
$ cdist inventory del-host -b -f old-hosts
<span class="c1"># Add tags to specifed hosts</span>
$ cdist inventory add-tag -b -t europe,croatia,web,static web1 web2
<span class="c1"># Add tag to all hosts in inventory</span>
$ cdist inventory add-tag -b -t vm
<span class="c1"># Delete all tags from specified host</span>
$ cdist inventory del-tag -b -a localhost
<span class="c1"># Delete tags read from stdin from hosts specified by file hosts</span>
$ cdist inventory del-tag -b -T - -f hosts
<span class="c1"># Configure hosts from inventory with any of specified tags</span>
$ cdist config -b -t web dynamic
<span class="c1"># Configure hosts from inventory with all specified tags</span>
$ cdist config -b -t -a web dynamic
<span class="c1"># Configure all hosts from inventory db</span>
$ cdist config -b -A
</pre></div>
</div>
</div>
<div class="section" id="example-of-manipulating-database">
<h2>18.6. Example of manipulating database<a class="headerlink" href="#example-of-manipulating-database" title="Permalink to this headline"></a></h2>
<div class="highlight-sh"><div class="highlight"><pre><span></span>$ python3 scripts/cdist inventory list -b
$ python3 scripts/cdist inventory add-host -b localhost
$ python3 scripts/cdist inventory add-host -b test.mycloud.net
$ python3 scripts/cdist inventory list -b
localhost
test.mycloud.net
$ python3 scripts/cdist inventory add-host -b web1.mycloud.net web2.mycloud.net shell1.mycloud.net shell2.mycloud.net
$ python3 scripts/cdist inventory list -b
localhost
test.mycloud.net
web1.mycloud.net
web2.mycloud.net
shell1.mycloud.net
shell2.mycloud.net
$ python3 scripts/cdist inventory add-tag -b -t web web1.mycloud.net web2.mycloud.net
$ python3 scripts/cdist inventory add-tag -b -t shell shell1.mycloud.net shell2.mycloud.net
$ python3 scripts/cdist inventory add-tag -b -t cloud
$ python3 scripts/cdist inventory list -b
localhost cloud
test.mycloud.net cloud
web1.mycloud.net cloud,web
web2.mycloud.net cloud,web
shell1.mycloud.net cloud,shell
shell2.mycloud.net cloud,shell
$ python3 scripts/cdist inventory add-tag -b -t test,web,shell test.mycloud.net
$ python3 scripts/cdist inventory list -b
localhost cloud
test.mycloud.net cloud,shell,test,web
web1.mycloud.net cloud,web
web2.mycloud.net cloud,web
shell1.mycloud.net cloud,shell
shell2.mycloud.net cloud,shell
$ python3 scripts/cdist inventory del-tag -b -t shell test.mycloud.net
$ python3 scripts/cdist inventory list -b
localhost cloud
test.mycloud.net cloud,test,web
web1.mycloud.net cloud,web
web2.mycloud.net cloud,web
shell1.mycloud.net cloud,shell
shell2.mycloud.net cloud,shell
$ python3 scripts/cdist inventory add-tag -b -t all
$ python3 scripts/cdist inventory add-tag -b -t mistake
$ python3 scripts/cdist inventory list -b
localhost all,cloud,mistake
test.mycloud.net all,cloud,mistake,test,web
web1.mycloud.net all,cloud,mistake,web
web2.mycloud.net all,cloud,mistake,web
shell1.mycloud.net all,cloud,mistake,shell
shell2.mycloud.net all,cloud,mistake,shell
$ python3 scripts/cdist inventory del-tag -b -t mistake
$ python3 scripts/cdist inventory list -b
localhost all,cloud
test.mycloud.net all,cloud,test,web
web1.mycloud.net all,cloud,web
web2.mycloud.net all,cloud,web
shell1.mycloud.net all,cloud,shell
shell2.mycloud.net all,cloud,shell
$ python3 scripts/cdist inventory del-host -b localhost
$ python3 scripts/cdist inventory list -b
test.mycloud.net all,cloud,test,web
web1.mycloud.net all,cloud,web
web2.mycloud.net all,cloud,web
shell1.mycloud.net all,cloud,shell
shell2.mycloud.net all,cloud,shell
$ python3 scripts/cdist inventory list -b -t web
test.mycloud.net all,cloud,test,web
web1.mycloud.net all,cloud,web
web2.mycloud.net all,cloud,web
$ python3 scripts/cdist inventory list -b -t -a web <span class="nb">test</span>
test.mycloud.net all,cloud,test,web
$ python3 scripts/cdist inventory list -b -t -a web all
test.mycloud.net all,cloud,test,web
web1.mycloud.net all,cloud,web
web2.mycloud.net all,cloud,web
$ python3 scripts/cdist inventory list -b -t web all
test.mycloud.net all,cloud,test,web
web1.mycloud.net all,cloud,web
web2.mycloud.net all,cloud,web
shell1.mycloud.net all,cloud,shell
shell2.mycloud.net all,cloud,shell
$ <span class="nb">cd</span> cdist/inventory
$ ls -1
shell1.mycloud.net
shell2.mycloud.net
test.mycloud.net
web1.mycloud.net
web2.mycloud.net
$ ls -l
total <span class="m">20</span>
-rw-r--r-- <span class="m">1</span> darko darko <span class="m">16</span> Jun <span class="m">24</span> <span class="m">12</span>:43 shell1.mycloud.net
-rw-r--r-- <span class="m">1</span> darko darko <span class="m">16</span> Jun <span class="m">24</span> <span class="m">12</span>:43 shell2.mycloud.net
-rw-r--r-- <span class="m">1</span> darko darko <span class="m">19</span> Jun <span class="m">24</span> <span class="m">12</span>:43 test.mycloud.net
-rw-r--r-- <span class="m">1</span> darko darko <span class="m">14</span> Jun <span class="m">24</span> <span class="m">12</span>:43 web1.mycloud.net
-rw-r--r-- <span class="m">1</span> darko darko <span class="m">14</span> Jun <span class="m">24</span> <span class="m">12</span>:43 web2.mycloud.net
$ cat test.mycloud.net
<span class="nb">test</span>
all
web
cloud
$ cat web2.mycloud.net
all
web
cloud
</pre></div>
</div>
<p>For more info about inventory commands and options see <a class="reference external" href="man1/cdist.html">cdist</a>(1).</p>
</div>
<div class="section" id="using-external-inventory">
<h2>18.7. Using external inventory<a class="headerlink" href="#using-external-inventory" title="Permalink to this headline"></a></h2>
<p>cdist can be used with any external inventory where external inventory is
some storage or database from which you can get a list of hosts to configure.
cdist can then be fed with this list of hosts through stdin or file using
<strong>-f</strong> option. For example, if your host list is stored in sqlite3 database
hosts.db and you want to select hosts which purpose is <strong>django</strong> then you
can use it with cdist like:</p>
<div class="highlight-sh"><div class="highlight"><pre><span></span>$ sqlite3 hosts.db <span class="s2">&quot;select hostname from hosts where purpose = &#39;django&#39;;&quot;</span> <span class="p">|</span> cdist config
</pre></div>
</div>
</div>
</div>
</div>
<div class="articleComments">
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="cdist-integration.html" class="btn btn-neutral float-right" title="19. cdist integration / using cdist as library" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="cdist-parallelization.html" class="btn btn-neutral" title="17. Parallelization" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</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:'./',
VERSION:'4.8.0',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</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>