Merge branch 'master' into preos

Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>

Conflicts:
	docs/changelog
This commit is contained in:
Nico Schottelius 2013-12-04 14:44:54 +01:00
commit 84eb05aed6
19 changed files with 468 additions and 59 deletions

View file

@ -0,0 +1,20 @@
Allow cross-type communication
Sending notifications is possible from
- manifest
- gencode-local
- gencode-remote
Sending a notification from an object means writing to the file "notifications" into
its object:
echo mytest >> "$__object/notifications" # a type reports something
Reading / Reacting on notifications works by accessing the file
referred to be "$__notifications". All notifications are prefixed with
the object name ($__object_name) and are appended into this file.
To find out, whether a file was copied, run:
grep __file/etc/passwd:copy "$__notifications"

View file

@ -0,0 +1,49 @@
An alternative / complementary approach to notifications: triggers (or actions?)
A type may support various actions by creating files in its subdirectory
"actions". Other types can trigger an action of a different type or object
by calling them (indirectly?):
if grep "__file/etc/nginx/conf.d/.*:copy" "$__notifications"; then
# Call action from a type
cdist trigger __nginx/reload
fi
Not sure whether this approach (calling "actions" of other types) is sane,
as nginx should probably better know if it should be restarted "itself".
--------------------------------------------------------------------------------
Alternate approach:
__nginx_vhost www.some-domain.ch --custom << eof
some custom code for __nginx_vhost inclusion
eof
__nginx_vhost:
manifest:
# __nginx_vhost requires __nginx: creates directories
require"$__object_name" __nginx --require-only
# Do WE or __file ... depend on nginx?
cdist require __nginx
# Create file that contains the giving code
__file /etc/nginx/conf.d/www.some-domain.ch
require="__nginx" __file /etc/nginx/conf.d/www.some-domain.ch
__nginx:
manifest:
__package nginx --state present
__file some-custom-files
gencode-remote:
if first_install or file changed:

View file

@ -0,0 +1,50 @@
Follow up from 2013-01-20:
- (re-)create message file per object?
- yes, but do not necessarily save in object space
- save $anywhere
- object_run
- current notifications are imported into a file available at $__messages_in
- after object run, everything that has been written to $__messages_out is merged into the $__messages file
- functions:
self.explorer.run_global_explorers(self.local.global_explorer_out_path)
self.manifest.run_initial_manifest(self.local.initial_manifest)
self.local.run_script(initial_manifest, env=self.env_initial_manifest(initial_manifest))
self.explorer.run_type_explorers(cdist_object)
self.manifest.run_type_manifest(cdist_object)
self.local.run_script(type_manifest, env=self.env_type_manifest(cdist_object))
self.code.run_gencode_local(cdist_object)
self.local.run_script(script, env=env, return_output=True)
self.code.run_gencode_remote(cdist_object)
self.local.run_script(script, env=env, return_output=True)
- message support in ...
- initialmanifest - yes
- explorer - no
- only locally - yes
- how to use notification / messaging in cdist
- can be used in all local scripts:
- initial manifest
- type manifest
- type gencode-*
- order of object exeution is random or as you requested using require=""
- example use:
__file/gencode-local:
if [ "$local_cksum" != "$remote_cksum" ]; then
echo "$__remote_copy" "$source" "${__target_host}:${destination}"
echo "copy" >> "$__messages_out"
fi
__nginx/manifest:
__file /etc/nginx/sites-enabled/myfile --source "$__type/files/nginx-config"
__nginx/gencode-remote:
if grep -q "__file/etc/nginx/sites-enabled/myfile:copy" "$__messages_in"; then
echo /etc/init.d/nginx restart
fi