2016-06-17 19:28:16 +00:00
|
|
|
Explorer
|
|
|
|
========
|
2016-06-23 14:08:59 +00:00
|
|
|
|
2016-06-17 19:28:16 +00:00
|
|
|
Description
|
2011-03-09 09:16:46 +00:00
|
|
|
-----------
|
2017-06-30 15:01:07 +00:00
|
|
|
Explorers are small shell scripts, which will be executed on the target
|
|
|
|
host. The aim of each explorer is to give hints to types on how to act on the
|
2011-03-09 09:16:46 +00:00
|
|
|
target system. An explorer outputs the result to stdout, which is usually
|
|
|
|
a one liner, but may be empty or multi line especially in the case of
|
|
|
|
type explorers.
|
|
|
|
|
|
|
|
There are general explorers, which are run in an early stage, and
|
|
|
|
type explorers. Both work almost exactly the same way, with the difference
|
|
|
|
that the values of the general explorers are stored in a general location and
|
|
|
|
the type specific below the object.
|
|
|
|
|
2016-05-20 06:50:56 +00:00
|
|
|
Explorers can reuse other explorers on the target system by calling
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
$__explorer/<explorer_name> (general and type explorer)
|
|
|
|
|
|
|
|
or
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
$__type_explorer/<explorer name> (type explorer).
|
2011-03-09 09:16:46 +00:00
|
|
|
|
|
|
|
In case of significant errors, the explorer may exit non-zero and return an
|
2011-09-26 23:21:16 +00:00
|
|
|
error message on stderr, which will cause cdist to abort.
|
2011-03-09 09:16:46 +00:00
|
|
|
|
2011-03-09 09:17:43 +00:00
|
|
|
You can also use stderr for debugging purposes while developing a new
|
|
|
|
explorer.
|
2011-03-09 09:16:46 +00:00
|
|
|
|
2016-06-17 19:28:16 +00:00
|
|
|
Examples
|
2011-03-09 09:16:46 +00:00
|
|
|
--------
|
2016-05-20 06:50:56 +00:00
|
|
|
A very simple explorer may look like this::
|
2011-03-09 09:16:46 +00:00
|
|
|
|
2016-05-20 06:50:56 +00:00
|
|
|
hostname
|
2011-03-09 09:16:46 +00:00
|
|
|
|
2016-05-20 06:50:56 +00:00
|
|
|
Which is in practise the **hostname** explorer.
|
2011-03-09 09:16:46 +00:00
|
|
|
|
|
|
|
A type explorer, which could check for the status of a package may look like this:
|
|
|
|
|
2016-05-20 06:50:56 +00:00
|
|
|
.. code-block:: sh
|
|
|
|
|
|
|
|
if [ -f "$__object/parameter/name" ]; then
|
|
|
|
name="$(cat "$__object/parameter/name")"
|
|
|
|
else
|
|
|
|
name="$__object_id"
|
|
|
|
fi
|
2011-03-09 09:16:46 +00:00
|
|
|
|
2016-05-20 06:50:56 +00:00
|
|
|
# Expect dpkg failing, if package is not known / installed
|
|
|
|
dpkg -s "$name" 2>/dev/null || exit 0
|