450 lines
18 KiB
HTML
450 lines
18 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>20. Inventory — cdist 6.0.1 documentation</title>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<script type="text/javascript" src="_static/js/modernizr.min.js"></script>
|
||
|
|
||
|
|
||
|
<script type="text/javascript">
|
||
|
var DOCUMENTATION_OPTIONS = {
|
||
|
URL_ROOT:'./',
|
||
|
VERSION:'6.0.1',
|
||
|
LANGUAGE:'None',
|
||
|
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>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<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="21. PreOS" href="cdist-preos.html" />
|
||
|
<link rel="prev" title="19. Parallelization" href="cdist-parallelization.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
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<img src="_static/cdist-logo.jpeg" class="logo" alt="Logo"/>
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<div class="version">
|
||
|
6.0.1
|
||
|
</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-why.html">1. Why should I use cdist?</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-features.html">2. Features</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-upgrade.html">5. How to upgrade 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-quickstart.html">7. Quickstart</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-real-world.html">8. Dive into real world cdist</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="man1/cdist-dump.html">10. cdist-dump(1)</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="man1/cdist-new-type.html">11. cdist-new-type(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"><a class="reference internal" href="cdist-type.html">15. cdist type</a></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 current"><a class="current reference internal" href="#">20. Inventory</a><ul>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#introduction">20.1. Introduction</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#description">20.2. Description</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#cdist-inventory-interface">20.3. cdist inventory interface</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#configuring-hosts-using-inventory">20.4. Configuring hosts using inventory</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#examples">20.5. Examples</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#example-of-manipulating-database">20.6. Example of manipulating database</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="#using-external-inventory">20.7. Using external inventory</a></li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-preos.html">21. PreOS</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-integration.html">22. cdist integration / using cdist as library</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-reference.html">23. Reference</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-best-practice.html">24. Best practice</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-stages.html">25. Execution stages</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-cache.html">26. Local cache overview</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-saving-output-streams.html">27. Saving output streams</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-remote-exec-copy.html">28. Remote exec and copy commands</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-hacker.html">29. Hacking</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="cdist-troubleshooting.html">30. 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>20. 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>20. Inventory<a class="headerlink" href="#inventory" title="Permalink to this headline">¶</a></h1>
|
||
|
<div class="section" id="introduction">
|
||
|
<h2>20.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>20.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>20.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>20.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>20.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 specified 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>20.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>20.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">"select hostname from hosts where purpose = 'django';"</span> <span class="p">|</span> cdist config
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
<footer>
|
||
|
|
||
|
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
|
||
|
|
||
|
<a href="cdist-preos.html" class="btn btn-neutral float-right" title="21. PreOS" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
|
||
|
|
||
|
|
||
|
<a href="cdist-parallelization.html" class="btn btn-neutral float-left" title="19. Parallelization" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
|
||
|
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<hr/>
|
||
|
|
||
|
<div role="contentinfo">
|
||
|
<p>
|
||
|
© Copyright ungleich GmbH 2019
|
||
|
|
||
|
</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>
|