hostlist

Package: WA2L/edrc 1.5.57
Section: Library Commands (3)
Updated: 23 December 2021
Index Return to Main Contents

 

NAME

hostlist - return a list of hosts

 

SYNOPSIS

edrc/lib/hostlist [ -h ]

hostlist

hostlist [ -g hostgroupname{[,hostgroupname]} ][ -l ]

hostlist -p

hostlist -i | -y | -j

 

AVAILABILITY

WA2L/edrc

 

DESCRIPTION

The hostlist command returns a list of hosts.

The intention is, that the output generated by hostlist is used as input for scripts or commands which compute commands/jobs on this list of hosts. Therefore there is only one source list of hosts being part of an environment and when a host is added/removed to/from it, only the edrc/etc/hostlist.cfg configuration file has to be adjusted and not all scripts which have to deal with a list of hosts.

hostlist can be used together with the server_environment(3) command in the configuration file edrc/etc/hostlist.cfg to enable hostlist to return the list of hosts that are part of a certain named server environment. E.g. the list of hosts in the PRODUCTION environment is different from the list of hosts in the DEVELOPMENT environment for an enterprise. See hostlist.cfg(4) for more information.

To compute different sets of hosts as returned by a call of hostlist, it is possible to define groups of hosts that can be accessed via a hostgroupname. This enables the abstraction of a group of hosts to a group name ( @HOSTGROUP ).

On complex configurations the resolution performance might decrease. To avoid this, the resolution cache can be used ( CACHE=True in edrc/etc/hostlist.cfg ). The cache data depends on the timestamps and filesizes of a configurable set of files ( CACHE_DEPENDENCY= file_1 file_2 ... file_n-1 file_n ), the hostlist(3) and server_environment(3) command files, and the hostname as resolved by hostname(1). The resolution cache is read/write for the WA2L/edrc owner and read only for all other users.

 

OPTIONS

return the list of hosts being part of the current server environment. See also server_environment(3) for information about the definition of server environments.

-h
usage message.

-g hostgroupname_list
comma separated list of hostgroupname. The convention is, that hostgroups always start with the @ character.

-l
the returned list of hosts is comma separated instead of space separated (=default). This eases further processing of the output as handing over the output to the -t option of rcmd.

-p
print all configured host groups in human readable form. The item listed without a HOSTGROUP name is the output of hostlist when used without an option.

The HOSTGROUPs having a name starting with an underscore ( _ ) should *not* be used interactively, due to the fact that the convention is, that those HOSTGROUPs are used internally within configuration files only.

-i
print all configured host groups as Ansible inventory ini file format.

The HOSTGROUPs having a name starting with an underscore ( _ ) are HOSTGROUPs that are used internally in WA2L/edrc within configuration files.

-y
print all configured host groups as Ansible inventory yaml file format.

The HOSTGROUPs having a name starting with an underscore ( _ ) are HOSTGROUPs that are used internally in WA2L/edrc within configuration files.

-j
print all configured host groups as Ansible inventory json file format.

The HOSTGROUPs having a name starting with an underscore ( _ ) are HOSTGROUPs that are used internally in WA2L/edrc within configuration files.

 

ENVIRONMENT

-

 

EXIT STATUS

0
no error.

2
a file that is defined in the CACHE_DEPENDENCY file list does not exist.

4
usage printed.

6
configuration file edrc/etc/hostlist.cfg does not exist.

 

FILES

edrc/etc/hostlist.cfg
configuration file of hostlist. this file contains all host list and host group definitions.

edrc/var/cache/hostlist/
resolution cache of the hostlist command if the CACHE setting in the configuration file edrc/etc/hostlist.cfg is set to True.

edrc/var/cache/hostlist/meta
meta data for the resolution cache. This file is used to check if the cache data is still valid.

edrc/var/cache/hostlist/data
this file contains the cache data, the resolved HOSTLIST and HOSTGRPS settings for the system where hostlist has been executed.

edrc/var/samples/hostlist/
configuration examples for hostlist(3) and server_environment(3).

 

EXAMPLES

1) command line usage example

[ /home/wilma ]
[ wilma@adm_db1_prod ][-ksh]: ~edrc/lib/hostlist

dcdbsi20 dcdbsi21 dcdbsi30 dcdbsi31 dcdbsi32 dcdbsi33

2) command line usage example using a hostgroup

[ /home/wilma ]
[ wilma@adm_db1_prod ][-ksh]: ~edrc/lib/hostlist -g @ADM

adm_db1_mnt adm_db1_tst adm_db1_pre adm_db1_prod

3) use of hostlist in configuration files

The use of hostlist in configuration files eases the configuration due to the fact that the target list of hosts can be centralized to one single configuration file ( the edrc/etc/hostlist.cfg file ) and changes in the server environment will be propagated to all tools used.

Example of the use of hostlist in the edrc/etc/edrc.cfg configuration file:

:
:

# Space separated list of hosts. To this hosts
# the files in SCRIPTS_BASEDIR will be distributed.
#
DIST_HOSTLIST="`hostlist -g @_DIST`"

:
:

Example of the use of hostlist in the edrc/etc/passwdsyncd.cfg configuration file:

:
:

# Space separated list of hosts. To this hosts
# the password information will be distributed.
#
SYNC_HOSTLIST="`hostlist`"

:
:

4) usage in scripts

Print uptime of all systems in a server environment.

:
:

targets=`hostlist -l`
rcmd -n -t $targets -c "sysinfo -u" | sort

:
:

 

SEE ALSO

edrcintro(1), hostlist.cfg(4), hostlistdat2cfg(3), rcmd(1), resolve_targetlist(3), server_environment(3), edrc/var/samples/hostlist/

 

NOTES

The commands rcmd(3) and filedist(1) use hostlist internally to resolve the list of hosts being part of the server environment where logged in.

 

BUGS

-

 

AUTHOR

hostlist 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: 00:14:04 GMT, March 08, 2025