From fe143d57b87ad0fce0b59b08dd255ecdde511778 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 5 Dec 2012 23:43:24 +0100 Subject: [PATCH 01/51] add new type: __rbenv Signed-off-by: Nico Schottelius --- cdist/conf/type/__rbenv/explorer/homedir | 25 +++++++++++++ cdist/conf/type/__rbenv/man.text | 43 ++++++++++++++++++++++ cdist/conf/type/__rbenv/manifest | 34 +++++++++++++++++ cdist/conf/type/__rbenv/parameter/optional | 1 + 4 files changed, 103 insertions(+) create mode 100755 cdist/conf/type/__rbenv/explorer/homedir create mode 100644 cdist/conf/type/__rbenv/man.text create mode 100644 cdist/conf/type/__rbenv/manifest create mode 100644 cdist/conf/type/__rbenv/parameter/optional diff --git a/cdist/conf/type/__rbenv/explorer/homedir b/cdist/conf/type/__rbenv/explorer/homedir new file mode 100755 index 00000000..8dc25535 --- /dev/null +++ b/cdist/conf/type/__rbenv/explorer/homedir @@ -0,0 +1,25 @@ +#!/bin/sh +# +# 2012 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 . +# +# +# Check whether repository exists +# + +user="$__object_id" +su - "$user" -c "pwd -P" diff --git a/cdist/conf/type/__rbenv/man.text b/cdist/conf/type/__rbenv/man.text new file mode 100644 index 00000000..bee57f76 --- /dev/null +++ b/cdist/conf/type/__rbenv/man.text @@ -0,0 +1,43 @@ +cdist-type__rbenv(7) +==================== +Nico Schottelius + + +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" + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# Install rbenv including ruby-build for nico +__rbenv nico + +# Bastian does not need rbenv anymore, he began to code C99 +__rbenv bastian --state absent +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2012 Nico Schottelius. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__rbenv/manifest b/cdist/conf/type/__rbenv/manifest new file mode 100644 index 00000000..2e8769a4 --- /dev/null +++ b/cdist/conf/type/__rbenv/manifest @@ -0,0 +1,34 @@ +#!/bin/sh +# +# 2012 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 . +# +# + +homedir="$(cat "$__object/explorer/homedir")" +state_should=present +[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" + +rbenvdir="$homedir/.rbenv" +rubybuilddir="$rbenvdir/plugins/ruby-build" + +__git "$rbenvdir" --source git://github.com/sstephenson/rbenv.git \ + --state "$state_should" + +require="__git/$rbendir" __git "$rubybuilddir" \ + --source git://github.com/sstephenson/ruby-build.git \ + --state "$state_should" diff --git a/cdist/conf/type/__rbenv/parameter/optional b/cdist/conf/type/__rbenv/parameter/optional new file mode 100644 index 00000000..ff72b5c7 --- /dev/null +++ b/cdist/conf/type/__rbenv/parameter/optional @@ -0,0 +1 @@ +state From ed7b6d1a68a68e9b12bb9740fc86842c167f21a7 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 6 Dec 2012 00:01:01 +0100 Subject: [PATCH 02/51] add linebreak, add broken require Signed-off-by: Nico Schottelius --- cdist/conf/type/__rbenv/manifest | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__rbenv/manifest b/cdist/conf/type/__rbenv/manifest index 2e8769a4..8f912861 100644 --- a/cdist/conf/type/__rbenv/manifest +++ b/cdist/conf/type/__rbenv/manifest @@ -26,9 +26,13 @@ state_should=present rbenvdir="$homedir/.rbenv" rubybuilddir="$rbenvdir/plugins/ruby-build" -__git "$rbenvdir" --source git://github.com/sstephenson/rbenv.git \ +__git "$rbenvdir" \ + --source git://github.com/sstephenson/rbenv.git \ + --owner "$__object_id" \ --state "$state_should" -require="__git/$rbendir" __git "$rubybuilddir" \ +#__git "$rubybuilddir" \ +require="__git/$rbenvdir" __git "$rubybuilddir" \ --source git://github.com/sstephenson/ruby-build.git \ + --owner "$__object_id" \ --state "$state_should" From 7df1f26c9aa37b50d240a65fb49220de4f1c9426 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 3 Jan 2013 13:01:34 +0100 Subject: [PATCH 03/51] +deps issue description Signed-off-by: Nico Schottelius --- docs/dev/logs/2013-01-03.dependency-issue | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 docs/dev/logs/2013-01-03.dependency-issue diff --git a/docs/dev/logs/2013-01-03.dependency-issue b/docs/dev/logs/2013-01-03.dependency-issue new file mode 100644 index 00000000..91db9425 --- /dev/null +++ b/docs/dev/logs/2013-01-03.dependency-issue @@ -0,0 +1,27 @@ + +Problem shown by using __rbenv: + +__rbenv/nicotest + __git /home/nico/.rbenv + __package git + __directory /home/nico/.rbenv + + require="__git/home/nico/.rbenv" + __git /home/nico/.rbenv/plugins/ruby-build + __package git + __directory /home/nico/.rbenv/plugins/ruby-build + + +1) if children do NOT automatically depend on their parents requiremnts + + __directory /home/nico/.rbenv/plugins/ruby-build fails: + because __directory /home/nico/.rbenv/plugins is created by + __git /home/nico/.rbenv, but __directory /home/nico/.rbenv/plugins/ruby-build + does not depend on __git /home/nico/.rbenv + +2) if children DO automatically depend on their parents requiremnts + __package git from __git /home/nico/.rbenv/plugins/ruby-build depends on __git /home/nico/.rbenv. + + __git /home/nico/.rbenv depends on __package git (via autorequire) + + => circular dependency, they depend on each other From e8f5d4c34039acc0df7d9feb357c2634df0088f2 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Thu, 13 Feb 2014 15:38:35 +0100 Subject: [PATCH 04/51] some new explorers wich are handy if you must tune for example sap or oracle to the systemtype, cpu cores and/or physical memory --- cdist/conf/explorer/cpu_cores | 31 ++++++++++++++++++ cdist/conf/explorer/cpu_sockets | 31 ++++++++++++++++++ cdist/conf/explorer/machine_type | 54 ++++++++++++++++++++++++++++++++ cdist/conf/explorer/memory | 27 ++++++++++++++++ 4 files changed, 143 insertions(+) create mode 100755 cdist/conf/explorer/cpu_cores create mode 100755 cdist/conf/explorer/cpu_sockets create mode 100755 cdist/conf/explorer/machine_type create mode 100755 cdist/conf/explorer/memory diff --git a/cdist/conf/explorer/cpu_cores b/cdist/conf/explorer/cpu_cores new file mode 100755 index 00000000..efabc848 --- /dev/null +++ b/cdist/conf/explorer/cpu_cores @@ -0,0 +1,31 @@ +#!/bin/sh +# +# 2014 Daniel Heule (hda at sfs.biz) +# 2014 Thomas Oettli (otho at sfs.biz) +# +# 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 . +# +# + +# FIXME: other system types (not linux ...) + +if [ -r /proc/cpuinfo ]; then + cores="$(cat /proc/cpuinfo | grep "core id" | sort | uniq | wc -l)" + if [ ${cores} -eq 0 ]; then + cores="1" + fi + echo "${cores}" +fi diff --git a/cdist/conf/explorer/cpu_sockets b/cdist/conf/explorer/cpu_sockets new file mode 100755 index 00000000..98836cec --- /dev/null +++ b/cdist/conf/explorer/cpu_sockets @@ -0,0 +1,31 @@ +#!/bin/sh +# +# 2014 Daniel Heule (hda at sfs.biz) +# 2014 Thomas Oettli (otho at sfs.biz) +# +# 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 . +# +# + +# FIXME: other system types (not linux ...) + +if [ -r /proc/cpuinfo ]; then + sockets="$(cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l)" + if [ ${sockets} -eq 0 ]; then + sockets="$(cat /proc/cpuinfo | grep "processor" | wc -l)" + fi + echo "${sockets}" +fi diff --git a/cdist/conf/explorer/machine_type b/cdist/conf/explorer/machine_type new file mode 100755 index 00000000..60b7f5e2 --- /dev/null +++ b/cdist/conf/explorer/machine_type @@ -0,0 +1,54 @@ +#!/bin/sh +# +# 2014 Daniel Heule (hda at sfs.biz) +# 2014 Thomas Oettli (otho at sfs.biz) +# +# 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 . +# +# + +# FIXME: other system types (not linux ...) + +if [ -r /proc/cpuinfo ]; then + # this should only exist on virtual guest machines, + # tested on vmware, xen, kvm + if grep -q "hypervisor" /proc/cpuinfo; then + # this file is aviable in xen guest systems + if [ -r /sys/hypervisor/type ]; then + if grep -q -i "xen" /sys/hypervisor/type; then + echo virtual by xen + exit + fi + else + if [ -r /sys/class/dmi/id/product_name ]; then + if grep -q -i 'vmware' /sys/class/dmi/id/product_name; then + echo "virtual by vmware" + exit + else + if grep -q -i 'bochs' /sys/class/dmi/id/product_name; then + echo "virtual by kvm" + exit + fi + fi + fi + fi + echo "virtual by unknown" + else + echo "physical" + fi +else + echo "unknown" +fi diff --git a/cdist/conf/explorer/memory b/cdist/conf/explorer/memory new file mode 100755 index 00000000..982b5dfa --- /dev/null +++ b/cdist/conf/explorer/memory @@ -0,0 +1,27 @@ +#!/bin/sh +# +# 2014 Daniel Heule (hda at sfs.biz) +# 2014 Thomas Oettli (otho at sfs.biz) +# +# 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 . +# +# + +# FIXME: other system types (not linux ...) + +if [ -r /proc/meminfo ]; then + echo "$(cat /proc/meminfo | grep "MemTotal:" | awk '{print $2}')" +fi From 95b1ac0706d0e6f127b78235dd89236053a92efe Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 14 Feb 2014 20:34:24 +0100 Subject: [PATCH 05/51] update rbenv type to cdist 3.0 style Signed-off-by: Nico Schottelius --- cdist/conf/type/__rbenv/explorer/homedir | 25 ------------------- cdist/conf/type/__rbenv/man.text | 12 ++++++--- cdist/conf/type/__rbenv/manifest | 14 +++++------ .../conf/type/__rbenv/parameter/default/state | 1 + cdist/conf/type/__rbenv/parameter/required | 1 + 5 files changed, 18 insertions(+), 35 deletions(-) delete mode 100755 cdist/conf/type/__rbenv/explorer/homedir create mode 100644 cdist/conf/type/__rbenv/parameter/default/state create mode 100644 cdist/conf/type/__rbenv/parameter/required diff --git a/cdist/conf/type/__rbenv/explorer/homedir b/cdist/conf/type/__rbenv/explorer/homedir deleted file mode 100755 index 8dc25535..00000000 --- a/cdist/conf/type/__rbenv/explorer/homedir +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh -# -# 2012 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 . -# -# -# Check whether repository exists -# - -user="$__object_id" -su - "$user" -c "pwd -P" diff --git a/cdist/conf/type/__rbenv/man.text b/cdist/conf/type/__rbenv/man.text index bee57f76..c6ed5de2 100644 --- a/cdist/conf/type/__rbenv/man.text +++ b/cdist/conf/type/__rbenv/man.text @@ -19,16 +19,22 @@ 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 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 bastian --state absent +__rbenv /home/bastian --state absent -------------------------------------------------------------------------------- @@ -39,5 +45,5 @@ SEE ALSO COPYING ------- -Copyright \(C) 2012 Nico Schottelius. Free use of this software is +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). diff --git a/cdist/conf/type/__rbenv/manifest b/cdist/conf/type/__rbenv/manifest index 8f912861..767abdba 100644 --- a/cdist/conf/type/__rbenv/manifest +++ b/cdist/conf/type/__rbenv/manifest @@ -1,6 +1,6 @@ #!/bin/sh # -# 2012 Nico Schottelius (nico-cdist at schottelius.org) +# 2012-2014 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -19,20 +19,20 @@ # # -homedir="$(cat "$__object/explorer/homedir")" -state_should=present -[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" +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 "$__object_id" \ + --owner "$owner" \ --state "$state_should" -#__git "$rubybuilddir" \ require="__git/$rbenvdir" __git "$rubybuilddir" \ --source git://github.com/sstephenson/ruby-build.git \ - --owner "$__object_id" \ + --owner "$owner" \ --state "$state_should" diff --git a/cdist/conf/type/__rbenv/parameter/default/state b/cdist/conf/type/__rbenv/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__rbenv/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__rbenv/parameter/required b/cdist/conf/type/__rbenv/parameter/required new file mode 100644 index 00000000..7ee3bde8 --- /dev/null +++ b/cdist/conf/type/__rbenv/parameter/required @@ -0,0 +1 @@ +owner From 478ebd190cf0f69a02dc5212389a8cebb43d7f76 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Fri, 14 Feb 2014 22:06:43 +0100 Subject: [PATCH 06/51] transfert idea into the file in git tree, so we can close issue 286 --- docs/dev/fancy-ideas | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/dev/fancy-ideas b/docs/dev/fancy-ideas index f125a884..8ee290cd 100644 --- a/docs/dev/fancy-ideas +++ b/docs/dev/fancy-ideas @@ -4,4 +4,14 @@ implemented as a proof of concept at: https://github.com/asteven/cdist/tree/type-namespaces + + +Execute all global explorers only when needed #286 +My intention is to create a brunch of global explorer which are of use in some cases and makes cdist more userfriendly. But now, all global explorers are allways executed, even the return value of the explorers is never used. + +I think a possible approach can be to replace the result files with pipes, and on first read of the pipe, the explorer is executed by the core, all following read calls from the pipe are answered from the core with the result of the first real execute of the explorer. + +So cdist can have an unlimited number of global explorers and only used explorers are executed on the target host, all other explorers laying around are simply ignored. + +Also a possible approach would be to create a new explorer type (dynamic explorers) which are sitting in a different directory to (for example dynexploer) and only this ones are executed with the conditional approach explained above. So the overhead to create pipes and monitor it is only in place on explorers which are not interesting for everyone ... From 4ce52c5a9d65fa5af4d492e56a1101a2ce7316a5 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 15 Feb 2014 11:31:39 +0100 Subject: [PATCH 07/51] -ws Signed-off-by: Nico Schottelius --- docs/changelog | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/changelog b/docs/changelog index 49a0a3c3..1dbc0787 100644 --- a/docs/changelog +++ b/docs/changelog @@ -21,7 +21,6 @@ Changelog * Type __rvm_gemset: Use default parameters for state (Daniel Heule) * Type __rvm_ruby: Use default parameters for state (Daniel Heule) - 3.0.8: 2014-02-11 * Core: Enhance object id verification (Daniel Heule) * Core: Add unit tests for dependencies based on execution order (Daniel Heule) From 9c6defe17c934796d3cb0d443be1cf4f1031181f Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 18 Feb 2014 20:17:08 +0100 Subject: [PATCH 08/51] unauthenticated problem Signed-off-by: Nico Schottelius --- .../logs/2014-02-18.unauthenticated-packages | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 docs/dev/logs/2014-02-18.unauthenticated-packages diff --git a/docs/dev/logs/2014-02-18.unauthenticated-packages b/docs/dev/logs/2014-02-18.unauthenticated-packages new file mode 100644 index 00000000..5fc6357b --- /dev/null +++ b/docs/dev/logs/2014-02-18.unauthenticated-packages @@ -0,0 +1,18 @@ +- we cannot install packages, which are not authenticated: + +INFO: voicerepublic-staging.sky.ungleich.ch: Executing code for __package_apt/deb-multimedia-keyring +Reading package lists... +Building dependency tree... +Reading state information... +The following NEW packages will be installed: + deb-multimedia-keyring + 0 upgraded, 1 newly installed, 0 to remove and 13 not upgraded. + Need to get 14.4 kB of archives. + After this operation, 46.1 kB of additional disk space will be used. + WARNING: The following packages cannot be authenticated! + deb-multimedia-keyring + E: There are problems and -y was used without --force-yes + ERROR: voicerepublic-staging.sky.ungleich.ch: Command failed: ssh -o User=root -q voicerepublic-staging.sky.ungleich.ch /bin/sh -e /var/lib/cdist/object/__package_apt/deb-multimedia-keyring/.cdist/code-remote + INFO: cdist: Total processing time for 1 host(s): 72.07943892478943 + ERROR: cdist: Failed to configure the following hosts: voicerepublic-staging.sky.ungleich.ch + From 68c1bf6633d3e6219211e11c25435dffb4b6e9d5 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Sat, 22 Feb 2014 00:51:26 +0100 Subject: [PATCH 09/51] preserve ownership and permissions of existing file Signed-off-by: Steven Armstrong --- cdist/conf/type/__line/gencode-remote | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__line/gencode-remote b/cdist/conf/type/__line/gencode-remote index 1fadf454..1ac1ad13 100755 --- a/cdist/conf/type/__line/gencode-remote +++ b/cdist/conf/type/__line/gencode-remote @@ -1,6 +1,7 @@ #!/bin/sh # # 2012 Nico Schottelius (nico-cdist at schottelius.org) +# 2014 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -74,8 +75,13 @@ case "$state_should" in fi cat << eof -tmp=\$(mktemp) -grep -v $greparg '$regex' '$file' > \$tmp && cat "\$tmp" > '$file' && rm -f "\$tmp" +tmpfile=\$(mktemp ${file}.cdist.XXXXXXXXXX) +# preserve ownership and permissions of existing file +if [ -f "$file" ]; then + cp -p "$file" "\$tmpfile" +fi +grep -v $greparg '$regex' '$file' > \$tmpfile +mv -f "\$tmpfile" "$file" eof ;; *) From 2fdff153d6f1c78693f7e49a9baa2b43cc668061 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Sat, 22 Feb 2014 00:51:54 +0100 Subject: [PATCH 10/51] dont fail if result is empty file Signed-off-by: Steven Armstrong --- cdist/conf/type/__line/gencode-remote | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__line/gencode-remote b/cdist/conf/type/__line/gencode-remote index 1ac1ad13..f73444e3 100755 --- a/cdist/conf/type/__line/gencode-remote +++ b/cdist/conf/type/__line/gencode-remote @@ -80,7 +80,7 @@ tmpfile=\$(mktemp ${file}.cdist.XXXXXXXXXX) if [ -f "$file" ]; then cp -p "$file" "\$tmpfile" fi -grep -v $greparg '$regex' '$file' > \$tmpfile +grep -v $greparg '$regex' '$file' > \$tmpfile || true mv -f "\$tmpfile" "$file" eof ;; From 16a829d3eb14cfdc338f1bba1a1dfcfb0be6841d Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Sat, 22 Feb 2014 01:09:42 +0100 Subject: [PATCH 11/51] manage individual keys instead of block of text also fixes #251 Signed-off-by: Steven Armstrong --- .../type/__ssh_authorized_keys/explorer/group | 22 +++++++++++ .../conf/type/__ssh_authorized_keys/man.text | 2 +- .../conf/type/__ssh_authorized_keys/manifest | 37 +++++++++++++------ 3 files changed, 49 insertions(+), 12 deletions(-) create mode 100755 cdist/conf/type/__ssh_authorized_keys/explorer/group diff --git a/cdist/conf/type/__ssh_authorized_keys/explorer/group b/cdist/conf/type/__ssh_authorized_keys/explorer/group new file mode 100755 index 00000000..cdea6fe7 --- /dev/null +++ b/cdist/conf/type/__ssh_authorized_keys/explorer/group @@ -0,0 +1,22 @@ +#!/bin/sh +# +# 2014 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +gid="$("$__type_explorer/passwd" | cut -d':' -f 4)" +getent group "$gid" || true diff --git a/cdist/conf/type/__ssh_authorized_keys/man.text b/cdist/conf/type/__ssh_authorized_keys/man.text index 7177f26e..259d4152 100644 --- a/cdist/conf/type/__ssh_authorized_keys/man.text +++ b/cdist/conf/type/__ssh_authorized_keys/man.text @@ -97,5 +97,5 @@ SEE ALSO COPYING ------- -Copyright \(C) 2012 Steven Armstrong. Free use of this software is +Copyright \(C) 2012-2014 Steven Armstrong. Free use of this software is granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__ssh_authorized_keys/manifest b/cdist/conf/type/__ssh_authorized_keys/manifest index 5a9cfbb3..01a29c37 100755 --- a/cdist/conf/type/__ssh_authorized_keys/manifest +++ b/cdist/conf/type/__ssh_authorized_keys/manifest @@ -1,6 +1,6 @@ #!/bin/sh # -# 2012 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012-2014 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -32,7 +32,7 @@ else fi if [ ! -f "$__object/parameter/noparent" -o ! -f "$__object/parameter/nofile" ]; then - group="$(cut -d':' -f 4 "$__object/explorer/passwd")" + group="$(cut -d':' -f 1 "$__object/explorer/group")" if [ -z "$group" ]; then echo "Failed to get owners group from explorer." >&2 exit 1 @@ -56,16 +56,31 @@ if [ ! -f "$__object/parameter/noparent" -o ! -f "$__object/parameter/nofile" ]; fi fi -# Generate entry for inclusion in authorized_keys file -( -if [ -f "$__object/parameter/comment" ]; then - echo "# $(cat "$__object/parameter/comment")" -fi -cat "$__object/parameter/key" -) | \ +# Remove legacy blocks created by old versions of this type __block "$__object_name" \ --file "$file" \ --prefix "#cdist:$__object_name" \ --suffix "#/cdist:$__object_name" \ - --state "$state" \ - --text - + --state 'absent' \ + --text - << DONE +remove legacy block +DONE + +_cksum() { + echo "$1" | cksum | cut -d' ' -f 1 +} + +# Add each key +IFS=$'\n' +for key in $(cat "$__object/parameter/key"); do + unset IFS + raw_key="$(echo "$key" | tr ' ' '\n' | awk '/^ssh-(rsa|dsa)/ {printf $1" ";getline;printf $1}')" + set -- "$(_cksum "$raw_key")" + set -- "$@" --file "$file" + set -- "$@" --regex ".*$raw_key.*" + if [ "$state" = 'present' ]; then + set -- "$@" --line "$key" + fi + set -- "$@" --state "$state" + require="__block/$__object_name" __line "$@" +done From 95f38d9d443fbceb7ed89f590df1932d16f21162 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Sat, 22 Feb 2014 01:12:41 +0100 Subject: [PATCH 12/51] remove no longer supported parameter --comment Signed-off-by: Steven Armstrong --- cdist/conf/type/__ssh_authorized_keys/man.text | 8 ++------ cdist/conf/type/__ssh_authorized_keys/parameter/optional | 1 - 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/cdist/conf/type/__ssh_authorized_keys/man.text b/cdist/conf/type/__ssh_authorized_keys/man.text index 259d4152..9fd683fd 100644 --- a/cdist/conf/type/__ssh_authorized_keys/man.text +++ b/cdist/conf/type/__ssh_authorized_keys/man.text @@ -40,9 +40,6 @@ state:: file:: an alternative destination file, defaults to ~$owner/.ssh/authorized_keys -comment:: - an optional comment - BOOLEAN PARAMETERS ------------------ @@ -67,12 +64,11 @@ __ssh_authorized_keys root \ __ssh_authorized_keys user-name \ --key "ssh-rsa AXYZAAB3NzaC1yc2..." -# same as above, but with explicit owner, two keys and a comment +# same as above, but with explicit owner and two keys __ssh_authorized_keys some-fancy-id \ --owner user-name \ --key "ssh-rsa AXYZAAB3NzaC1yc2..." \ - --key "ssh-rsa AZXYAAB3NzaC1yc2..." \ - --comment "allow the members of project foo to login" + --key "ssh-rsa AZXYAAB3NzaC1yc2..." # same as above, but authorized_keys file in non standard location __ssh_authorized_keys some-fancy-id \ diff --git a/cdist/conf/type/__ssh_authorized_keys/parameter/optional b/cdist/conf/type/__ssh_authorized_keys/parameter/optional index bfbd72ab..989750b3 100644 --- a/cdist/conf/type/__ssh_authorized_keys/parameter/optional +++ b/cdist/conf/type/__ssh_authorized_keys/parameter/optional @@ -1,4 +1,3 @@ owner state file -comment From d6b7033f2bb79e6243eb866f83cce43add1fba56 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 22 Feb 2014 10:13:51 +0100 Subject: [PATCH 13/51] ++changes Signed-off-by: Nico Schottelius --- docs/changelog | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/changelog b/docs/changelog index 1dbc0787..66a83b31 100644 --- a/docs/changelog +++ b/docs/changelog @@ -5,8 +5,10 @@ Changelog * Exception: No braces means author == Nico Schottelius -3.0.10: +next: * Type __git: Pass onwer/group/mode values to __directory + * Type __ssh_authorized_keys: Allow managing existing keys (Steven Armstrong) + 3.0.9: 2014-02-14 * Core: Ignore order dependencies if override is set (Daniel Heule) From 4e535b6b8bc1ceef209b63f24bcbc3067f29c6c5 Mon Sep 17 00:00:00 2001 From: Antoine Catton Date: Sun, 23 Feb 2014 20:22:06 -0700 Subject: [PATCH 14/51] Docfix: ssh service listen on port 22 --- cdist/conf/type/__iptables_rule/man.text | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__iptables_rule/man.text b/cdist/conf/type/__iptables_rule/man.text index eb230093..2f5b9785 100644 --- a/cdist/conf/type/__iptables_rule/man.text +++ b/cdist/conf/type/__iptables_rule/man.text @@ -41,7 +41,7 @@ __iptables_rule established --rule "-A INPUT -m state --state RELATED,ESTABLISH # Some service rules __iptables_rule http --rule "-A INPUT -p tcp --dport 80 -j ACCEPT" -__iptables_rule ssh --rule "-A INPUT -p tcp --dport 80 -j ACCEPT" +__iptables_rule ssh --rule "-A INPUT -p tcp --dport 22 -j ACCEPT" __iptables_rule https --rule "-A INPUT -p tcp --dport 443 -j ACCEPT" # Ensure some rules are not present anymore From ce0f779664e5808382134f12904553b30db65c22 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 24 Feb 2014 16:00:12 +0100 Subject: [PATCH 15/51] include the owner into the object_id for line Signed-off-by: Nico Schottelius --- cdist/conf/type/__ssh_authorized_keys/manifest | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__ssh_authorized_keys/manifest b/cdist/conf/type/__ssh_authorized_keys/manifest index 01a29c37..313e3b23 100755 --- a/cdist/conf/type/__ssh_authorized_keys/manifest +++ b/cdist/conf/type/__ssh_authorized_keys/manifest @@ -1,6 +1,7 @@ #!/bin/sh # # 2012-2014 Steven Armstrong (steven-cdist at armstrong.cc) +# 2014 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -75,7 +76,11 @@ IFS=$'\n' for key in $(cat "$__object/parameter/key"); do unset IFS raw_key="$(echo "$key" | tr ' ' '\n' | awk '/^ssh-(rsa|dsa)/ {printf $1" ";getline;printf $1}')" - set -- "$(_cksum "$raw_key")" + + cksum_key="$(_cksum "$raw_key")" + line_id="${owner}-${cksum_key}" + + set -- "$line_id" set -- "$@" --file "$file" set -- "$@" --regex ".*$raw_key.*" if [ "$state" = 'present' ]; then From a126bd955ff2aafc2e715a9fb9b7a5c515bcc0d2 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 24 Feb 2014 18:06:15 +0100 Subject: [PATCH 16/51] use while read -> avoids ifs problem Signed-off-by: Nico Schottelius --- cdist/conf/type/__ssh_authorized_keys/manifest | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/cdist/conf/type/__ssh_authorized_keys/manifest b/cdist/conf/type/__ssh_authorized_keys/manifest index 313e3b23..efcd2d7a 100755 --- a/cdist/conf/type/__ssh_authorized_keys/manifest +++ b/cdist/conf/type/__ssh_authorized_keys/manifest @@ -71,21 +71,17 @@ _cksum() { echo "$1" | cksum | cut -d' ' -f 1 } -# Add each key -IFS=$'\n' -for key in $(cat "$__object/parameter/key"); do - unset IFS - raw_key="$(echo "$key" | tr ' ' '\n' | awk '/^ssh-(rsa|dsa)/ {printf $1" ";getline;printf $1}')" - - cksum_key="$(_cksum "$raw_key")" +while read key; do + cksum_key="$(_cksum "$key")" line_id="${owner}-${cksum_key}" set -- "$line_id" set -- "$@" --file "$file" - set -- "$@" --regex ".*$raw_key.*" + set -- "$@" --regex ".*$key.*" if [ "$state" = 'present' ]; then set -- "$@" --line "$key" fi set -- "$@" --state "$state" - require="__block/$__object_name" __line "$@" -done + # Ensure __line does not read stdin + require="__block/$__object_name" __line "$@" < /dev/null +done < "$__object/parameter/key" From 1c0d74f7db1163b5f673d58ad0481f58c28ec74e Mon Sep 17 00:00:00 2001 From: og Date: Sun, 2 Mar 2014 17:18:25 -0700 Subject: [PATCH 17/51] openbsd stat works the same way that freebsd's does --- cdist/conf/type/__file/explorer/stat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__file/explorer/stat b/cdist/conf/type/__file/explorer/stat index 298221b7..52570379 100755 --- a/cdist/conf/type/__file/explorer/stat +++ b/cdist/conf/type/__file/explorer/stat @@ -25,7 +25,7 @@ destination="/$__object_id" os=$("$__explorer/os") case "$os" in - "freebsd") + "freebsd"|"openbsd") # FIXME: should be something like this based on man page, but can not test stat -f "type: %ST owner: %Du %Su From 5cbdf981c0003ba1b958ef7ba937404cc7cf71ed Mon Sep 17 00:00:00 2001 From: og Date: Sun, 2 Mar 2014 17:32:14 -0700 Subject: [PATCH 18/51] adding pkg_path parameter to be explicitly set, this is important for using -current, as os_version always parses to a release version (e.g. 5.5) but the path that mirrors have is /snapshots/ --- cdist/conf/type/__package_pkg_openbsd/gencode-remote | 8 ++++++-- cdist/conf/type/__package_pkg_openbsd/parameter/optional | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__package_pkg_openbsd/gencode-remote b/cdist/conf/type/__package_pkg_openbsd/gencode-remote index 1df87997..9d760655 100755 --- a/cdist/conf/type/__package_pkg_openbsd/gencode-remote +++ b/cdist/conf/type/__package_pkg_openbsd/gencode-remote @@ -50,8 +50,11 @@ fi pkg_version="$(cat "$__object/explorer/pkg_version")" -# TODO: Shouldn't be hardcoded -echo export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/$os_version/packages/$machine/ +if [ -f "$__object/parameter/pkg_path" ]; then + pkg_path="$(cat "$__object/parameter/pkg_path")" +else + pkg_path="ftp://ftp.openbsd.org/pub/OpenBSD/$os_version/packages/$machine/" +fi if [ "$pkg_version" ]; then state_is="present" @@ -65,6 +68,7 @@ case "$state_should" in present) # use this because pkg_add doesn't properly handle errors cat << eof +export PKG_PATH="$pkg_path" status=\$(pkg_add "$pkgopts" "$name--$flavor") # no error diff --git a/cdist/conf/type/__package_pkg_openbsd/parameter/optional b/cdist/conf/type/__package_pkg_openbsd/parameter/optional index 77fd22b3..43278d16 100644 --- a/cdist/conf/type/__package_pkg_openbsd/parameter/optional +++ b/cdist/conf/type/__package_pkg_openbsd/parameter/optional @@ -1,3 +1,4 @@ name flavor state +pkg_path From 6a455be63a874b7b63bdde34499f86222e749166 Mon Sep 17 00:00:00 2001 From: og Date: Sun, 2 Mar 2014 17:34:36 -0700 Subject: [PATCH 19/51] openbsd and freebsd both use the 'passwd' database --- cdist/conf/type/__user/explorer/shadow | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cdist/conf/type/__user/explorer/shadow b/cdist/conf/type/__user/explorer/shadow index a949ec51..59abaa8a 100755 --- a/cdist/conf/type/__user/explorer/shadow +++ b/cdist/conf/type/__user/explorer/shadow @@ -26,9 +26,10 @@ os="$($__explorer/os)" # Default to using shadow passwords database="shadow" -if [ "$os" = "freebsd" ]; then - database="passwd" -fi +case "$os" in + "freebsd"|"openbsd") database="passwd";; +esac + getent "$database" "$name" || true From ef1f9bf6331add3878fc3c4836e7cf49cb59c95a Mon Sep 17 00:00:00 2001 From: og Date: Sun, 2 Mar 2014 17:44:22 -0700 Subject: [PATCH 20/51] updated documentation to reflect new parameter --- cdist/conf/type/__package_pkg_openbsd/man.text | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cdist/conf/type/__package_pkg_openbsd/man.text b/cdist/conf/type/__package_pkg_openbsd/man.text index f523a892..c7de2652 100644 --- a/cdist/conf/type/__package_pkg_openbsd/man.text +++ b/cdist/conf/type/__package_pkg_openbsd/man.text @@ -29,6 +29,8 @@ flavor:: state:: Either "present" or "absent", defaults to "present" +pkg_path:: + Manually specify a PKG_PATH to add packages from. EXAMPLES -------- @@ -45,6 +47,10 @@ __package_pkg_openbsd python --state present --name python2 # Remove obsolete package __package_pkg_openbsd puppet --state absent + +# Add a package using a particular mirror +__package_pkg_openbsd bash \ + --pkg_path http://openbsd.mirrorcatalogs.com/snapshots/packages/amd64 -------------------------------------------------------------------------------- From 19f6126a0f6895a2b28ee58037d24d5b64f6809c Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 3 Mar 2014 07:42:27 +0100 Subject: [PATCH 21/51] ++changes Signed-off-by: Nico Schottelius --- docs/changelog | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/changelog b/docs/changelog index 66a83b31..e7ac935d 100644 --- a/docs/changelog +++ b/docs/changelog @@ -8,6 +8,10 @@ Changelog next: * Type __git: Pass onwer/group/mode values to __directory * Type __ssh_authorized_keys: Allow managing existing keys (Steven Armstrong) + * Type __iptable_rule: Fix example documentation (Antoine Catton) + * Type __file: Enhance OpenBSD Support (og) + * Type __package_pkg_openbsd: Allow to change PKG_PATH (og) + * Type __user: Enhance OpenBSD Support (og) 3.0.9: 2014-02-14 From 3fffb93150a57786b6db1c1406b93a17bf727e64 Mon Sep 17 00:00:00 2001 From: og Date: Mon, 3 Mar 2014 14:59:50 -0700 Subject: [PATCH 22/51] OpenBSD pkg utils does not return properly, so we have to verify success by looking at the list of installed packages after the present/absent actions --- .../type/__package_pkg_openbsd/gencode-remote | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/cdist/conf/type/__package_pkg_openbsd/gencode-remote b/cdist/conf/type/__package_pkg_openbsd/gencode-remote index 9d760655..7583167e 100755 --- a/cdist/conf/type/__package_pkg_openbsd/gencode-remote +++ b/cdist/conf/type/__package_pkg_openbsd/gencode-remote @@ -69,12 +69,17 @@ case "$state_should" in # use this because pkg_add doesn't properly handle errors cat << eof export PKG_PATH="$pkg_path" -status=\$(pkg_add "$pkgopts" "$name--$flavor") +status=\$(pkg_add "$pkgopts" "$name--$flavor" 2>&1) +pkg_info | grep "^${name}.*${flavor}" > /dev/null 2>&1 -# no error -if [ -n "\$status" ]; then +# We didn't find the package in the list of 'installed packages', so it failed +# This is necessary because pkg_add doesn't return properly +if [ $? -ne 0 ]; then + if [ -z "${status}" ]; then + status="Failed to add package, uncaught exception." + fi echo "Error: \$status" - exit 1 + exit 1 fi eof ;; @@ -83,9 +88,14 @@ eof # use this because pkg_add doesn't properly handle errors cat << eof status=\$(pkg_delete "$pkgopts" "$name--$flavor") +pkg_info | grep "^${name}.*${flavor}" > /dev/null 2>&1 -# no error -if [ -n "\$status" ]; then +# We found the package in the list of 'installed packages' +# This would indicate that pkg_delete failed, send the output of pkg_delete +if [ $? -eq 0 ]; then + if [ -z "${status}" ]; then + status="Failed to remove package, uncaught exception." + fi echo "Error: \$status" exit 1 fi From 074938c697f2671d384f774ecf80d4ee5e2d2c32 Mon Sep 17 00:00:00 2001 From: og Date: Mon, 3 Mar 2014 15:13:57 -0700 Subject: [PATCH 23/51] . --- cdist/conf/type/__package_pkg_openbsd/gencode-remote | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__package_pkg_openbsd/gencode-remote b/cdist/conf/type/__package_pkg_openbsd/gencode-remote index 7583167e..e7f40a4d 100755 --- a/cdist/conf/type/__package_pkg_openbsd/gencode-remote +++ b/cdist/conf/type/__package_pkg_openbsd/gencode-remote @@ -79,7 +79,7 @@ if [ $? -ne 0 ]; then status="Failed to add package, uncaught exception." fi echo "Error: \$status" - exit 1 + exit 1 fi eof ;; From 3d5706d3cc30e556ea6fbf2e6addf8a925362020 Mon Sep 17 00:00:00 2001 From: og Date: Sat, 8 Mar 2014 17:18:19 -0700 Subject: [PATCH 24/51] escaped some variables in the gencode-remote output --- cdist/conf/type/__package_pkg_openbsd/gencode-remote | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cdist/conf/type/__package_pkg_openbsd/gencode-remote b/cdist/conf/type/__package_pkg_openbsd/gencode-remote index e7f40a4d..08e15e89 100755 --- a/cdist/conf/type/__package_pkg_openbsd/gencode-remote +++ b/cdist/conf/type/__package_pkg_openbsd/gencode-remote @@ -74,8 +74,8 @@ pkg_info | grep "^${name}.*${flavor}" > /dev/null 2>&1 # We didn't find the package in the list of 'installed packages', so it failed # This is necessary because pkg_add doesn't return properly -if [ $? -ne 0 ]; then - if [ -z "${status}" ]; then +if [ \$? -ne 0 ]; then + if [ -z "\${status}" ]; then status="Failed to add package, uncaught exception." fi echo "Error: \$status" @@ -92,8 +92,8 @@ pkg_info | grep "^${name}.*${flavor}" > /dev/null 2>&1 # We found the package in the list of 'installed packages' # This would indicate that pkg_delete failed, send the output of pkg_delete -if [ $? -eq 0 ]; then - if [ -z "${status}" ]; then +if [ \$? -eq 0 ]; then + if [ -z "\${status}" ]; then status="Failed to remove package, uncaught exception." fi echo "Error: \$status" From 0a98abbffadbc8a0c2bdbe087fdbef025cfd4f0a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 11 Mar 2014 15:39:08 +0100 Subject: [PATCH 25/51] add messaging support for __key_value Signed-off-by: Nico Schottelius --- cdist/conf/type/__key_value/gencode-remote | 5 ++++- cdist/conf/type/__key_value/man.text | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__key_value/gencode-remote b/cdist/conf/type/__key_value/gencode-remote index b79d9688..e1041a02 100755 --- a/cdist/conf/type/__key_value/gencode-remote +++ b/cdist/conf/type/__key_value/gencode-remote @@ -1,7 +1,7 @@ #!/bin/sh # # 2011 Steven Armstrong (steven-cdist at armstrong.cc) -# 2012 Nico Schottelius (nico-cdist at schottelius.org) +# 2012-2014 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -42,12 +42,14 @@ cp -p "$file" "\$tmpfile" sed '/^$key\($delimiter\+\)/d' "$file" > "\$tmpfile" mv -f "\$tmpfile" "$file" DONE + echo "remove" >> "$__messages_out" ;; present) case "$state_is" in absent) # add new key and value printf 'echo "%s%s%s" >> "%s"' "$key" "$delimiter" "$value_escaped" "$file" + echo "add" >> "$__messages_out" ;; wrongvalue) # change exisiting value @@ -58,6 +60,7 @@ cp -p "$file" "\$tmpfile" sed "s|^$key\($delimiter\+\).*|$key\\1$value_escaped|" "$file" > "\$tmpfile" mv -f "\$tmpfile" "$file" DONE + echo "changevalue" >> "$__messages_out" ;; *) echo "Unknown explorer state: $state_is" >&2 diff --git a/cdist/conf/type/__key_value/man.text b/cdist/conf/type/__key_value/man.text index 1423fc7d..7def7139 100644 --- a/cdist/conf/type/__key_value/man.text +++ b/cdist/conf/type/__key_value/man.text @@ -32,6 +32,15 @@ key:: value:: The value for the key. Optional if state=absent, required otherwise. +MESSAGES +-------- +create:: + Added key and value +change:: + Changed value of existing key +remove:: + Removed existing key and value + EXAMPLES -------- From d288ee1cde8dcc5c2d6886e1f6690e0a32152183 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 11 Mar 2014 15:40:44 +0100 Subject: [PATCH 26/51] ++changes Signed-off-by: Nico Schottelius --- docs/changelog | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/changelog b/docs/changelog index e7ac935d..9477d8d0 100644 --- a/docs/changelog +++ b/docs/changelog @@ -6,11 +6,12 @@ Changelog next: - * Type __git: Pass onwer/group/mode values to __directory - * Type __ssh_authorized_keys: Allow managing existing keys (Steven Armstrong) - * Type __iptable_rule: Fix example documentation (Antoine Catton) * Type __file: Enhance OpenBSD Support (og) + * Type __git: Pass onwer/group/mode values to __directory + * Type __iptable_rule: Fix example documentation (Antoine Catton) + * Type __key_value: Add messaging support * Type __package_pkg_openbsd: Allow to change PKG_PATH (og) + * Type __ssh_authorized_keys: Allow managing existing keys (Steven Armstrong) * Type __user: Enhance OpenBSD Support (og) From 75c203a1f05748ff877e986148f43e8e792edb16 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 11 Mar 2014 20:48:47 +0100 Subject: [PATCH 27/51] handle existing symlink but wrong source Signed-off-by: Steven Armstrong --- cdist/conf/type/__link/explorer/state | 10 +++++++--- cdist/conf/type/__link/gencode-remote | 9 +++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cdist/conf/type/__link/explorer/state b/cdist/conf/type/__link/explorer/state index a9220a3c..48278d9e 100755 --- a/cdist/conf/type/__link/explorer/state +++ b/cdist/conf/type/__link/explorer/state @@ -1,6 +1,6 @@ #!/bin/sh # -# 2012 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012-2014 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -34,8 +34,12 @@ case "$type" in symbolic) cd "$destination_dir" source_is=$(ls -l "$destination" | sed 's/.*-> //g') - if [ -h "$destination" -a "$source_is" = "$source" ]; then - echo present + if [ -h "$destination" ]; then + if [ "$source_is" = "$source" ]; then + echo present + else + echo wrongsource + fi else echo absent fi diff --git a/cdist/conf/type/__link/gencode-remote b/cdist/conf/type/__link/gencode-remote index cbdfd30f..7582863f 100755 --- a/cdist/conf/type/__link/gencode-remote +++ b/cdist/conf/type/__link/gencode-remote @@ -1,7 +1,7 @@ #!/bin/sh # # 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) -# 2013 Steven Armstrong (steven-cdist at armstrong.cc) +# 2013-2014 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -18,9 +18,6 @@ # You should have received a copy of the GNU General Public License # along with cdist. If not, see . # -# -# Mostly a wrapper for ln -# destination="/$__object_id" @@ -55,6 +52,10 @@ rm -rf "$destination" DONE fi + if [ "$state_is" = "wrongsource" ]; then + printf 'rm -f "%s"\n' "$destination" + fi + # create our link cat << DONE ln ${lnopt} -f "$source" "$destination" From 301b4e18ff8fc87f2a10d0c471c93df55fe0abc4 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 11 Mar 2014 21:07:20 +0100 Subject: [PATCH 28/51] either to it all, or fail; echo and cat suck, printf ftw! Signed-off-by: Steven Armstrong --- cdist/conf/type/__link/gencode-remote | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/cdist/conf/type/__link/gencode-remote b/cdist/conf/type/__link/gencode-remote index 7582863f..9e7831c7 100755 --- a/cdist/conf/type/__link/gencode-remote +++ b/cdist/conf/type/__link/gencode-remote @@ -47,24 +47,22 @@ case "$state_should" in present) if [ "$file_type" = "directory" ]; then # our destination is currently a directory, delete it - cat << DONE -rm -rf "$destination" -DONE - fi - - if [ "$state_is" = "wrongsource" ]; then - printf 'rm -f "%s"\n' "$destination" + printf 'rm -rf "%s" &&\n' "$destination" + else + if [ "$state_is" = "wrongsource" ]; then + # our destination is a symlink but points to the wrong source, + # delete it + printf 'rm -f "%s" &&\n' "$destination" + fi fi # create our link - cat << DONE -ln ${lnopt} -f "$source" "$destination" -DONE + printf 'ln %s -f "%s" "%s"\n' "$lnopt" "$source" "$destination" ;; absent) # only delete if it is a sym/hard link if [ "$file_type" = "symlink" -o "$file_type" = "hardlink" ]; then - echo rm -f \"$destination\" + printf 'rm -f "%s"\n' "$destination" fi ;; *) From 5ec617fa3e4dba53a85cad90d75590fea0abf591 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 11 Mar 2014 22:16:08 +0100 Subject: [PATCH 29/51] ignore trailing slashes for comparison of source Signed-off-by: Steven Armstrong --- cdist/conf/type/__link/explorer/state | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__link/explorer/state b/cdist/conf/type/__link/explorer/state index 48278d9e..b8d8fc2b 100755 --- a/cdist/conf/type/__link/explorer/state +++ b/cdist/conf/type/__link/explorer/state @@ -35,7 +35,8 @@ case "$type" in cd "$destination_dir" source_is=$(ls -l "$destination" | sed 's/.*-> //g') if [ -h "$destination" ]; then - if [ "$source_is" = "$source" ]; then + # ignore trailing slashes for comparison + if [ "${source_is%/}" = "${source%/}" ]; then echo present else echo wrongsource From 2b03ccd776a37bd0bfe0a3ccd7e9ef42ea6b9756 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 19 Mar 2014 18:57:11 +0100 Subject: [PATCH 30/51] changes for 3.1.0 Signed-off-by: Nico Schottelius --- cdist/conf/type/__ssh_authorized_keys/manifest | 1 + docs/changelog | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__ssh_authorized_keys/manifest b/cdist/conf/type/__ssh_authorized_keys/manifest index efcd2d7a..1c9df208 100755 --- a/cdist/conf/type/__ssh_authorized_keys/manifest +++ b/cdist/conf/type/__ssh_authorized_keys/manifest @@ -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" \ diff --git a/docs/changelog b/docs/changelog index 9477d8d0..df23d39f 100644 --- a/docs/changelog +++ b/docs/changelog @@ -5,7 +5,8 @@ Changelog * Exception: No braces means author == Nico Schottelius -next: +3.1.0: 2014-03-19 + * New Type: __rbenv * Type __file: Enhance OpenBSD Support (og) * Type __git: Pass onwer/group/mode values to __directory * Type __iptable_rule: Fix example documentation (Antoine Catton) @@ -14,7 +15,6 @@ next: * Type __ssh_authorized_keys: Allow managing existing keys (Steven Armstrong) * Type __user: Enhance OpenBSD Support (og) - 3.0.9: 2014-02-14 * Core: Ignore order dependencies if override is set (Daniel Heule) * Core: Improve Mac OS X support for unit tests (Steven Armstrong) From 9a79cec140ce76230e078e3c47abcad83950145c Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 19 Mar 2014 18:58:54 +0100 Subject: [PATCH 31/51] remove useless error in build script Signed-off-by: Nico Schottelius --- bin/build-helper | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/build-helper b/bin/build-helper index 1de2eb94..93401d3b 100755 --- a/bin/build-helper +++ b/bin/build-helper @@ -175,7 +175,7 @@ eof release-git-tag) target_version=$($0 changelog-version) - if git rev-parse --verify refs/tags/$target_version; then + if git rev-parse --verify refs/tags/$target_version 2>/dev/null; then echo "Tag for $target_version exists, aborting" exit 1 fi From 10a71eb35a8aa9cfa356e6bc79f42ff12ddfa34a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 19 Mar 2014 19:00:39 +0100 Subject: [PATCH 32/51] notes for 3.0 -> 3.1 update Signed-off-by: Nico Schottelius --- docs/web/cdist/update.mdwn | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/web/cdist/update.mdwn b/docs/web/cdist/update.mdwn index 2e3e9b92..28f41da7 100644 --- a/docs/web/cdist/update.mdwn +++ b/docs/web/cdist/update.mdwn @@ -55,6 +55,11 @@ To upgrade to the lastet version do ## General Update Instructions +### Updating from 3.0 to 3.1 + +The type **\_\_ssh_authorized_keys** now also manages existing keys, +not only the ones added by cdist. + ### Updating from 2.3 to 3.0 The **changed** attribute of objects has been removed. From 5ef27191fca6b60f6a02664cb7799e45de052674 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Thu, 20 Mar 2014 13:52:12 +0100 Subject: [PATCH 33/51] implementing the $__object and $__object_id on the local and remote execution call, to allow read access to parameter files --- cdist/core/code.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cdist/core/code.py b/cdist/core/code.py index f128697f..6abfb393 100644 --- a/cdist/core/code.py +++ b/cdist/core/code.py @@ -123,15 +123,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) From b87b5eab31d38c1685e3c30056c7c18fd55531ff Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Thu, 20 Mar 2014 16:23:28 +0100 Subject: [PATCH 34/51] documentation to __object in execution run --- docs/man/cdist-reference.text.sh | 14 ++++++++------ docs/man/man7/cdist-type.text | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/docs/man/cdist-reference.text.sh b/docs/man/cdist-reference.text.sh index 62614c55..6552bf82 100755 --- a/docs/man/cdist-reference.text.sh +++ b/docs/man/cdist-reference.text.sh @@ -157,13 +157,13 @@ TYPES The following types are available: eof - -for type in man7/cdist-type__*.text; do +set -x +for type in man7/cdist-type__*.html; do no_dir="${type#man7/}"; no_type="${no_dir#cdist-type}"; - name="${no_type%.text}"; + name="${no_type%.html}"; name_no_underline="$(echo $name | sed 's/^__/\\__/g')" - man="${no_dir%.text}(7)" + man="${no_dir%.html}(7)" echo "- $name_no_underline" "($man)" done @@ -209,10 +209,12 @@ __messages_out:: Available for: initial manifest, type manifest, type gencode __object:: Directory that contains the current object. - Available for: type manifest, type explorer, type gencode + Available for: type manifest, type explorer, type gencode and + at the execution of the gencode scripts __object_id:: The type unique object id. - Available for: type manifest, type explorer, type gencode + Available for: type manifest, type explorer, type gencode and + at the execution of the gencode scripts Note: The leading and the trailing "/" will always be stripped (caused by the filesystem database and ensured by the core). Note: Double slashes ("//") will not be fixed and result in an error. diff --git a/docs/man/man7/cdist-type.text b/docs/man/man7/cdist-type.text index 8415f991..06026542 100644 --- a/docs/man/man7/cdist-type.text +++ b/docs/man/man7/cdist-type.text @@ -252,6 +252,27 @@ echo "touch /etc/cdist-configured" -------------------------------------------------------------------------------- +VARIABLE ACCESS FROM THE GENERATED SCRIPTS +------------------------------------------ +In the generated scripts, you have access to the following cdist variables + +- __object +- __object_id + +but only for read operations, means there is no back copy of this +files after the script execution. + +So when you generate a script with the following content, it will work: + +-------------------------------------------------------------------------------- +if [ -f "$__object/parameter/name" ]; then + name="$(cat "$__object/parameter/name")" +else + name="$__object_id" +fi +-------------------------------------------------------------------------------- + + HINTS FOR TYPEWRITERS ---------------------- It must be assumed that the target is pretty dumb and thus does not have high From f36dc1160153558f1d83d8490fc091186e193619 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Thu, 20 Mar 2014 17:22:07 +0100 Subject: [PATCH 35/51] forgot myself to the headers .. --- cdist/core/code.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cdist/core/code.py b/cdist/core/code.py index 6abfb393..5374bcdf 100644 --- a/cdist/core/code.py +++ b/cdist/core/code.py @@ -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. # From b5b1a25e4ff00b6a8dd9531f567447ffeb096aac Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Thu, 20 Mar 2014 18:53:19 +0100 Subject: [PATCH 36/51] fixed some formulations and removed a debug statement --- docs/man/cdist-reference.text.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/man/cdist-reference.text.sh b/docs/man/cdist-reference.text.sh index 6552bf82..28c46fa6 100755 --- a/docs/man/cdist-reference.text.sh +++ b/docs/man/cdist-reference.text.sh @@ -1,6 +1,7 @@ #!/bin/sh # # 2010-2013 Nico Schottelius (nico-cdist at schottelius.org) +# 2014 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. # @@ -157,7 +158,7 @@ TYPES The following types are available: eof -set -x + for type in man7/cdist-type__*.html; do no_dir="${type#man7/}"; no_type="${no_dir#cdist-type}"; @@ -209,12 +210,10 @@ __messages_out:: Available for: initial manifest, type manifest, type gencode __object:: Directory that contains the current object. - Available for: type manifest, type explorer, type gencode and - at the execution of the gencode scripts + Available for: type manifest, type explorer, type gencode and code scripts __object_id:: The type unique object id. - Available for: type manifest, type explorer, type gencode and - at the execution of the gencode scripts + Available for: type manifest, type explorer, type gencode and code scripts Note: The leading and the trailing "/" will always be stripped (caused by the filesystem database and ensured by the core). Note: Double slashes ("//") will not be fixed and result in an error. From e1766aa070de2c7de99b52428758be60d0137a10 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Thu, 20 Mar 2014 19:04:09 +0100 Subject: [PATCH 37/51] reverted the change to .html in generating the reference, since I have fooled myself ... --- docs/man/cdist-reference.text.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/man/cdist-reference.text.sh b/docs/man/cdist-reference.text.sh index 28c46fa6..cff0f9c7 100755 --- a/docs/man/cdist-reference.text.sh +++ b/docs/man/cdist-reference.text.sh @@ -159,12 +159,12 @@ The following types are available: eof -for type in man7/cdist-type__*.html; do +for type in man7/cdist-type__*.text; do no_dir="${type#man7/}"; no_type="${no_dir#cdist-type}"; - name="${no_type%.html}"; + name="${no_type%.text}"; name_no_underline="$(echo $name | sed 's/^__/\\__/g')" - man="${no_dir%.html}(7)" + man="${no_dir%.text}(7)" echo "- $name_no_underline" "($man)" done From 6e4533cb145165a88f8bec1ffbf347fb0f20a774 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 20 Mar 2014 20:40:04 +0100 Subject: [PATCH 38/51] ++changes Signed-off-by: Nico Schottelius --- docs/changelog | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/changelog b/docs/changelog index df23d39f..7db43304 100644 --- a/docs/changelog +++ b/docs/changelog @@ -5,6 +5,9 @@ Changelog * Exception: No braces means author == Nico Schottelius +3.1.1: + * Core: Make __object and __object available to code (Daniel Heule) + 3.1.0: 2014-03-19 * New Type: __rbenv * Type __file: Enhance OpenBSD Support (og) From c31278bcd09e4da521b9b72566a2fe3b8bd218c9 Mon Sep 17 00:00:00 2001 From: Jake Guffey Date: Tue, 25 Mar 2014 12:50:27 -0400 Subject: [PATCH 39/51] Fix __jail explorers Only fixed gencode*, manifest in PR #279, fixed explorers here --- cdist/conf/type/__jail/explorer/basepresent | 2 +- cdist/conf/type/__jail/explorer/present | 2 +- cdist/conf/type/__jail/explorer/status | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cdist/conf/type/__jail/explorer/basepresent b/cdist/conf/type/__jail/explorer/basepresent index f167a19c..034128d5 100755 --- a/cdist/conf/type/__jail/explorer/basepresent +++ b/cdist/conf/type/__jail/explorer/basepresent @@ -26,7 +26,7 @@ #set -x if [ -f "$__object/parameter/jaildir" ]; then - jaildir="$(cat "$__object/parameter/name")" + jaildir="$(cat "$__object/parameter/jaildir")" else jaildir="/usr/jail" fi diff --git a/cdist/conf/type/__jail/explorer/present b/cdist/conf/type/__jail/explorer/present index 2ba3b2af..ddfb805c 100755 --- a/cdist/conf/type/__jail/explorer/present +++ b/cdist/conf/type/__jail/explorer/present @@ -32,7 +32,7 @@ else fi if [ -f "$__object/parameter/jaildir" ]; then - jaildir="$(cat "$__object/parameter/name")" + jaildir="$(cat "$__object/parameter/jaildir")" else jaildir="/usr/jail" fi diff --git a/cdist/conf/type/__jail/explorer/status b/cdist/conf/type/__jail/explorer/status index fe81eaf7..06f7d063 100755 --- a/cdist/conf/type/__jail/explorer/status +++ b/cdist/conf/type/__jail/explorer/status @@ -32,7 +32,7 @@ else fi if [ -f "$__object/parameter/jaildir" ]; then - jaildir="$(cat "$__object/parameter/name")" + jaildir="$(cat "$__object/parameter/jaildir")" else jaildir="/usr/jail" fi From dfdd77eff4ecba79cd7d09337fba3c621ae00b24 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 26 Mar 2014 11:00:38 +0100 Subject: [PATCH 40/51] ++changes Signed-off-by: Nico Schottelius --- docs/changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog b/docs/changelog index 7db43304..54c5cf8c 100644 --- a/docs/changelog +++ b/docs/changelog @@ -7,6 +7,7 @@ Changelog 3.1.1: * Core: Make __object and __object available to code (Daniel Heule) + * Type __line: Ensure permissions are kept (Steven Armstrong) 3.1.0: 2014-03-19 * New Type: __rbenv From 653012ee5fc153cf555113b03a79c94f04c6efe2 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 26 Mar 2014 11:17:16 +0100 Subject: [PATCH 41/51] ++changes Signed-off-by: Nico Schottelius --- docs/changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog b/docs/changelog index 54c5cf8c..5cafc436 100644 --- a/docs/changelog +++ b/docs/changelog @@ -8,6 +8,7 @@ Changelog 3.1.1: * Core: Make __object and __object available to code (Daniel Heule) * Type __line: Ensure permissions are kept (Steven Armstrong) + * Type __link: Do not create link in directory, if link exists (Steven Armstrong) 3.1.0: 2014-03-19 * New Type: __rbenv From ae477d69c8975a13033444cdbab2cb669b113241 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 26 Mar 2014 11:18:35 +0100 Subject: [PATCH 42/51] ++changes Signed-off-by: Nico Schottelius --- docs/changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog b/docs/changelog index 5cafc436..2dce48e4 100644 --- a/docs/changelog +++ b/docs/changelog @@ -9,6 +9,7 @@ Changelog * Core: Make __object and __object available to code (Daniel Heule) * Type __line: Ensure permissions are kept (Steven Armstrong) * Type __link: Do not create link in directory, if link exists (Steven Armstrong) + * Type __package_pkg_openbsd: Improve error handling (og) 3.1.0: 2014-03-19 * New Type: __rbenv From 94c7d4cacfa24f5bc1b24a743c95b713f0dbd675 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 26 Mar 2014 11:20:54 +0100 Subject: [PATCH 43/51] ++changes Signed-off-by: Nico Schottelius --- docs/changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog b/docs/changelog index 2dce48e4..3194b5ee 100644 --- a/docs/changelog +++ b/docs/changelog @@ -7,6 +7,7 @@ Changelog 3.1.1: * Core: Make __object and __object available to code (Daniel Heule) + * Type __jail: Fix parameter names in explorer (Jake Guffey) * Type __line: Ensure permissions are kept (Steven Armstrong) * Type __link: Do not create link in directory, if link exists (Steven Armstrong) * Type __package_pkg_openbsd: Improve error handling (og) From 7b6102750e6511243217622bd8291880918b4c6a Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Wed, 26 Mar 2014 11:57:15 +0100 Subject: [PATCH 44/51] as requested, replace space with _ --- cdist/conf/explorer/machine_type | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cdist/conf/explorer/machine_type b/cdist/conf/explorer/machine_type index 60b7f5e2..74789f5a 100755 --- a/cdist/conf/explorer/machine_type +++ b/cdist/conf/explorer/machine_type @@ -29,23 +29,23 @@ if [ -r /proc/cpuinfo ]; then # this file is aviable in xen guest systems if [ -r /sys/hypervisor/type ]; then if grep -q -i "xen" /sys/hypervisor/type; then - echo virtual by xen + echo virtual_by_xen exit fi else if [ -r /sys/class/dmi/id/product_name ]; then if grep -q -i 'vmware' /sys/class/dmi/id/product_name; then - echo "virtual by vmware" + echo "virtual_by_vmware" exit else if grep -q -i 'bochs' /sys/class/dmi/id/product_name; then - echo "virtual by kvm" + echo "virtual_by_kvm" exit fi fi fi fi - echo "virtual by unknown" + echo "virtual_by_unknown" else echo "physical" fi From c3de952d559fa4d71e6c161179d2584a56310d38 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 26 Mar 2014 13:09:48 +0100 Subject: [PATCH 45/51] release date for 3.1.1 Signed-off-by: Nico Schottelius --- docs/changelog | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/changelog b/docs/changelog index 3194b5ee..78c856aa 100644 --- a/docs/changelog +++ b/docs/changelog @@ -5,8 +5,12 @@ Changelog * Exception: No braces means author == Nico Schottelius -3.1.1: +3.1.1: 2014-03-26 * Core: Make __object and __object available to code (Daniel Heule) + * New explorer: cpu_cores (Daniel Heule/Thomas Oettli) + * New explorer: cpu_sockets (Daniel Heule/Thomas Oettli) + * New explorer: machine_type (Daniel Heule/Thomas Oettli) + * New explorer: memory (Daniel Heule/Thomas Oettli) * Type __jail: Fix parameter names in explorer (Jake Guffey) * Type __line: Ensure permissions are kept (Steven Armstrong) * Type __link: Do not create link in directory, if link exists (Steven Armstrong) From 63347497ad2a8ee00f7b032ba4abfe72f826190f Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 26 Mar 2014 13:14:26 +0100 Subject: [PATCH 46/51] --typo before release Signed-off-by: Nico Schottelius --- docs/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog b/docs/changelog index 78c856aa..8b66e95b 100644 --- a/docs/changelog +++ b/docs/changelog @@ -6,7 +6,7 @@ Changelog 3.1.1: 2014-03-26 - * Core: Make __object and __object available to code (Daniel Heule) + * Core: Make __object and __object_id available to code (Daniel Heule) * New explorer: cpu_cores (Daniel Heule/Thomas Oettli) * New explorer: cpu_sockets (Daniel Heule/Thomas Oettli) * New explorer: machine_type (Daniel Heule/Thomas Oettli) From ff8f7ac2878fff4bec02ba7dcd7333b498a4d52c Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 30 Mar 2014 13:09:38 +0200 Subject: [PATCH 47/51] add copied version __dog_vdi from __qemu_img Signed-off-by: Nico Schottelius --- cdist/conf/type/__dog_vdi/explorer/list | 23 +++++++++ cdist/conf/type/__dog_vdi/gencode-remote | 19 +++++++ cdist/conf/type/__dog_vdi/man.text | 50 +++++++++++++++++++ .../type/__dog_vdi/parameter/default/format | 1 + .../type/__dog_vdi/parameter/default/state | 1 + cdist/conf/type/__dog_vdi/parameter/optional | 2 + cdist/conf/type/__dog_vdi/parameter/required | 1 + 7 files changed, 97 insertions(+) create mode 100755 cdist/conf/type/__dog_vdi/explorer/list create mode 100644 cdist/conf/type/__dog_vdi/gencode-remote create mode 100644 cdist/conf/type/__dog_vdi/man.text create mode 100644 cdist/conf/type/__dog_vdi/parameter/default/format create mode 100644 cdist/conf/type/__dog_vdi/parameter/default/state create mode 100644 cdist/conf/type/__dog_vdi/parameter/optional create mode 100644 cdist/conf/type/__dog_vdi/parameter/required diff --git a/cdist/conf/type/__dog_vdi/explorer/list b/cdist/conf/type/__dog_vdi/explorer/list new file mode 100755 index 00000000..856c86fc --- /dev/null +++ b/cdist/conf/type/__dog_vdi/explorer/list @@ -0,0 +1,23 @@ +#!/bin/sh +# +# 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 . +# + +name="$__object_id" + +dog vdi list -r "$name" diff --git a/cdist/conf/type/__dog_vdi/gencode-remote b/cdist/conf/type/__dog_vdi/gencode-remote new file mode 100644 index 00000000..6e4bb4d0 --- /dev/null +++ b/cdist/conf/type/__dog_vdi/gencode-remote @@ -0,0 +1,19 @@ +################################################################################ +# State: absent is handled by manifest - we need only to do stuff if image is +# not existing and state != absent +# +state="$(cat "$__object/parameter/state")" +[ "$state" = "absent" ] && exit 0 + +exists="$(cat "$__object/explorer/exists")" +[ "$exists" ] && exit 0 + +################################################################################ +# Still there? Create image +# + +format="$(cat "$__object/parameter/format")" +size="$(cat "$__object/parameter/size")" +diskimage="/$__object_id" + +echo qemu-img create -f \"$format\" \"$diskimage\" \"$size\" diff --git a/cdist/conf/type/__dog_vdi/man.text b/cdist/conf/type/__dog_vdi/man.text new file mode 100644 index 00000000..444ab15d --- /dev/null +++ b/cdist/conf/type/__dog_vdi/man.text @@ -0,0 +1,50 @@ +cdist-type__dog_vdi(7) +====================== +Nico Schottelius + + +NAME +---- +cdist-type__dog_vdi - Manage Sheepdog VM images + + +DESCRIPTION +----------- +The dog program is used to create qemu images for +qemu and (qemu-)kvm. + + +REQUIRED PARAMETERS +------------------- +size:: + Size of the image in dog vdi compatible units. + + +OPTIONAL PARAMETERS +------------------- +state:: + Either "present" or "absent", defaults to "present" + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# Create a 50G size image +__dog_vdi nico-privat.sky.ungleich.ch --size 50G + +# Remove image +__dog_vdi nico-privat.sky.ungleich.ch --state absent +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- dog(8) + + +COPYING +------- +Copyright \(C) 2014 Nico Schottelius. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__dog_vdi/parameter/default/format b/cdist/conf/type/__dog_vdi/parameter/default/format new file mode 100644 index 00000000..e0a90ab9 --- /dev/null +++ b/cdist/conf/type/__dog_vdi/parameter/default/format @@ -0,0 +1 @@ +qcow2 diff --git a/cdist/conf/type/__dog_vdi/parameter/default/state b/cdist/conf/type/__dog_vdi/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__dog_vdi/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__dog_vdi/parameter/optional b/cdist/conf/type/__dog_vdi/parameter/optional new file mode 100644 index 00000000..71b9a32b --- /dev/null +++ b/cdist/conf/type/__dog_vdi/parameter/optional @@ -0,0 +1,2 @@ +format +state diff --git a/cdist/conf/type/__dog_vdi/parameter/required b/cdist/conf/type/__dog_vdi/parameter/required new file mode 100644 index 00000000..2a613ba5 --- /dev/null +++ b/cdist/conf/type/__dog_vdi/parameter/required @@ -0,0 +1 @@ +size From b22b581b671fa9816f82efda3dc1d60f246f499e Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 31 Mar 2014 14:26:14 +0200 Subject: [PATCH 48/51] first version of __dog_vdi Signed-off-by: Nico Schottelius --- cdist/conf/type/__dog_vdi/gencode-remote | 53 +++++++++++++------ cdist/conf/type/__dog_vdi/man.text | 22 +++++--- cdist/conf/type/__dog_vdi/manifest | 28 ++++++++++ .../type/__dog_vdi/parameter/default/format | 1 - cdist/conf/type/__dog_vdi/parameter/optional | 2 +- cdist/conf/type/__dog_vdi/parameter/required | 1 - 6 files changed, 81 insertions(+), 26 deletions(-) create mode 100644 cdist/conf/type/__dog_vdi/manifest delete mode 100644 cdist/conf/type/__dog_vdi/parameter/default/format delete mode 100644 cdist/conf/type/__dog_vdi/parameter/required diff --git a/cdist/conf/type/__dog_vdi/gencode-remote b/cdist/conf/type/__dog_vdi/gencode-remote index 6e4bb4d0..56e4108a 100644 --- a/cdist/conf/type/__dog_vdi/gencode-remote +++ b/cdist/conf/type/__dog_vdi/gencode-remote @@ -1,19 +1,42 @@ -################################################################################ -# State: absent is handled by manifest - we need only to do stuff if image is -# not existing and state != absent +#!/bin/sh # -state="$(cat "$__object/parameter/state")" -[ "$state" = "absent" ] && exit 0 - -exists="$(cat "$__object/explorer/exists")" -[ "$exists" ] && exit 0 - -################################################################################ -# Still there? Create image +# 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 . # -format="$(cat "$__object/parameter/format")" -size="$(cat "$__object/parameter/size")" -diskimage="/$__object_id" +state_should="$(cat "$__object/parameter/state")" +num_vdi_lines=$(wc -l < "$__object/explorer/list") +name="$__object_id" -echo qemu-img create -f \"$format\" \"$diskimage\" \"$size\" + +if [ "$num_vdi_lines" = 1 ]; then + state_is=present +else + state_is=absent +fi + +[ "$state_is" = "$state_should" ] && exit 0 + +case "$state_should" in + present) + size="$(cat "$__object/parameter/size")" + echo "dog vdi create '$name' '$size'" + ;; + absent) + echo "dog vdi delete '$name'" + ;; +esac diff --git a/cdist/conf/type/__dog_vdi/man.text b/cdist/conf/type/__dog_vdi/man.text index 444ab15d..d7cc6f88 100644 --- a/cdist/conf/type/__dog_vdi/man.text +++ b/cdist/conf/type/__dog_vdi/man.text @@ -10,20 +10,19 @@ cdist-type__dog_vdi - Manage Sheepdog VM images DESCRIPTION ----------- -The dog program is used to create qemu images for -qemu and (qemu-)kvm. - - -REQUIRED PARAMETERS -------------------- -size:: - Size of the image in dog vdi compatible units. +The dog program is used to create images for sheepdog +to be used in qemu. OPTIONAL PARAMETERS ------------------- state:: Either "present" or "absent", defaults to "present" +size:: + Size of the image in dog vdi compatible units. + + Required if state == present. + EXAMPLES @@ -33,8 +32,14 @@ EXAMPLES # Create a 50G size image __dog_vdi nico-privat.sky.ungleich.ch --size 50G +# Create a 50G size image (more explicit) +__dog_vdi nico-privat.sky.ungleich.ch --size 50G --state present + # Remove image __dog_vdi nico-privat.sky.ungleich.ch --state absent + +# Remove image - keeping --size is ok +__dog_vdi nico-privat.sky.ungleich.ch --size 50G --state absent -------------------------------------------------------------------------------- @@ -42,6 +47,7 @@ SEE ALSO -------- - cdist-type(7) - dog(8) +- qemu(1) COPYING diff --git a/cdist/conf/type/__dog_vdi/manifest b/cdist/conf/type/__dog_vdi/manifest new file mode 100644 index 00000000..cd022f28 --- /dev/null +++ b/cdist/conf/type/__dog_vdi/manifest @@ -0,0 +1,28 @@ +#!/bin/sh +# +# 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 . +# + +state_should="$(cat "$__object/parameter/state")" + +if [ "$state_should" = "present" ]; then + if [ ! -f "$__object/parameter/size" ]; then + echo "Size is required when state is present" >&2 + exit 1 + fi +fi diff --git a/cdist/conf/type/__dog_vdi/parameter/default/format b/cdist/conf/type/__dog_vdi/parameter/default/format deleted file mode 100644 index e0a90ab9..00000000 --- a/cdist/conf/type/__dog_vdi/parameter/default/format +++ /dev/null @@ -1 +0,0 @@ -qcow2 diff --git a/cdist/conf/type/__dog_vdi/parameter/optional b/cdist/conf/type/__dog_vdi/parameter/optional index 71b9a32b..c3ac4490 100644 --- a/cdist/conf/type/__dog_vdi/parameter/optional +++ b/cdist/conf/type/__dog_vdi/parameter/optional @@ -1,2 +1,2 @@ -format state +size diff --git a/cdist/conf/type/__dog_vdi/parameter/required b/cdist/conf/type/__dog_vdi/parameter/required deleted file mode 100644 index 2a613ba5..00000000 --- a/cdist/conf/type/__dog_vdi/parameter/required +++ /dev/null @@ -1 +0,0 @@ -size From b7f8b5e33951f931cb6be12ac892d914dd0a4cba Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 31 Mar 2014 21:22:15 +0200 Subject: [PATCH 49/51] catch unsupported state cases in __dog_vdi und __qemu_img Signed-off-by: Nico Schottelius --- cdist/conf/type/__dog_vdi/manifest | 18 ++++++++++----- cdist/conf/type/__qemu_img/manifest | 22 ++++++++++++++----- cdist/conf/type/__qemu_img/parameter/required | 1 - 3 files changed, 30 insertions(+), 11 deletions(-) delete mode 100644 cdist/conf/type/__qemu_img/parameter/required diff --git a/cdist/conf/type/__dog_vdi/manifest b/cdist/conf/type/__dog_vdi/manifest index cd022f28..ab533c4b 100644 --- a/cdist/conf/type/__dog_vdi/manifest +++ b/cdist/conf/type/__dog_vdi/manifest @@ -20,9 +20,17 @@ state_should="$(cat "$__object/parameter/state")" -if [ "$state_should" = "present" ]; then - if [ ! -f "$__object/parameter/size" ]; then - echo "Size is required when state is present" >&2 +case "$state_should" in + present) + if [ ! -f "$__object/parameter/size" ]; then + echo "Size is required when state is present" >&2 + exit 1 + fi + absent) + : + ;; + *) + echo "Unsupported state: $state_should" >&2 exit 1 - fi -fi + ;; +esac diff --git a/cdist/conf/type/__qemu_img/manifest b/cdist/conf/type/__qemu_img/manifest index 6d50037f..bb2c9366 100644 --- a/cdist/conf/type/__qemu_img/manifest +++ b/cdist/conf/type/__qemu_img/manifest @@ -3,11 +3,23 @@ # format="$(cat "$__object/parameter/format")" -state="$(cat "$__object/parameter/state")" +state_should="$(cat "$__object/parameter/state")" diskimage="/$__object_id" -# Absent is ensured by __file, present by gencode-remote -if [ "$state" = "absent" ]; then - __file "$diskimage" --state absent -fi +case "$state_should" in + present) + if [ ! -f "$__object/parameter/size" ]; then + echo "Size is required when state is present" >&2 + exit 1 + fi + ;; + absent) + # Absent is ensured by __file, present by gencode-remote + __file "$diskimage" --state absent + ;; + *) + echo "Unsupported state: $state_should" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__qemu_img/parameter/required b/cdist/conf/type/__qemu_img/parameter/required deleted file mode 100644 index 2a613ba5..00000000 --- a/cdist/conf/type/__qemu_img/parameter/required +++ /dev/null @@ -1 +0,0 @@ -size From 2955ef4344c864a1276c333ab027b029fb80f74a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 31 Mar 2014 21:22:29 +0200 Subject: [PATCH 50/51] cleanups Signed-off-by: Nico Schottelius --- cdist/conf/type/__dog_vdi/man.text | 4 ++-- cdist/conf/type/__qemu_img/man.text | 13 ++++++------- cdist/conf/type/__qemu_img/parameter/optional | 1 + 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cdist/conf/type/__dog_vdi/man.text b/cdist/conf/type/__dog_vdi/man.text index d7cc6f88..e3453ba7 100644 --- a/cdist/conf/type/__dog_vdi/man.text +++ b/cdist/conf/type/__dog_vdi/man.text @@ -19,9 +19,9 @@ OPTIONAL PARAMETERS state:: Either "present" or "absent", defaults to "present" size:: - Size of the image in dog vdi compatible units. + Size of the image in "dog vdi" compatible units. - Required if state == present. + Required if state is "present". diff --git a/cdist/conf/type/__qemu_img/man.text b/cdist/conf/type/__qemu_img/man.text index 39188ab0..0fe2bbec 100644 --- a/cdist/conf/type/__qemu_img/man.text +++ b/cdist/conf/type/__qemu_img/man.text @@ -14,17 +14,15 @@ The qemu-img program is used to create qemu images for qemu and (qemu-)kvm. -REQUIRED PARAMETERS -------------------- -size:: - Size of the image in qemu-img compatible units. - See qemu-img(1). - OPTIONAL PARAMETERS ------------------- state:: Either "present" or "absent", defaults to "present" +size:: + Size of the image in qemu-img compatible units. + + Required if state is "present". EXAMPLES @@ -42,9 +40,10 @@ __qemu_img /home/services/kvm/vm/myoldvm/system-disk --state absent SEE ALSO -------- - cdist-type(7) +- qemu-img(1) COPYING ------- -Copyright \(C) 2012 Nico Schottelius. Free use of this software is +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). diff --git a/cdist/conf/type/__qemu_img/parameter/optional b/cdist/conf/type/__qemu_img/parameter/optional index 71b9a32b..21aa421b 100644 --- a/cdist/conf/type/__qemu_img/parameter/optional +++ b/cdist/conf/type/__qemu_img/parameter/optional @@ -1,2 +1,3 @@ format state +size From 47b6149803b89a09d88522404191a345cd2278db Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 31 Mar 2014 21:23:40 +0200 Subject: [PATCH 51/51] ++changes Signed-off-by: Nico Schottelius --- docs/changelog | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/changelog b/docs/changelog index 8b66e95b..8d0cb31a 100644 --- a/docs/changelog +++ b/docs/changelog @@ -5,6 +5,10 @@ Changelog * Exception: No braces means author == Nico Schottelius +3.1.2: + * Type __qemu_img: size is optional, if state is not present + * New Type: __dog_vdi + 3.1.1: 2014-03-26 * Core: Make __object and __object_id available to code (Daniel Heule) * New explorer: cpu_cores (Daniel Heule/Thomas Oettli)