Package: hostlist
hostlistHostlist reads yaml lists with information about hosts and generates
config files and inventory for several services.QuickstartExample input files are in thetestsdirectory. Hostlists are defined in thehostslistssubdirectory, where the filename
encodes thehosttypeandinstituteattributes of the contained hosts.Runbuildfilesto generate the output.buildfiles --helpshows the available options.ConfigurationThe main configuration is inconfig.ymlin the working directory.
Hostlists are collected in a directory listed inconfig.yml.Format of hostlistsThe hostlists are files underhostlists. The file format is eitherhosttype-institute.ymlorhosttype.yml, i.e. 0 or 1 dash. The filename will
be parsed and set as institute/hosttype for all hosts in that file.The hostlists are in yaml. Multiple yaml documents in one file are allows. Each
yaml document starts with a line containing only---.Each yaml document document has aheaderand a list ofhosts.
The header has to have an iprange, that lists the allowed range for the hosts in
the file. It can also set variables and groups.The hostlist is a list of dicts, which each need a hostname and an ip and can
take other variables.Variables and GroupsEach host has a list of variables (dict) associated with it as well as a list of groups (set).If variables are set in multiple places they are overwritten in this order:
filename < header < hostFor groups a default is set in the config file.
In the header and the host definition one can define listsgroupsandnotgroupsthat are added/subtracted from the list of
groups for that host.Groups are used to define which hosts are used in some outputs (muninnode, ssh_known_hosts) or which hosts should be included for
checks (needs_ip, needs_mac).ChecksMany checks are performed to ensure consistency and find mistakes before they
are deployed:IP rangehosts must have an IP in the given rangeall hosts must fall into the IP ranges stated in the configipranges between files must not overlap (except iprange_allow_overlap is set)IP, MAC and hostname must be uniqueifuseris set, it must be an existing user account (to detect machines
belonging to users who no longer have an account)ifend_dateis set, it must be in the futureTo ignore failed tests list them in theignore_checkslist in yourconfig.yml:ignore_checks:-"end_date"-"user"-"nonunique"-"cnames"-"duplicates"-"missing_mac_ip"-"iprange_overlap"ServicesAt the moment the supported services are:/etc/hosts, can also be used for dnsmasqdhcpdansible inventorymuninssh_known_hosts generationWeb daemonYou can starthostlist-daemonto serve the generated content (dns,dhcp,munin,...) via http. Starthostlist-daemonwhere you would runbuildfiles. The web daemon is based on cherrypy and has a config file daemon.conf.In addition there is a human readable web page generated withansible-cmdb. Optional settings for ansible-cmd are:ansible_cmdb:columns:-name-ram-comment-main_iptemplate:'fancy_html'data:fact_dirs:-factswhich can be tested by viewing the output ofbuildfiles --web > index.htmlin a web browser.
Note that if you want to have various host variables listed you must add them to theansiblevarsdict in the config.yml in order to have them in the ansible inventory.
Since buildfiles does not execute ansible on any remote host, there are no host facts (ram,cpu,vendors,disk usage...) available. However, one can supply these informations via fact caching from previous ansible runs via the directories listed infact_dirs(see the ansible-cmdb documentation).ExampleA working example for inputs and all configuration files can be found intests.DNSVS SynchronizationBesides generating config files, the hostlist can also be synchronized against
DNSVS, which is the dns management system used byhttps://www.scc.kit.edu.In order to use the DNSVS interface you need an API token , which is expected in ~/.config/netdb_client.ini. In order to generate the token, log-in/got-tohttps://netvs.scc.kit.edu/user/tokens.With the token-file added, you can runbuildfiles, which shows you a
diff between dnsvs and the local files and gives the option to copy the local
hostlist to dnsvs.TestsTo run the tests:
::cd tests; py.testContributeFeel free to use the code and adjust it to your needs.
Pull requests are welcome!Style guideThe code should obey PEP8 (as enforced by flake8 or pylint) when possible.