From 32f878ad00fc36716b5cbaa6f17a47f0e70ae774 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 12 Aug 2013 11:42:00 +0200 Subject: [PATCH] update docs, document exit code bug Signed-off-by: Nico Schottelius --- cdist/config_install.py | 5 +-- docs/man/man1/cdist.text | 57 ++++++++++++++++++-------- docs/man/man7/cdist-best-practice.text | 39 ++++++++++++++---- scripts/cdist | 8 +++- 4 files changed, 79 insertions(+), 30 deletions(-) diff --git a/cdist/config_install.py b/cdist/config_install.py index f179972f..045c8a43 100644 --- a/cdist/config_install.py +++ b/cdist/config_install.py @@ -28,6 +28,7 @@ import time import pprint import cdist +import cdist.context from cdist import core class ConfigInstall(object): @@ -107,11 +108,7 @@ class ConfigInstall(object): def onehost(cls, host, args, parallel): """Configure or install ONE system""" - # FIXME: Refactor relict - remove later - log = logging.getLogger("cdist") - try: - import cdist.context context = cdist.context.Context( target_host=host, diff --git a/docs/man/man1/cdist.text b/docs/man/man1/cdist.text index 113454a7..8faff66c 100644 --- a/docs/man/man1/cdist.text +++ b/docs/man/man1/cdist.text @@ -5,40 +5,51 @@ Nico Schottelius NAME ---- -cdist - Configuration management +cdist - Usable Configuration Management SYNOPSIS -------- -cdist [-h] [-V] +cdist [-h] [-d] [-v] [-V] {banner,config,shell} ... -cdist banner +cdist banner [-h] [-d] [-v] cdist config [-h] [-d] [-V] [-c CONF_DIR] [-i MANIFEST] [-p] [-s] host [host ...] +cdist shell [-h] [-d] [-v] [-s SHELL] DESCRIPTION ----------- cdist is the frontend executable to the cdist configuration management. -cdist supports different as explained below. The options to the main -program are: +cdist supports different subcommands as explained below. + +GENERAL +------- +All commands except the following options: + +-d, --debug:: + Set log level to debug -h, --help:: Show the help screen +-v, --verbose: + Set log level to info, be more verbose + -V, --version:: Show version and exit BANNER -------- -Displays the cdist banner. +------ +Displays the cdist banner. Useful for printing +cdist posters - a must have for every office. CONFIG ------ -Configure a system +Configure one or more hosts -h, --help:: Show the help screen @@ -52,9 +63,6 @@ Configure a system --conf-dir argument have higher precedence over those set through the environment variable. --d, --debug:: - Enable debug output - -i MANIFEST, --initial-manifest MANIFEST:: Path to a cdist manifest or - to read from stdin @@ -70,20 +78,27 @@ Configure a system --remote-exec REMOTE_EXEC: Command to use for remote execution (should behave like ssh) +SHELL +----- +This command allows you to + +-s/--shell:: + Select shell to use, defaults to current shell + EXAMPLES -------- -------------------------------------------------------------------------------- # Configure ikq05.ethz.ch with debug enabled -cdist config -d ikq05.ethz.ch +% cdist config -d ikq05.ethz.ch # Configure hosts in parallel and use a different configuration directory -cdist config -c ~/p/cdist-nutzung \ +% cdist config -c ~/p/cdist-nutzung \ -p ikq02.ethz.ch ikq03.ethz.ch ikq04.ethz.ch # Use custom remote exec / copy commands -cdist config --remote-exec /path/to/my/remote/exec \ +% cdist config --remote-exec /path/to/my/remote/exec \ --remote-copy /path/to/my/remote/copy \ -p ikq02.ethz.ch ikq03.ethz.ch ikq04.ethz.ch @@ -91,10 +106,18 @@ cdist config --remote-exec /path/to/my/remote/exec \ cdist banner # Show help -cdist --help +% cdist --help # Show Version -cdist --version +% cdist --version + +# Enter a shell that has access to emulated types +% cdist shell +% __git +usage: __git --source SOURCE [--state STATE] [--branch BRANCH] + [--group GROUP] [--owner OWNER] [--mode MODE] object_id + + -------------------------------------------------------------------------------- @@ -125,5 +148,5 @@ SEE ALSO COPYING ------- -Copyright \(C) 2011-2012 Nico Schottelius. Free use of this software is +Copyright \(C) 2011-2013 Nico Schottelius. Free use of this software is granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/docs/man/man7/cdist-best-practice.text b/docs/man/man7/cdist-best-practice.text index 818c423a..a254d10b 100644 --- a/docs/man/man7/cdist-best-practice.text +++ b/docs/man/man7/cdist-best-practice.text @@ -118,7 +118,7 @@ The following **.git/config** is taken from a a real world scenario: url = git://git.schottelius.org/cdist fetch = +refs/heads/*:refs/remotes/upstream/* -# Same as upstream, but works when being offline +# Same as upstream, but works when being offline [remote "local"] fetch = +refs/heads/*:refs/remotes/local/* url = /home/users/nico/p/cdist @@ -167,7 +167,7 @@ TEMPLATING * create directory templates/ in your type (convention) * create the template as an executable file like templates/basic.conf.sh, it will output text using shell variables for the values --------------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- #!/bin/sh # in the template, use cat << eof (here document) to output the text # and use standard shell variables in the template @@ -182,19 +182,42 @@ server { error_log /var/log/nginx/$SERVERNAME_error.log } EOF --------------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- * in the manifest, export the relevant variables and add the following lines in your manifest: --------------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- # export variables needed for the template export SERVERNAME='test" export ROOT='/var/www/test' # render the template mkdir -p "$__object/files" "$__type/templates/basic.conf.sh" > "$__object/files/basic.conf" -# send the rendered template - __file /etc/nginx/sites-available/test.conf --state present --source "$__object/files/basic.conf" --------------------------------------------------------------------------------------- +# send the rendered template + __file /etc/nginx/sites-available/test.conf \ + --state present + --source "$__object/files/basic.conf" +-------------------------------------------------------------------------------- + + +TESTING A NEW TYPE +------------------ +If you want to test a new type on a node, you can tell cdist to only use an +object of this type: Use the '--initial-manifest' parameter +with - (stdin) as argument and feed object into stdin +of cdist: + +-------------------------------------------------------------------------------- +# Singleton type without parameter +echo __ungleich_munin_server | cdist --initial-manifest - munin.panter.ch + +# Singleton type with parameter +echo __ungleich_munin_node --allow 1.2.3.4 | \ + cdist --initial-manifest - rails-19.panter.ch + +# Normal type +echo __file /tmp/stdintest --mode 0644 | \ + cdist --initial-manifest - cdist-dev-01.ungleich.ch +-------------------------------------------------------------------------------- SEE ALSO -------- @@ -204,5 +227,5 @@ SEE ALSO COPYING ------- -Copyright \(C) 2011-2012 Nico Schottelius. Free use of this software is +Copyright \(C) 2011-2013 Nico Schottelius. Free use of this software is granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/scripts/cdist b/scripts/cdist index 83035f5d..6a61faf4 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -167,10 +167,16 @@ if __name__ == "__main__": commandline() except KeyboardInterrupt: - exit_code = 2 + pass + + # FIXME: We always get exit code = 130 + # exit_code = 2 + # does not make a difference except cdist.Error as e: log.error(e) exit_code = 1 + #sys.exit(20) + #print("ok2 %s" % exit_code) sys.exit(exit_code)