2011-03-07 22:35:58 +00:00
|
|
|
cdist-type(7)
|
2011-03-08 19:26:44 +00:00
|
|
|
=============
|
2011-02-07 17:13:04 +00:00
|
|
|
Nico Schottelius <nico-cdist--@--schottelius.org>
|
|
|
|
|
|
|
|
|
|
|
|
NAME
|
|
|
|
----
|
2011-03-07 22:35:58 +00:00
|
|
|
cdist-type - Functionality bundled
|
|
|
|
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
--------
|
2011-03-11 18:09:36 +00:00
|
|
|
__TYPE ID --parameter value [--parameter value ...]
|
|
|
|
|
|
|
|
__TYPE --parameter value [--parameter value ...] (for singletons)
|
2011-02-07 17:13:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
-----------
|
2011-03-07 22:35:58 +00:00
|
|
|
Types are the main component of cdist and define functionality. If you
|
|
|
|
use cdist, you'll write a type for every functionality you would like
|
|
|
|
to use.
|
|
|
|
|
|
|
|
|
2011-03-08 11:36:59 +00:00
|
|
|
HOW TO USE A TYPE
|
|
|
|
-----------------
|
|
|
|
You can use types from the initial manifest or the type manifest like a
|
|
|
|
normal command:
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
# Creates empty file /etc/cdist-configured
|
|
|
|
__file /etc/cdist-configured --type file
|
|
|
|
|
|
|
|
# Ensure tree is installed
|
|
|
|
__package tree --state installed
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
Internally cdist-type-emulator(1) will be called from cdist-manifest-run(1) to
|
|
|
|
save the given parameters into a cconfig database, so they can be accessed by
|
|
|
|
the manifest and gencode scripts of the type (see below).
|
|
|
|
|
2011-03-11 18:09:36 +00:00
|
|
|
A list of supported types can be found in the cdist-reference(7) manpage.
|
|
|
|
|
|
|
|
SINGLETON TYPES
|
|
|
|
---------------
|
|
|
|
If a type is flagged as a singleton, it may me used only once. This
|
|
|
|
is useful for types which can be used only once on a system. If a type
|
|
|
|
can only be used once, it does not take an
|
|
|
|
|
|
|
|
Example:
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
# __issue type manages /etc/issue
|
|
|
|
__issue
|
|
|
|
|
|
|
|
# Probably your own type - singletons may use parameters
|
|
|
|
__myfancysingleton --colour green
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2011-03-09 07:54:52 +00:00
|
|
|
|
2011-03-08 11:36:59 +00:00
|
|
|
|
2011-03-07 22:35:58 +00:00
|
|
|
HOW TO WRITE A NEW TYPE
|
|
|
|
-----------------------
|
|
|
|
A type consists of
|
|
|
|
|
2011-03-08 11:36:59 +00:00
|
|
|
- parameter (optional)
|
2011-03-07 22:35:58 +00:00
|
|
|
- manifest (optional)
|
2011-03-11 18:09:36 +00:00
|
|
|
- singleton (optional)
|
2011-03-07 22:35:58 +00:00
|
|
|
- explorer (optional)
|
2011-03-08 18:58:35 +00:00
|
|
|
- gencode (optional)
|
2011-03-07 22:35:58 +00:00
|
|
|
|
|
|
|
Types are stored below conf/type/. Their name should always be prefixed with
|
|
|
|
two underscores (__) to prevent collisions with other binaries in $PATH.
|
|
|
|
|
2011-03-07 23:13:57 +00:00
|
|
|
To begin a new type from a template, execute "cdist-type-template __NAME"
|
2011-03-08 11:36:59 +00:00
|
|
|
and cd conf/type/__NAME.
|
2011-03-07 22:35:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
DEFINING PARAMETERS
|
|
|
|
-------------------
|
2011-03-08 11:36:59 +00:00
|
|
|
Every type consists of optional and required parameters, which must
|
|
|
|
be created in a newline seperated file in parameters/required and
|
|
|
|
parameters/optional. If either or both missing, the type will have
|
|
|
|
no required, no optional or no parameters at all.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
echo servername >> conf/type/__nginx_vhost/parameter/required
|
|
|
|
echo logdirectory >> conf/type/__nginx_vhost/parameter/optional
|
|
|
|
--------------------------------------------------------------------------------
|
2011-03-07 22:35:58 +00:00
|
|
|
|
|
|
|
|
2011-03-08 11:36:59 +00:00
|
|
|
WRITING THE MANIFEST
|
|
|
|
--------------------
|
2011-03-08 11:47:51 +00:00
|
|
|
In the manifest of a type you can use other types, so your type extends
|
|
|
|
their functionality. A good example is the __package type, which in
|
|
|
|
a shortened version looks like this:
|
2011-03-08 11:36:59 +00:00
|
|
|
|
2011-03-08 11:47:51 +00:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
os="$(cat "$__global/explorer/os")"
|
|
|
|
case "$os" in
|
|
|
|
archlinux) type="pacman" ;;
|
|
|
|
debian|ubuntu) type="apt" ;;
|
|
|
|
gentoo) type="emerge" ;;
|
|
|
|
*)
|
|
|
|
echo "Don't know how to manage packages on: $os" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
__package_$type "$@"
|
|
|
|
--------------------------------------------------------------------------------
|
2011-02-23 12:55:42 +00:00
|
|
|
|
2011-03-08 11:47:51 +00:00
|
|
|
As you can see, the type can reference different environment variables,
|
|
|
|
which are documented in cdist-environment-variables(7).
|
2011-02-23 12:55:42 +00:00
|
|
|
|
2011-03-08 11:47:51 +00:00
|
|
|
Always ensure the manifest is executable, otherwise cdist will not be able
|
|
|
|
to execute it.
|
2011-02-07 22:34:18 +00:00
|
|
|
|
2011-03-08 19:26:44 +00:00
|
|
|
|
2011-03-11 18:09:36 +00:00
|
|
|
SINGLETON - ONLY INSTANCE ONLY
|
|
|
|
------------------------------
|
|
|
|
If you want to ensure that a type can only be used once per target, you can
|
|
|
|
mark it as a singleton: Just create the (empty) file "singleton" in your type
|
|
|
|
directory. This will also change the way your type must be called:
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
__YOURTYPE --parameter value
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
As you can see, the ID is omitted, because it does not make any sense, if your
|
|
|
|
type can be used only once.
|
|
|
|
|
|
|
|
|
2011-03-08 18:58:35 +00:00
|
|
|
THE TYPE EXPLORERS
|
|
|
|
------------------
|
2011-03-08 19:35:21 +00:00
|
|
|
If a type needs to explore specific details, it can provide type specific
|
|
|
|
explorers, which will be executed on the target for every created object.
|
|
|
|
|
|
|
|
The explorers are stored under the "explorer" directory below the type.
|
|
|
|
It could for instance contain code to check the md5sum of a file on the
|
|
|
|
client, like this (shortened version from real type __file):
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
if [ -f "$__object/parameter/destination" ]; then
|
|
|
|
destination="$(cat "$__object/parameter/destination")"
|
|
|
|
else
|
|
|
|
destination="/$__object_id"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -e "$destination" ]; then
|
|
|
|
md5sum < "$destination"
|
|
|
|
fi
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2011-03-08 18:58:35 +00:00
|
|
|
|
2011-03-08 11:47:51 +00:00
|
|
|
WRITING THE GENCODE SCRIPT
|
|
|
|
--------------------------
|
2011-03-08 19:26:44 +00:00
|
|
|
The gencode script can make use of the parameters, the global explorers
|
|
|
|
and the type specific explorers. The output (stdout) of this script is
|
|
|
|
saved by cdist and will be executed on the target.
|
|
|
|
|
|
|
|
If the gencode script encounters an error, it should print diagnostic
|
|
|
|
messages to stderr and exit non-zero. If you need to debug the gencode
|
|
|
|
script, you can write to stderr:
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
# Debug output to stderr
|
|
|
|
echo "My fancy debug line" >&2
|
|
|
|
|
|
|
|
# Output to be saved by cdist for execution on the target
|
|
|
|
echo "touch /etc/cdist-configured"
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
HINTS FOR TYPEWRITERS
|
|
|
|
----------------------
|
|
|
|
It must be assumed that the target is pretty dumb and thus does not have high
|
|
|
|
level tools like ruby installed. If a type requires specific tools to be present
|
|
|
|
on the target, there must be another type that provides this tool and the first
|
|
|
|
type should create an object of the specific type.
|
|
|
|
|
2011-03-14 22:12:14 +00:00
|
|
|
If your type wants to save temporay data, that may be used by other types
|
|
|
|
later on (for instance __file), you can save them in the subdirectory
|
|
|
|
"files" below $__object (but you must create it yourself). cdist will not touch
|
|
|
|
this directory.
|
|
|
|
|
|
|
|
If your type contains static files, it's also recommened to place them in
|
|
|
|
a folder named "files" within the type (again, because cdist guarantees to
|
|
|
|
never ever touch this folder).
|
2011-02-07 22:34:18 +00:00
|
|
|
|
2011-03-08 11:47:51 +00:00
|
|
|
HOW TO INCLUDE A TYPE INTO UPSTREAM CDIST
|
|
|
|
-----------------------------------------
|
|
|
|
If you think your type may be useful for others, ensure it works with the
|
|
|
|
current master branch of cdist and submit the git url containing the type for
|
|
|
|
inclusion to the mailinglist **cdist at cdist -- at -- l.schottelius.org**.
|
|
|
|
|
2011-03-09 12:06:23 +00:00
|
|
|
Ensure a corresponding manpage named man.text in asciidoc format with
|
|
|
|
the manpage-name "cdist-type__NAME" is included in the type directory.
|
2011-02-07 22:34:18 +00:00
|
|
|
|
2011-02-07 17:13:04 +00:00
|
|
|
|
|
|
|
SEE ALSO
|
|
|
|
--------
|
2011-03-08 11:36:59 +00:00
|
|
|
- cdist-manifest-run(1)
|
2011-03-08 19:26:44 +00:00
|
|
|
- cdist-stages(7)
|
2011-03-08 11:36:59 +00:00
|
|
|
|
2011-02-07 17:13:04 +00:00
|
|
|
|
|
|
|
COPYING
|
|
|
|
-------
|
2011-03-08 19:35:21 +00:00
|
|
|
Copyright \(C) 2011 Nico Schottelius. Free use of this software is
|
2011-02-07 17:13:04 +00:00
|
|
|
granted under the terms of the GNU General Public License version 3 (GPLv3).
|