hostlistdat2cfg

Package: WA2L/edrc 1.5.57
Section: Library Commands (3)
Updated: 13 May 2013
Index Return to Main Contents

 

NAME

hostlistdat2cfg - generate hostlist.cfg from hostlist.dat

 

SYNOPSIS

edrc/lib/hostlistdat2cfg [ -h ]

hostlistdat2cfg [ -o ]

hostlistdat2cfg [ -f file ... ][ central_opt ][ action_opt ][ env_opt ]

central_opt ::= -m
[[ XGRPS_PREF=string ][ XGRPS_LEGACY ][ MGRPS_LIST=hostgrouplist ]]

action_opt  ::= -a
{[ print_cfg ][ -o ] | list_dat [ type_opt ] | list_res [ type_opt ]}

env_opt     ::= -n
CUSTOMER.NAME

type_opt    ::= -t
{ table | csv | csv_header }

 

AVAILABILITY

WA2L/edrc

 

DESCRIPTION

convert a hostlist.dat file that has the structure

Example:

  #
  # Format:
  #
  #   <CUSTOMER>;<ENVIRONMENT>;<GROUPS>;<OPTIONS>;<HOSTS>
  #
  ACME;DEVELOPMENT   ;@APP  ;;host-001 host-002;
  ACME;DEVELOPMENT   ;@DB   ;;host-003;
  ACME;TEST          ;@APP  ;;host-101 host-103;
  ACME;PREPRODUCTION ;@APP  ;;host-201 host-202 host-205;
  ACME;PRODUCTION    ;@APP  ;;host-303 host-308 host-309;

into settings that can be used in the hostlist.cfg file.

This command will significantly simplify the definition of host lists of large environments and will make the more complicated constructs obsolete where using the fmatch(3) command in the hostlist.cfg(4) configuration file.

Despite the many options that the hostlistdat2cfg provides, normally only the -m and the -o options will be used in the hostlist.cfg config file. See also samples in the edrc/var/samples/hostlist directory.

 

OPTIONS

-h
print usage message.

-o
write configuration to temporary file and return the name of the the temporary file.

The output is written to a temporary directory that is generated by the maketemp(3) command internally. Therefore the tempfile can be removed using removetemp(3) later:

    out=`hostlistdat2cfg -o`
    . $out
    removetemp -q -d `dirname ${out}`

-f file...
a list of csv files. If this option is not specified, the edrc/etc/hostlist.dat file is read by default.

The csv files is a semicolon separated file having the format as explained below. Rows can span multiple lines in the file, if they end with a backslash ( \).

To verify the syntax of the csv file, use the command hostlistdat2cfg -a list_dat -f file which will only list the correct rows.

Format:

CUSTOMER;ENVIRONMENT;GROUPS;OPTIONS;HOSTS;

Keys:

CUSTOMER
Customer name as returned by server_environment -C.

ENVIRONMENT
Environment name as returned by server_environment. If this field is left empty, the row is valid for all environments of the CUSTOMER.

GROUPS
Space separated list of hostgroups ( @HOSTGRP ) as known from the hostlist(3) command.

The GROUPs @ALL and @_DIST are generated automatically out of all hosts specified in the HOSTS field for the ENVIRONMENTs of a CUSTOMER.

If certain host(s) should be excluded from the @ALL or @_DIST group, specify -@ALL or -@_DIST in the GROUPS field.

OPTIONS
Additional options for a row. Currently this field is not resolved and should be left empty.

HOSTS
space separated list of hosts.

-m [ options ]
options:

XGRPS_PREF=string
cross env HOSTGRPS prefix (default="")

XGRPS_LEGACY
also create legacy customer HOSTGRPS omitting .ALL.

MGRPS_LIST=hostgrouplist
comma separated HOSTGRPS to be merged.

-a action
action:

print_cfg
print the hostlist.cfg configuration structure. If no action is given, this is the default action.

list_dat
list the data of the given csv ( hostlist.dat ) file(s). This option can be used to check if the syntax of the processed csv file(s) is correct, because only correct columns are printed.

list_res
list resolved hostlist.dat file for the related environment. This option can also be used for further data processing.

-t type
type:

table
list in table format. If no type is given, this is the default output type.

csv
list in csv format. When using this option, only the data rows are listed.

csv_header
list the header row for the csv output.

-n CUSTOMER.NAME
set the CUSTOMER and ENVIRONMENT name.

This enables to test a configuration for an certain environment without logging in to it.

If this option is not used, the default is the customer name and environment of the server where logged on as returned by server_environment -C (=CUSTOMER) and server_environment (=NAME).

 

ENVIRONMENT

-

 

EXIT STATUS

0
no error.

4
usage message printed.

 

FILES

edrc/etc/hostlist.dat
configuration file of hostlistdat2cfg. This file contains all host list and host group definitions.

 

EXAMPLES

1) print config for environment where logged on:

hostlistdat2cfg

2) print central management config for environment where logged on:

hostlistdat2cfg -m

3) print central management config for environment where logged on and merge all operating system groups (@SOLARIS, @LINUX ...) that are defined in all customer environments:

hostlistdat2cfg -m MGRPS_LIST=@LINUX,@SOLARIS,@HPUX

With that the local @ANY.SOLARIS group will contain all hosts that are member of @SOLARIS groups in all customer environments.

4) use hostlistdat2cfg in etc/hostlist.dat:

USE_HOSTLIST_DAT=True
CMAN_ENVIRONMENT="Highlander.ADMIN"

if [ "$USE_HOSTLIST_DAT" = True ]; then
    case `server_environment -C`.`server_environment` in
        $CMAN_ENVIRONMENT)
           out=`hostlistdat2cfg -o -m MGRPS_LIST=@LINUX,@SOLARIS,@HPUX`;;
        *) out=`hostlistdat2cfg -o`;;
    esac
    . $out; removetemp -q -d `dirname ${out}`; return 0
fi

5) example with complete file set server_environment.cfg, hostlist.cfg and hostlist.dat

edrc/etc/server_environment.cfg

  #
  # server_environment.cfg - config for server_environment
  #
  # [00] 24.07.2004 CWa Initial Version
  # [50] 18.04.2013 CWa chg: cleanup
  #

  # Server environment definition.
  #
  # If you log on to a system, the <NAME> field of the
  # first matching <server_regex> will be returned. 
  #

  #
  #  Format:
  #    <NAME>:<Description>:<server_regex>:<Customer>:
  #

  # Highlander (the 'one and only' central administration environment)
  #
  ADMIN:Datactr Schaffhausen, Central ADMIN:adm-(linux|hpux|solaris):Highlander:
  REPORT:Datactr Schaffhausen, Central ADMIN:rpt-[0-9]+):Highlander:

  # ACME
  #
  PRODUCTION:Datacenter Bern, PRODUCTION Env:host-3[0-9][0-9]:ACME:
  PREPRODUCTION:Datacenter Boston, Integration Env:host-2[0-9][0-9]:ACME:
  TEST:Datacenter Plano, Test Env:host-1[0-9][0-9]:ACME:
  DEVELOPMENT:Datacenter San Jose, Development Env:host-0[0-9][0-9]:ACME:

edrc/etc/hostlist.cfg

  #
  # etc/hostlist.cfg - configuration of hostlist
  #
  # [00] 16.02.2004 CWa   Initial Version
  # [64] 16.03.2013 CWa   chg: use of hostlistdat2cfg
  #


  # Set USE_HOSTLIST_DAT to True, if hosts are listed in
  # the etc/hostlist.dat file, if hosts are defined directly
  # in etc/hostlist.cfg, set USE_HOSTLIST_DAT to False.
  #
  USE_HOSTLIST_DAT=True


  # Define the central administration environment in the 
  # format CUSTOMER.NAME as defined in server_environment.cfg.
  #
  CMAN_ENVIRONMENT="Highlander.ADMIN"


  # Read hostlist.dat definitions as resolved.
  #
  if [ "$USE_HOSTLIST_DAT" = True ]; then
      case `server_environment -C`.`server_environment` in
          $CMAN_ENVIRONMENT)
             out=`hostlistdat2cfg -o -m MGRPS_LIST=@LINUX,@SOLARIS,@HPUX`;;
          *) out=`hostlistdat2cfg -o`;;
      esac
      . $out; removetemp -q -d `dirname ${out}`; return 0
  fi


  # List of hosts when defined directly in the hostlist.cfg
  # file.
  #
  # The only compulsory settings in the hostlist.cfg file are
  # HOSTLIST and HOSTGRPS, everything else is for convenience
  # only and could be removed. See also: hostlist.cfg (4).
  #
  case `server_environment -C`.`server_environment` in
      Dummy.DUMMY)
          HOSTLIST="
                   "
          HOSTGRPS="@_DIST:
                    @ALL:
                   "
          ;;
  esac

edrc/etc/hostlist.dat

  #
  # etc/hostlist.dat - hostlist csv database file
  #
  # [00] 12.08.2008 CWa   Initial Version
  # [58] 16.03.2013 CWa   chg: to hostlistdat2cfg structure
  #

  #
  # Format:
  #
  #   <CUSTOMER>;<ENVIRONMENT>;<GROUPS>;<OPTIONS>;<HOSTS>
  #
  #   To verify the syntax, use: hostlistdat2cfg -a dat 
  #   Only correct entries will be listed.
  #
  Highlander  ;ADMIN          ;       ;;adm-linux adm-hpux adm-solaris;
  Highlander  ;REPORT         ;       ;;rpt-001 rpt-002;
  ACME        ;DEVELOPMENT    ;@APP   ;;host-001 host-002;
  ACME        ;DEVELOPMENT    ;@DB    ;;host-003;
  ACME        ;TEST           ;       ;;host-101 host-103;
  ACME        ;PREPRODUCTION  ;       ;;host-201 host-203 host-205;
  ACME        ;PRODUCTION     ;       ;;host-303 host-308 host-309;
  ACME        ;               ;@PING  ;;ping-001 ping-002 ping-003;

resulting configuration on ACME.TEST

  #
  # hostlist.cfg - configuration for hostlist
  #
  # [00] 03.05.2013 root  generated by: /opt/edrc/lib/hostlistdat2cfg
  #
  # resolved for:
  #
  #  SERVER_ENVIRONMENT_CUSTOMER: ACME
  #  SERVER_ENVIRONMENT_NAME:     TEST
  #
  CACHE=True

  CACHE_DEPENDENCY="etc/hostlist.cfg etc/server_environment.cfg
                    etc/hostlist.dat lib/hostlistdat2cfg"

  HOSTLIST="
           host-101 host-103
  "

  HOSTGRPS="
      @_DIST:
           host-001 host-002 host-003
           host-101 host-103
           host-201 host-203 host-205
           host-303 host-308 host-309

      @PING:
           ping-001 ping-002 ping-003

      @ALL:
           host-001 host-002 host-003
           host-101 host-103
           host-201 host-203 host-205
           host-303 host-308 host-309
           ping-001 ping-002 ping-003

  "
  export HOSTLIST HOSTGRPS CACHE CACHE_DEPENDENCY

resulting configuration on Highlander.ADMIN

  #
  # hostlist.cfg - configuration for hostlist
  #
  # [00] 03.05.2013 root  generated by: /opt/edrc/lib/hostlistdat2cfg
  #
  # resolved for:
  #
  #  SERVER_ENVIRONMENT_CUSTOMER: Highlander
  #  SERVER_ENVIRONMENT_NAME:     ADMIN
  #
  CACHE=True

  CACHE_DEPENDENCY="etc/hostlist.cfg etc/server_environment.cfg
                    etc/hostlist.dat lib/hostlistdat2cfg"

  HOSTLIST="
           adm-hpux adm-linux adm-solaris
  "

  HOSTGRPS="
      @Highlander.ADMIN:
           adm-hpux adm-linux adm-solaris

      @ACME.TEST:
           host-101 host-103

      @ACME.PREPRODUCTION:
           host-201 host-203 host-205

      @ACME.PRODUCTION:
           host-303 host-308 host-309

      @ACME.DEVELOPMENT:
           host-001 host-002 host-003

      @ACME.ALL:
           host-001 host-002 host-003
           host-101 host-103 host-201
           host-203 host-205
           host-303 host-308 host-309
           ping-001 ping-002 ping-003

      @ANY.ALL:
           adm-hpux adm-linux adm-solaris
           host-001 host-002 host-003
           host-101 host-103
           host-201 host-203 host-205
           host-303 host-308 host-309
           ping-001 ping-002 ping-003
           rpt-001 rpt-002

      @ACME.DEVELOPMENT.APP:
           host-001 host-002

      @Highlander.ALL:
           adm-hpux adm-linux adm-solaris
           rpt-001 rpt-002

      @_DIST:
           adm-hpux adm-linux adm-solaris
           rpt-001 rpt-002

      @Highlander.REPORT:
           rpt-001 rpt-002

      @ACME.DEVELOPMENT.DB:
           host-003

      @ACME.ANY.PING:
           ping-001 ping-002 ping-003

      @ALL:
           adm-hpux adm-linux adm-solaris
           rpt-001 rpt-002

  "
  export HOSTLIST HOSTGRPS CACHE CACHE_DEPENDENCY

 

SEE ALSO

edrcintro(1), edrcsetup(1m), hostlist(3), hostlist.cfg(4), hostlist.dat(4), server_environment(3), edrc/var/samples/hostlist/

 

NOTES

-

 

BUGS

-

 

AUTHOR

hostlistdat2cfg was developed by Christian Walther. Send suggestions and bug reports to wa2l@users.sourceforge.net .

 

COPYRIGHT

Copyright © 2013 Christian Walther

This is free software; see edrc/doc/COPYING for copying conditions. There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


 

Index

NAME
SYNOPSIS
AVAILABILITY
DESCRIPTION
OPTIONS
ENVIRONMENT
EXIT STATUS
FILES
EXAMPLES
SEE ALSO
NOTES
BUGS
AUTHOR
COPYRIGHT

This document was created by man2html using the manual pages.
Time: 16:53:11 GMT, August 28, 2024