2019-04-23 18:55:23 +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" >
2021-04-20 05:50:28 +00:00
< meta name = "generator" content = "Docutils 0.17: http://docutils.sourceforge.net/" / >
2019-04-23 18:55:23 +00:00
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
2021-07-10 18:59:18 +00:00
< title > 20. Inventory — cdist 6.9.7 documentation< / title >
2019-04-23 18:55:23 +00:00
< script type = "text/javascript" src = "_static/js/modernizr.min.js" > < / script >
2020-06-17 10:20:44 +00:00
< script type = "text/javascript" id = "documentation_options" data-url_root = "./" src = "_static/documentation_options.js" > < / script >
< script src = "_static/jquery.js" > < / script >
< script src = "_static/underscore.js" > < / script >
< script src = "_static/doctools.js" > < / script >
2019-04-23 18:55:23 +00:00
< 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" / >
2019-05-22 16:44:06 +00:00
< link rel = "next" title = "21. Trigger" href = "cdist-trigger.html" / >
< link rel = "prev" title = "19. Parallelization" href = "cdist-parallelization.html" / >
2019-04-23 18:55:23 +00:00
< / 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
2019-05-04 22:18:20 +00:00
< img src = "_static/cdist-logo.jpeg" class = "logo" alt = "Logo" / >
2019-04-23 18:55:23 +00:00
< / a >
< div class = "version" >
2021-07-10 18:59:18 +00:00
6.9.7
2019-04-23 18:55:23 +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" >
< ul class = "current" >
2019-05-04 22:18:20 +00:00
< 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 >
2019-04-23 18:55:23 +00:00
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-install.html" > 4. How to install cdist< / a > < / li >
2019-05-04 22:18:20 +00:00
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-upgrade.html" > 5. How to upgrade cdist< / a > < / li >
2019-04-23 18:55:23 +00:00
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-support.html" > 6. Support< / a > < / li >
2019-05-04 22:18:20 +00:00
< 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 >
2019-05-22 16:44:06 +00:00
< 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 >
2019-04-23 18:55:23 +00:00
< / ul >
< / li >
2019-05-22 16:44:06 +00:00
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-trigger.html" > 21. Trigger< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-preos.html" > 22. PreOS< / a > < / li >
2021-07-10 18:59:18 +00:00
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-scan.html" > 23. Scan< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-integration.html" > 24. cdist integration / using cdist as library< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-reference.html" > 25. Reference< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-best-practice.html" > 26. Best practice< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-stages.html" > 27. Execution stages< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-cache.html" > 28. Local cache overview< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-saving-output-streams.html" > 29. Saving output streams< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-remote-exec-copy.html" > 30. Remote exec and copy commands< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-hacker.html" > 31. Hacking< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-troubleshooting.html" > 32. Troubleshooting< / a > < / li >
2019-04-23 18:55:23 +00:00
< / 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 >
2020-06-17 10:20:44 +00:00
< li > < span class = "section-number" > 20. < / span > Inventory< / li >
2019-04-23 18:55:23 +00:00
< 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" >
2021-04-20 05:50:28 +00:00
< section id = "inventory" >
2020-06-17 10:20:44 +00:00
< h1 > < span class = "section-number" > 20. < / span > Inventory< a class = "headerlink" href = "#inventory" title = "Permalink to this headline" > ¶< / a > < / h1 >
2021-04-20 05:50:28 +00:00
< section id = "introduction" >
2020-06-17 10:20:44 +00:00
< h2 > < span class = "section-number" > 20.1. < / span > Introduction< a class = "headerlink" href = "#introduction" title = "Permalink to this headline" > ¶< / a > < / h2 >
2019-04-23 18:55:23 +00:00
< 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 >
2021-04-20 05:50:28 +00:00
< / section >
< section id = "description" >
2020-06-17 10:20:44 +00:00
< h2 > < span class = "section-number" > 20.2. < / span > Description< a class = "headerlink" href = "#description" title = "Permalink to this headline" > ¶< / a > < / h2 >
2019-04-23 18:55:23 +00:00
< 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 >
2021-04-20 05:50:28 +00:00
< / section >
< section id = "cdist-inventory-interface" >
2020-06-17 10:20:44 +00:00
< h2 > < span class = "section-number" > 20.3. < / span > cdist inventory interface< a class = "headerlink" href = "#cdist-inventory-interface" title = "Permalink to this headline" > ¶< / a > < / h2 >
2019-04-23 18:55:23 +00:00
< 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 >
2021-04-20 05:50:28 +00:00
< / section >
< section id = "configuring-hosts-using-inventory" >
2020-06-17 10:20:44 +00:00
< h2 > < span class = "section-number" > 20.4. < / span > Configuring hosts using inventory< a class = "headerlink" href = "#configuring-hosts-using-inventory" title = "Permalink to this headline" > ¶< / a > < / h2 >
2019-04-23 18:55:23 +00:00
< 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 >
2021-04-20 05:50:28 +00:00
< / section >
< section id = "examples" >
2020-06-17 10:20:44 +00:00
< h2 > < span class = "section-number" > 20.5. < / span > Examples< a class = "headerlink" href = "#examples" title = "Permalink to this headline" > ¶< / a > < / h2 >
< div class = "highlight-sh notranslate" > < div class = "highlight" > < pre > < span > < / span > < span class = "c1" > # List inventory content< / span >
2019-04-23 18:55:23 +00:00
$ 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 >
2021-04-20 05:50:28 +00:00
< / section >
< section id = "example-of-manipulating-database" >
2020-06-17 10:20:44 +00:00
< h2 > < span class = "section-number" > 20.6. < / span > Example of manipulating database< a class = "headerlink" href = "#example-of-manipulating-database" title = "Permalink to this headline" > ¶< / a > < / h2 >
< div class = "highlight-sh notranslate" > < div class = "highlight" > < pre > < span > < / span > $ python3 scripts/cdist inventory list -b
2019-04-23 18:55:23 +00:00
$ 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 >
2021-04-20 05:50:28 +00:00
< / section >
< section id = "using-external-inventory" >
2020-06-17 10:20:44 +00:00
< h2 > < span class = "section-number" > 20.7. < / span > Using external inventory< a class = "headerlink" href = "#using-external-inventory" title = "Permalink to this headline" > ¶< / a > < / h2 >
2019-04-23 18:55:23 +00:00
< 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 >
2020-06-17 10:20:44 +00:00
< div class = "highlight-sh notranslate" > < 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
2019-04-23 18:55:23 +00:00
< / pre > < / div >
< / div >
2021-04-20 05:50:28 +00:00
< / section >
< / section >
2019-04-23 18:55:23 +00:00
< / div >
< / div >
< footer >
< div class = "rst-footer-buttons" role = "navigation" aria-label = "footer navigation" >
2019-05-22 16:44:06 +00:00
< a href = "cdist-trigger.html" class = "btn btn-neutral float-right" title = "21. Trigger" accesskey = "n" rel = "next" > Next < span class = "fa fa-arrow-circle-right" > < / span > < / a >
2019-04-23 18:55:23 +00:00
2019-05-22 16:44:06 +00:00
< 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 >
2019-04-23 18:55:23 +00:00
< / div >
< hr / >
< div role = "contentinfo" >
< p >
2021-07-20 08:29:04 +00:00
© Copyright ungleich GmbH 2021
2019-04-23 18:55:23 +00:00
< / 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 >