<h2><spanclass="section-number">20.3. </span>cdist inventory interface<aclass="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),
<h2><spanclass="section-number">20.4. </span>Configuring hosts using inventory<aclass="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>
<divclass="section"id="examples">
<h2><spanclass="section-number">20.5. </span>Examples<aclass="headerlink"href="#examples"title="Permalink to this headline">¶</a></h2>
<divclass="highlight-sh notranslate"><divclass="highlight"><pre><span></span><spanclass="c1"># List inventory content</span>
$ cdist inventory list -b
<spanclass="c1"># List inventory for specified host localhost</span>
$ cdist inventory list -b localhost
<spanclass="c1"># List inventory for specified tag loadbalancer</span>
$ cdist inventory list -b -t loadbalancer
<spanclass="c1"># Add hosts to inventory</span>
$ cdist inventory add-host -b web1 web2 web3
<spanclass="c1"># Delete hosts from file old-hosts from inventory</span>
$ cdist inventory del-host -b -f old-hosts
<spanclass="c1"># Add tags to specified hosts</span>
<h2><spanclass="section-number">20.6. </span>Example of manipulating database<aclass="headerlink"href="#example-of-manipulating-database"title="Permalink to this headline">¶</a></h2>
<divclass="highlight-sh notranslate"><divclass="highlight"><pre><span></span>$ python3 scripts/cdist inventory list -b
$ python3 scripts/cdist inventory list -b -t -a web <spanclass="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
$ <spanclass="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 <spanclass="m">20</span>
-rw-r--r-- <spanclass="m">1</span> darko darko <spanclass="m">16</span> Jun <spanclass="m">24</span><spanclass="m">12</span>:43 shell1.mycloud.net
-rw-r--r-- <spanclass="m">1</span> darko darko <spanclass="m">16</span> Jun <spanclass="m">24</span><spanclass="m">12</span>:43 shell2.mycloud.net
-rw-r--r-- <spanclass="m">1</span> darko darko <spanclass="m">19</span> Jun <spanclass="m">24</span><spanclass="m">12</span>:43 test.mycloud.net
-rw-r--r-- <spanclass="m">1</span> darko darko <spanclass="m">14</span> Jun <spanclass="m">24</span><spanclass="m">12</span>:43 web1.mycloud.net
-rw-r--r-- <spanclass="m">1</span> darko darko <spanclass="m">14</span> Jun <spanclass="m">24</span><spanclass="m">12</span>:43 web2.mycloud.net
$ cat test.mycloud.net
<spanclass="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 <aclass="reference external"href="man1/cdist.html">cdist</a>(1).</p>
</div>
<divclass="section"id="using-external-inventory">
<h2><spanclass="section-number">20.7. </span>Using external inventory<aclass="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>
<divclass="highlight-sh notranslate"><divclass="highlight"><pre><span></span>$ sqlite3 hosts.db <spanclass="s2">"select hostname from hosts where purpose = 'django';"</span><spanclass="p">|</span> cdist config
Built with <ahref="http://sphinx-doc.org/">Sphinx</a> using a <ahref="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <ahref="https://readthedocs.org">Read the Docs</a>.