Skip to main content

Sync hostlist and builds config files for services.

Project description

hostlist

Hostlist reads yaml lists with information about hosts and generates config files and inventory for several services.

Quickstart

Example input files are in the tests directory. Hostlists are defined in the hostslists subdirectory, where the filename encodes the hosttype and institute attributes of the contained hosts.

Run buildfiles to generate the output. buildfiles --help shows the available options.

Configuration

The main configuration is in config.yml in the working directory. Hostlists are collected in a directory listed in config.yml.

Format of hostlists

The hostlists are files under hostlists. The file format is either hosttype-institute.yml or hosttype.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 a header and a list of hosts. 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 Groups

Each 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 < host

For groups a default is set in the config file. In the header and the host definition one can define lists groups and notgroups that 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).

Checks

Many checks are performed to ensure consistency and find mistakes before they are deployed:

  • IP range

    • hosts must have an IP in the given range
    • all hosts must fall into the IP ranges stated in the config
    • ipranges between files must not overlap (except iprange_allow_overlap is set)
  • IP, MAC and hostname must be unique

  • if user is set, it must be an existing user account (to detect machines belonging to users who no longer have an account)

  • if end_date is set, it must be in the future

To ignore failed tests list them in the ignore_checks list in your config.yml:

ignore_checks:
    - "end_date"
    - "user"
    - "nonunique"
    - "cnames"
    - "duplicates"
    - "missing_mac_ip"
    - "iprange_overlap"

Services

At the moment the supported services are:

  • /etc/hosts, can also be used for dnsmasq
  • dhcpd
  • ansible inventory
  • munin
  • ssh_known_hosts generation

Web daemon

You can start hostlist-daemon to serve the generated content (dns,dhcp,munin,...) via http. Start hostlist-daemon where you would run buildfiles. The web daemon is based on cherrypy and has a config file daemon.conf.

In addition there is a human readable web page generated with ansible-cmdb. Optional settings for ansible-cmd are:

ansible_cmdb:
  columns:
    - name
    - ram
    - comment
    - main_ip
  template: 'fancy_html'
  data: 
  fact_dirs:
    - facts

which can be tested by viewing the output of buildfiles --web > index.html in a web browser. Note that if you want to have various host variables listed you must add them to the ansiblevars dict 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 in fact_dirs (see the ansible-cmdb documentation).

Example

A working example for inputs and all configuration files can be found in tests.

DNSVS Synchronization

Besides generating config files, the hostlist can also be synchronized against DNSVS, which is the dns management system used by https://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-to https://netvs.scc.kit.edu/user/tokens.

With the token-file added, you can run buildfiles, which shows you a diff between dnsvs and the local files and gives the option to copy the local hostlist to dnsvs.

Tests

To run the tests: ::

cd tests; py.test

Contribute

Feel free to use the code and adjust it to your needs. Pull requests are welcome!

Style guide

The code should obey PEP8 (as enforced by flake8 or pylint) when possible.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hostlist-1.4.9.tar.gz (35.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hostlist-1.4.9-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

File details

Details for the file hostlist-1.4.9.tar.gz.

File metadata

  • Download URL: hostlist-1.4.9.tar.gz
  • Upload date:
  • Size: 35.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.5

File hashes

Hashes for hostlist-1.4.9.tar.gz
Algorithm Hash digest
SHA256 225a5fd9a305886fa1032ed4da0afcc18d67593a71a039884af0f1d07dd37384
MD5 8a782467eb548f158becab0fb6dc92b7
BLAKE2b-256 efb85fd7de0d53ba80a163f447e2753ad7a9474ff51204ac8845d0f223669608

See more details on using hashes here.

File details

Details for the file hostlist-1.4.9-py3-none-any.whl.

File metadata

  • Download URL: hostlist-1.4.9-py3-none-any.whl
  • Upload date:
  • Size: 34.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.5

File hashes

Hashes for hostlist-1.4.9-py3-none-any.whl
Algorithm Hash digest
SHA256 a7066835be4abfac1c48524f79861aeee35c141a1a49e96ce2dc81a560eddd4f
MD5 fe82f41048c7aac73358cd228fa50b02
BLAKE2b-256 1ee5e51cb1ccff526b22005bad385233c6b400f28c1a2e9d325345c10857bffe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page