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" >
2019-01-25 15:18:27 +00:00
< title > 19. Inventory — cdist 4.10.5-270-g0dc94fb5 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
2019-01-25 15:18:27 +00:00
< 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 = "20. Trigger" href = "cdist-trigger.html" / >
< link rel = "prev" title = "18. Parallelization" href = "cdist-parallelization.html" / >
2016-11-27 15:32:05 +00:00
< script src = "_static/js/modernizr.min.js" > < / script >
< / head >
2019-01-25 15:18:27 +00:00
< body class = "wy-body-for-nav" >
2016-11-27 15:32:05 +00:00
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" >
2019-01-25 15:18:27 +00:00
4.10.5-270-g0dc94fb5
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 >
2019-01-25 15:18:27 +00:00
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-real-world.html" > 9. Dive into real world cdist< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "man1/cdist.html" > 10. cdist(1)< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-bootstrap.html" > 11. Bootstrap< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-configuration.html" > 12. Configuration< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-manifest.html" > 13. Manifest< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-type.html" > 14. cdist type< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-types.html" > 15. cdist types< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-explorer.html" > 16. Explorer< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-messaging.html" > 17. Messaging< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-parallelization.html" > 18. Parallelization< / a > < / li >
< li class = "toctree-l1 current" > < a class = "current reference internal" href = "#" > 19. Inventory< / a > < ul >
< li class = "toctree-l2" > < a class = "reference internal" href = "#introduction" > 19.1. Introduction< / a > < / li >
< li class = "toctree-l2" > < a class = "reference internal" href = "#description" > 19.2. Description< / a > < / li >
< li class = "toctree-l2" > < a class = "reference internal" href = "#cdist-inventory-interface" > 19.3. cdist inventory interface< / a > < / li >
< li class = "toctree-l2" > < a class = "reference internal" href = "#configuring-hosts-using-inventory" > 19.4. Configuring hosts using inventory< / a > < / li >
< li class = "toctree-l2" > < a class = "reference internal" href = "#examples" > 19.5. Examples< / a > < / li >
< li class = "toctree-l2" > < a class = "reference internal" href = "#example-of-manipulating-database" > 19.6. Example of manipulating database< / a > < / li >
< li class = "toctree-l2" > < a class = "reference internal" href = "#using-external-inventory" > 19.7. Using external inventory< / a > < / li >
2016-11-27 15:32:05 +00:00
< / ul >
< / li >
2019-01-25 15:18:27 +00:00
< li class = "toctree-l1" > < a class = "reference internal" href = "cdist-trigger.html" > 20. Trigger< / a > < / 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 >
2016-11-27 15:32:05 +00:00
< / ul >
< / div >
< / div >
< / nav >
< section data-toggle = "wy-nav-shift" class = "wy-nav-content-wrap" >
2019-01-25 15:18:27 +00:00
< nav class = "wy-nav-top" 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" >
2019-01-25 15:18:27 +00:00
2016-11-27 15:32:05 +00:00
< div class = "rst-content" >
2019-01-25 15:18:27 +00:00
2016-11-27 15:32:05 +00:00
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 > » < / li >
2019-01-25 15:18:27 +00:00
< li > 19. Inventory< / li >
2017-06-13 20:40:23 +00:00
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-inventory.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 = "inventory" >
2019-01-25 15:18:27 +00:00
< h1 > 19. Inventory< a class = "headerlink" href = "#inventory" title = "Permalink to this headline" > ¶< / a > < / h1 >
2016-11-27 15:32:05 +00:00
< div class = "section" id = "introduction" >
2019-01-25 15:18:27 +00:00
< h2 > 19.1. Introduction< a class = "headerlink" href = "#introduction" title = "Permalink to this headline" > ¶< / a > < / h2 >
2016-11-27 15:32:05 +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
2016-11-29 06:40:57 +00:00
command line flag is specified (-b, --beta) or setting CDIST_BETA env var.< / p >
2016-11-27 15:32:05 +00:00
< / div >
< div class = "section" id = "description" >
2019-01-25 15:18:27 +00:00
< h2 > 19.2. Description< a class = "headerlink" href = "#description" title = "Permalink to this headline" > ¶< / a > < / h2 >
2016-11-27 15:32:05 +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 >
< / div >
< div class = "section" id = "cdist-inventory-interface" >
2019-01-25 15:18:27 +00:00
< h2 > 19.3. cdist inventory interface< a class = "headerlink" href = "#cdist-inventory-interface" title = "Permalink to this headline" > ¶< / a > < / h2 >
2016-11-27 15:32:05 +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 >
< / div >
< div class = "section" id = "configuring-hosts-using-inventory" >
2019-01-25 15:18:27 +00:00
< h2 > 19.4. Configuring hosts using inventory< a class = "headerlink" href = "#configuring-hosts-using-inventory" title = "Permalink to this headline" > ¶< / a > < / h2 >
2016-11-27 15:32:05 +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 >
< / div >
< div class = "section" id = "examples" >
2019-01-25 15:18:27 +00:00
< h2 > 19.5. 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 >
2016-11-27 15:32:05 +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
2019-01-25 15:18:27 +00:00
< span class = "c1" > # Add tags to specified hosts< / span >
2016-11-27 15:32:05 +00:00
$ 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" >
2019-01-25 15:18:27 +00:00
< h2 > 19.6. 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
2016-11-27 15:32:05 +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
2017-06-13 20:40:23 +00:00
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
2016-11-27 15:32:05 +00:00
$ 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" >
2019-01-25 15:18:27 +00:00
< h2 > 19.7. Using external inventory< a class = "headerlink" href = "#using-external-inventory" title = "Permalink to this headline" > ¶< / a > < / h2 >
2016-11-27 15:32:05 +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 >
2019-01-25 15:18:27 +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
2016-11-27 15:32:05 +00:00
< / pre > < / div >
< / div >
< / div >
< / div >
2017-06-13 20:40:23 +00:00
< / div >
2019-01-25 15:18:27 +00:00
2016-11-27 15:32:05 +00:00
< / div >
< footer >
< div class = "rst-footer-buttons" role = "navigation" aria-label = "footer navigation" >
2019-01-25 15:18:27 +00:00
< a href = "cdist-trigger.html" class = "btn btn-neutral float-right" title = "20. Trigger" accesskey = "n" rel = "next" > Next < span class = "fa fa-arrow-circle-right" > < / span > < / a >
2016-11-27 15:32:05 +00:00
2019-01-25 15:18:27 +00:00
< a href = "cdist-parallelization.html" class = "btn btn-neutral" title = "18. Parallelization" 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 >
2019-01-25 15:18:27 +00:00
© Copyright
2016-11-27 15:32:05 +00:00
< / p >
< / div >
2019-01-25 15:18:27 +00:00
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 > .
2016-11-27 15:32:05 +00:00
< / footer >
< / div >
< / div >
< / section >
< / div >
2019-01-25 15:18:27 +00:00
< script type = "text/javascript" id = "documentation_options" data-url_root = "./" src = "_static/documentation_options.js" > < / 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 async = "async" type = "text/javascript" src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML" > < / script >
2016-11-27 15:32:05 +00:00
2019-01-25 15:18:27 +00:00
< script type = "text/javascript" src = "_static/js/theme.js" > < / script >
2016-11-27 15:32:05 +00:00
< script type = "text/javascript" >
jQuery(function () {
2019-01-25 15:18:27 +00:00
SphinxRtdTheme.Navigation.enable(true);
2016-11-27 15:32:05 +00:00
});
2019-01-25 15:18:27 +00:00
< / script >
2016-11-27 15:32:05 +00:00
< / body >
< / html >