update docs, document exit code bug

Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
Nico Schottelius 2013-08-12 11:42:00 +02:00
parent 8fddb1692f
commit 32f878ad00
4 changed files with 79 additions and 30 deletions

View file

@ -28,6 +28,7 @@ import time
import pprint import pprint
import cdist import cdist
import cdist.context
from cdist import core from cdist import core
class ConfigInstall(object): class ConfigInstall(object):
@ -107,11 +108,7 @@ class ConfigInstall(object):
def onehost(cls, host, args, parallel): def onehost(cls, host, args, parallel):
"""Configure or install ONE system""" """Configure or install ONE system"""
# FIXME: Refactor relict - remove later
log = logging.getLogger("cdist")
try: try:
import cdist.context
context = cdist.context.Context( context = cdist.context.Context(
target_host=host, target_host=host,

View file

@ -5,40 +5,51 @@ Nico Schottelius <nico-cdist--@--schottelius.org>
NAME NAME
---- ----
cdist - Configuration management cdist - Usable Configuration Management
SYNOPSIS 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 config [-h] [-d] [-V] [-c CONF_DIR] [-i MANIFEST] [-p] [-s] host [host ...]
cdist shell [-h] [-d] [-v] [-s SHELL]
DESCRIPTION DESCRIPTION
----------- -----------
cdist is the frontend executable to the cdist configuration management. cdist is the frontend executable to the cdist configuration management.
cdist supports different as explained below. The options to the main cdist supports different subcommands as explained below.
program are:
GENERAL
-------
All commands except the following options:
-d, --debug::
Set log level to debug
-h, --help:: -h, --help::
Show the help screen Show the help screen
-v, --verbose:
Set log level to info, be more verbose
-V, --version:: -V, --version::
Show version and exit Show version and exit
BANNER BANNER
------- ------
Displays the cdist banner. Displays the cdist banner. Useful for printing
cdist posters - a must have for every office.
CONFIG CONFIG
------ ------
Configure a system Configure one or more hosts
-h, --help:: -h, --help::
Show the help screen Show the help screen
@ -52,9 +63,6 @@ Configure a system
--conf-dir argument have higher precedence over those set through the --conf-dir argument have higher precedence over those set through the
environment variable. environment variable.
-d, --debug::
Enable debug output
-i MANIFEST, --initial-manifest MANIFEST:: -i MANIFEST, --initial-manifest MANIFEST::
Path to a cdist manifest or - to read from stdin Path to a cdist manifest or - to read from stdin
@ -70,20 +78,27 @@ Configure a system
--remote-exec REMOTE_EXEC: --remote-exec REMOTE_EXEC:
Command to use for remote execution (should behave like ssh) 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 EXAMPLES
-------- --------
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
# Configure ikq05.ethz.ch with debug enabled # 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 # 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 -p ikq02.ethz.ch ikq03.ethz.ch ikq04.ethz.ch
# Use custom remote exec / copy commands # 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 \ --remote-copy /path/to/my/remote/copy \
-p ikq02.ethz.ch ikq03.ethz.ch ikq04.ethz.ch -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 cdist banner
# Show help # Show help
cdist --help % cdist --help
# Show Version # 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 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). granted under the terms of the GNU General Public License version 3 (GPLv3).

View file

@ -118,7 +118,7 @@ The following **.git/config** is taken from a a real world scenario:
url = git://git.schottelius.org/cdist url = git://git.schottelius.org/cdist
fetch = +refs/heads/*:refs/remotes/upstream/* fetch = +refs/heads/*:refs/remotes/upstream/*
# Same as upstream, but works when being offline # Same as upstream, but works when being offline
[remote "local"] [remote "local"]
fetch = +refs/heads/*:refs/remotes/local/* fetch = +refs/heads/*:refs/remotes/local/*
url = /home/users/nico/p/cdist url = /home/users/nico/p/cdist
@ -167,7 +167,7 @@ TEMPLATING
* create directory templates/ in your type (convention) * 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 * create the template as an executable file like templates/basic.conf.sh, it will output text using shell variables for the values
-------------------------------------------------------------------------------------- --------------------------------------------------------------------------------
#!/bin/sh #!/bin/sh
# in the template, use cat << eof (here document) to output the text # in the template, use cat << eof (here document) to output the text
# and use standard shell variables in the template # and use standard shell variables in the template
@ -182,19 +182,42 @@ server {
error_log /var/log/nginx/$SERVERNAME_error.log error_log /var/log/nginx/$SERVERNAME_error.log
} }
EOF EOF
-------------------------------------------------------------------------------------- --------------------------------------------------------------------------------
* in the manifest, export the relevant variables and add the following lines in your manifest: * in the manifest, export the relevant variables and add the following lines in your manifest:
-------------------------------------------------------------------------------------- --------------------------------------------------------------------------------
# export variables needed for the template # export variables needed for the template
export SERVERNAME='test" export SERVERNAME='test"
export ROOT='/var/www/test' export ROOT='/var/www/test'
# render the template # render the template
mkdir -p "$__object/files" mkdir -p "$__object/files"
"$__type/templates/basic.conf.sh" > "$__object/files/basic.conf" "$__type/templates/basic.conf.sh" > "$__object/files/basic.conf"
# send the rendered template # send the rendered template
__file /etc/nginx/sites-available/test.conf --state present --source "$__object/files/basic.conf" __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 SEE ALSO
-------- --------
@ -204,5 +227,5 @@ SEE ALSO
COPYING 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). granted under the terms of the GNU General Public License version 3 (GPLv3).

View file

@ -167,10 +167,16 @@ if __name__ == "__main__":
commandline() commandline()
except KeyboardInterrupt: 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: except cdist.Error as e:
log.error(e) log.error(e)
exit_code = 1 exit_code = 1
#sys.exit(20)
#print("ok2 %s" % exit_code)
sys.exit(exit_code) sys.exit(exit_code)