Host generator

From techdocs
Revision as of 16:56, 27 Haziran 2022 by Plinich (talk | contribs) (Created page with "The '''host generator''' API is a way of automatically and consistly applying scripts to the contents of <code>hostlist.csv</code> to generate files to be installed on cfengine client hosts. A good example of this is the <code>/etc/hostname</code> file. Because <code>hostlist.csv</code> contains both the name and IP address of each known host its contents can be used to create an individual <code>/etc/hostname</code> that cfengine (or <code>cf-agent</code>,...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The host generator API is a way of automatically and consistly applying scripts to the contents of hostlist.csv to generate files to be installed on cfengine client hosts.

A good example of this is the /etc/hostname file. Because hostlist.csv contains both the name and IP address of each known host its contents can be used to create an individual /etc/hostname that cfengine (or cf-agent, actually) will install on each host.

Introduction to how host generators work

  1. On the cfengine hub there is a directory /usr/local/administration/host.generators,
  2. Inside this directory there is a subdirectory for each host generator. For example, the host generator for the /etc/hostname file for each client host is there and its subdirectory is called etc_hostname. As a second example, there's also a host generator for the automounter configuration files and its subdirectory is called autofs,
  3. The host generators are invoked by running the update_hosts script on the cfengine hub. It:
    1. Invokes the setup.sh script in each host generator subdirectory ONCE at the start of each run of update_hosts,
    2. It then iterates through each host line in hostlist.csv and then invokes the add_host.sh once per host per host generator passing the scripts the following parameters:
      1. A temporary persistent directory (shared with other generators)
      2. The unqualified host name
      3. The IP address of the host
      4. The host's host classes ('+'-separated)
      5. The host's file system exports if it's a server ('+'-separated)
    3. After all host lines have been processed the finish.sh script in each host generator subdirectory is executed ONCE.
  4. Generally, the host generators create files in directories in /usr/local/warehouse from whence cf-agent collects the files and installs them on the individual hosts.

At this stage it'd probably be most informative to look at individual host generators on the cfengine hub for more insight on how they work.