Merge branch 'master' of https://github.com/telmich/cdist into bugfix_type__key_value

New functionality for remote __object is needed
This commit is contained in:
Daniel Heule 2014-03-21 09:23:44 +01:00
commit 807e2902ea
13 changed files with 173 additions and 11 deletions

View file

@ -0,0 +1,49 @@
cdist-type__rbenv(7)
====================
Nico Schottelius <nico-cdist--@--schottelius.org>
NAME
----
cdist-type__rbenv - Manage rbenv installation
DESCRIPTION
-----------
This cdist type allows you to manage rbenv installations.
It also installs ruby-build.
OPTIONAL PARAMETERS
-------------------
state::
Either "present" or "absent", defaults to "present"
owner::
Which user should own the rbenv installation, defaults to root
EXAMPLES
--------
--------------------------------------------------------------------------------
# Install rbenv including ruby-build for nico
__rbenv /home/nico
# Install rbenv including ruby-build for nico
__rbenv /home/nico --owner nico
# Bastian does not need rbenv anymore, he began to code C99
__rbenv /home/bastian --state absent
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
COPYING
-------
Copyright \(C) 2012-2014 Nico Schottelius. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

View file

@ -0,0 +1,38 @@
#!/bin/sh
#
# 2012-2014 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
homedir="$__object_id"
state_should="$(cat "$__object/parameter/state")"
owner="$(cat "$__object/parameter/owner")"
rbenvdir="$homedir/.rbenv"
rubybuilddir="$rbenvdir/plugins/ruby-build"
__git "$rbenvdir" \
--source git://github.com/sstephenson/rbenv.git \
--owner "$owner" \
--state "$state_should"
require="__git/$rbenvdir" __git "$rubybuilddir" \
--source git://github.com/sstephenson/ruby-build.git \
--owner "$owner" \
--state "$state_should"

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1 @@
state

View file

@ -0,0 +1 @@
owner

View file

@ -58,6 +58,7 @@ if [ ! -f "$__object/parameter/noparent" -o ! -f "$__object/parameter/nofile" ];
fi
# Remove legacy blocks created by old versions of this type
# FIXME: remove me in 3.2+
__block "$__object_name" \
--file "$file" \
--prefix "#cdist:$__object_name" \

View file

@ -2,6 +2,7 @@
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2011-2013 Nico Schottelius (nico-cdist at schottelius.org)
# 2014 Daniel Heule (hda at sfs.biz)
#
# This file is part of cdist.
#
@ -123,15 +124,27 @@ class Code(object):
self.remote.mkdir(destination)
self.remote.transfer(source, destination)
def _run_code(self, cdist_object, which):
def _run_code(self, cdist_object, which, env=None):
which_exec = getattr(self, which)
script = os.path.join(which_exec.object_path, getattr(cdist_object, 'code_%s_path' % which))
return which_exec.run_script(script)
return which_exec.run_script(script, env=env)
def run_code_local(self, cdist_object):
"""Run the code-local script for the given cdist object."""
return self._run_code(cdist_object, 'local')
# Put some env vars, to allow read only access to the parameters over $__object
env = os.environ.copy()
env.update(self.env)
env.update({
'__object': cdist_object.absolute_path,
'__object_id': cdist_object.object_id,
})
return self._run_code(cdist_object, 'local', env=env)
def run_code_remote(self, cdist_object):
"""Run the code-remote script for the given cdist object on the remote side."""
return self._run_code(cdist_object, 'remote')
# Put some env vars, to allow read only access to the parameters over $__object which is already on the remote side
env = {
'__object': os.path.join(self.remote.object_path, cdist_object.path),
'__object_id': cdist_object.object_id,
}
return self._run_code(cdist_object, 'remote', env=env)