diff --git a/Makefile b/Makefile index 1962c96e..112b1411 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,13 @@ A2XM=a2x -f manpage --no-xmllint -a encoding=UTF-8 A2XH=a2x -f xhtml --no-xmllint -a encoding=UTF-8 +# Create cross-links in html man pages +# We look for something like "cdist-type(7)" and make a href out of it +# The first matching group is the man page name and the second group +# is the man page section (1 or 7). The first three lines of the input +# (xml, DOCTYPE, head tags) are ignored, since the head tags contains +# the title of the page and should not contain a href. +CROSSLINK=sed --in-place '1,3!s/\([[:alnum:]_-]*\)(\([17]\))/&<\/a>/g' helper=./bin/build-helper MANDIR=docs/man @@ -86,6 +93,7 @@ MANSTATICALL=$(MANSTATICMAN) $(MANSTATICHTML) # Creating the type html page %.html: %.text $(A2XH) $^ + $(CROSSLINK) $@ man: $(MANTYPEALL) $(MANREFALL) $(MANSTATICALL) @@ -99,7 +107,7 @@ man-dist: man check-date cp ${MAN7DSTDIR}/*.html ${MAN7DSTDIR}/*.css ${MANWEBDIR}/man7 cd ${MANWEBDIR} && git add . && git commit -m "cdist manpages update: $(CHANGELOG_VERSION)" || true -man-fix-link: web-pub +man-latest-link: web-pub # Fix ikiwiki, which does not like symlinks for pseudo security ssh tee.schottelius.org \ "cd /home/services/www/nico/www.nico.schottelius.org/www/software/cdist/man && rm -f latest && ln -sf "$(CHANGELOG_VERSION)" latest" @@ -146,7 +154,8 @@ web-dist: web-blog web-doc web-pub: web-dist man-dist speeches-dist cd "${WEBDIR}" && make pub -web-release-all: man-fix-link +web-release-all: man-latest-link +web-release-all-no-latest: web-pub ################################################################################ # Release: Mailinglist diff --git a/bin/build-helper b/bin/build-helper index bfd7d31c..d28c0616 100755 --- a/bin/build-helper +++ b/bin/build-helper @@ -104,6 +104,11 @@ eof ;; ml-release) + if [ $# -ne 1 ]; then + echo "$0 ml-release version" >&2 + exit 1 + fi + version=$1; shift to_a=cdist @@ -142,40 +147,22 @@ eof freecode-release) version=$1; shift - api_token=$(awk '/machine freecode login/ { print $8 }' ~/.netrc) - printf "Enter tag list for freecode release %s> " "$version" read taglist printf "Enter changelog for freecode release %s> " "$version" read changelog - echo "Submit preview" - cat << eof -tag_list = $taglist -changelog = $changelog -version = $version -eof - printf "Press enter to submit to freecode> " - read dummy - - cat << eof | cfreecode-api release-add cdist - { - "auth_code": "$api_token", - "release": { - "tag_list": "$taglist", - "version": "$version", - "changelog": "$changelog", - "hidden_from_frontpage": false - } - } -eof - + echo "Submitting to freecode ..." + python2 ~/p/foreign/freecode-submit-2.7/freecode-submit -P cdist \ + -v "$version" -c "$changelog" \ + -t "$taglist" \ + -n ;; 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 @@ -256,7 +243,11 @@ eof make pub # publish man, speeches, website - make web-release-all + if [ "$masterbranch" = yes ]; then + make web-release-all + else + make web-release-all-no-latest + fi # Ensure that pypi release has the right version "$0" version 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/interfaces b/cdist/conf/explorer/interfaces index 6804f2db..c1f2a57a 100755 --- a/cdist/conf/explorer/interfaces +++ b/cdist/conf/explorer/interfaces @@ -24,12 +24,12 @@ # # Use ip, if available -if command -v ip; then +if command -v ip >/dev/null; then ip -o link show | sed -n 's/^[0-9]\+: \(.\+\): <.*/\1/p' exit 0 fi -if ! command -v ifconfig; then +if ! command -v ifconfig >/dev/null; then # no ifconfig, nothing we could do exit 0 fi diff --git a/cdist/conf/explorer/machine_type b/cdist/conf/explorer/machine_type new file mode 100755 index 00000000..74789f5a --- /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 diff --git a/cdist/conf/type/__ccollect_source/explorer/stat b/cdist/conf/type/__ccollect_source/explorer/stat index 298221b7..7c86d94f 100755 --- a/cdist/conf/type/__ccollect_source/explorer/stat +++ b/cdist/conf/type/__ccollect_source/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 @@ -35,6 +35,15 @@ size: %Dz links: %Dl " "$destination" ;; + "macosx") + stat -f "type: %HT + owner: %Du %Su + group: %Dg %Sg + mode: %Lp %Sp + size: %Dz + links: %Dl + " "$destination" + ;; *) stat --printf="type: %F owner: %u %U diff --git a/cdist/conf/type/__directory/explorer/stat b/cdist/conf/type/__directory/explorer/stat index d8cdbb9e..077aa43b 100755 --- a/cdist/conf/type/__directory/explorer/stat +++ b/cdist/conf/type/__directory/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 @@ -33,6 +33,13 @@ group: %Dg %Sg mode: %Op %Sp " "$destination" ;; + "macosx") + stat -f "type: %HT + owner: %Du %Su + group: %Dg %Sg + mode: %Lp %Sp + " "$destination" + ;; *) stat --printf="type: %F owner: %u %U 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..56e4108a --- /dev/null +++ b/cdist/conf/type/__dog_vdi/gencode-remote @@ -0,0 +1,42 @@ +#!/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")" +num_vdi_lines=$(wc -l < "$__object/explorer/list") +name="$__object_id" + + +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 new file mode 100644 index 00000000..e3453ba7 --- /dev/null +++ b/cdist/conf/type/__dog_vdi/man.text @@ -0,0 +1,56 @@ +cdist-type__dog_vdi(7) +====================== +Nico Schottelius + + +NAME +---- +cdist-type__dog_vdi - Manage Sheepdog VM images + + +DESCRIPTION +----------- +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 is "present". + + + +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 +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- dog(8) +- qemu(1) + + +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/manifest b/cdist/conf/type/__dog_vdi/manifest new file mode 100644 index 00000000..be327a3a --- /dev/null +++ b/cdist/conf/type/__dog_vdi/manifest @@ -0,0 +1,37 @@ +#!/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")" + +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 + ;; +esac 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..c3ac4490 --- /dev/null +++ b/cdist/conf/type/__dog_vdi/parameter/optional @@ -0,0 +1,2 @@ +state +size diff --git a/cdist/conf/type/__file/explorer/stat b/cdist/conf/type/__file/explorer/stat index 298221b7..00e34cca 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 @@ -33,6 +33,15 @@ group: %Dg %Sg mode: %Op %Sp size: %Dz links: %Dl +" "$destination" + ;; + "macosx") + stat -f "type: %HT +owner: %Du %Su +group: %Dg %Sg +mode: %Lp %Sp +size: %Dz +links: %Dl " "$destination" ;; *) diff --git a/cdist/conf/type/__git/man.text b/cdist/conf/type/__git/man.text index 7c6b83cd..5f74108b 100644 --- a/cdist/conf/type/__git/man.text +++ b/cdist/conf/type/__git/man.text @@ -26,6 +26,7 @@ state:: branch:: Create this branch by checking out the remote branch of this name + Default branch is "master" group:: Group to chgrp to. diff --git a/cdist/conf/type/__git/manifest b/cdist/conf/type/__git/manifest index 7f6fee84..b2b0feb0 100644 --- a/cdist/conf/type/__git/manifest +++ b/cdist/conf/type/__git/manifest @@ -24,6 +24,9 @@ __package git --state present state_should="$(cat "$__object/parameter/state")" +owner="$(cat "$__object/parameter/owner")" +group="$(cat "$__object/parameter/group")" +mode="$(cat "$__object/parameter/mode")" # Let __directory handle removal of git repos @@ -33,7 +36,10 @@ case "$state_should" in ;; absent) - __directory "$__object_id" --state absent + __directory "$__object_id" --state absent \ + --owner "$owner" \ + --group "$group" \ + --mode "$mode" ;; *) diff --git a/cdist/conf/type/__hostname/explorer/hostname_file b/cdist/conf/type/__hostname/explorer/hostname_file index ed28c8a8..6a00aa9f 100755 --- a/cdist/conf/type/__hostname/explorer/hostname_file +++ b/cdist/conf/type/__hostname/explorer/hostname_file @@ -21,6 +21,10 @@ # Retrieve the contents of /etc/hostname # +# Almost any distribution if [ -f /etc/hostname ]; then cat /etc/hostname +# SuSE +elif [ -f /etc/HOSTNAME ]; then + cat /etc/HOSTNAME fi diff --git a/cdist/conf/type/__hostname/explorer/hostname_sysconfig b/cdist/conf/type/__hostname/explorer/hostname_sysconfig new file mode 100755 index 00000000..d0d7b4e7 --- /dev/null +++ b/cdist/conf/type/__hostname/explorer/hostname_sysconfig @@ -0,0 +1,26 @@ +#!/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 . +# +# +# Retrieve the contents of /etc/hostname +# + +if [ -f /etc/sysconfig/network ]; then + awk -F= '/^HOSTNAME=/ { print $2 }' /etc/sysconfig/network +fi diff --git a/cdist/conf/type/__hostname/gencode-remote b/cdist/conf/type/__hostname/gencode-remote index 3d208cbe..576f80bf 100755 --- a/cdist/conf/type/__hostname/gencode-remote +++ b/cdist/conf/type/__hostname/gencode-remote @@ -28,14 +28,28 @@ fi os=$(cat "$__global/explorer/os") name_running=$(cat "$__global/explorer/hostname") name_config=$(cat "$__object/explorer/hostname_file") +name_sysconfig=$(cat "$__object/explorer/hostname_sysconfig") has_hostnamectl=$(cat "$__object/explorer/has_hostnamectl") ################################################################################ # If everything is ok -> exit # -if [ "$name_config" = "$name_should" -a "$name_running" = "$name_should" ]; then - exit 0 -fi +case "$os" in + archlinux|debian|suse|ubuntu) + if [ "$name_config" = "$name_should" -a "$name_running" = "$name_should" ]; then + exit 0 + fi + ;; + centos) + if [ "$name_sysconfig" = "$name_should" -a "$name_running" = "$name_should" ]; then + exit 0 + fi + ;; + *) + echo "Unsupported os: $os" >&2 + exit 1 + ;; +esac ################################################################################ # Setup hostname @@ -45,6 +59,17 @@ echo changed >> "$__messages_out" if [ "$has_hostnamectl" ]; then echo "hostnamectl set-hostname '$name_should'" else - echo "hostname '$name_should'" - echo "printf '%s\n' '$name_should' > /etc/hostname" + case "$os" in + archlinux|debian|ubuntu) + echo "hostname '$name_should'" + echo "printf '%s\n' '$name_should' > /etc/hostname" + ;; + centos) + echo "hostname '$name_should'" + ;; + suse) + echo "hostname '$name_should'" + echo "printf '%s\n' '$name_should' > /etc/HOSTNAME" + ;; + esac fi diff --git a/cdist/conf/type/__hostname/manifest b/cdist/conf/type/__hostname/manifest index 0544a6f9..448e56da 100755 --- a/cdist/conf/type/__hostname/manifest +++ b/cdist/conf/type/__hostname/manifest @@ -20,6 +20,12 @@ # os=$(cat "$__global/explorer/os") +if [ -f "$__object/parameter/name" ]; then + name_should="$(cat "$__object/parameter/name")" +else + name_should="$(echo "${__target_host%%.*}")" +fi + not_supported() { echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 @@ -28,11 +34,18 @@ not_supported() { } case "$os" in - archlinux|debian|ubuntu) - # handled in gencode-remote - : - ;; - *) - not_supported - ;; + archlinux|debian|suse|ubuntu) + # handled in gencode-remote + : + ;; + centos) + __key_value sysconfig-hostname \ + --file /etc/sysconfig/network \ + --delimiter '=' \ + --key HOSTNAME \ + --value "$name_should" --exact_delimiter + ;; + *) + not_supported + ;; esac 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 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..1ceba212 100755 --- a/cdist/conf/type/__jail/explorer/status +++ b/cdist/conf/type/__jail/explorer/status @@ -32,14 +32,14 @@ else fi if [ -f "$__object/parameter/jaildir" ]; then - jaildir="$(cat "$__object/parameter/name")" + jaildir="$(cat "$__object/parameter/jaildir")" else jaildir="/usr/jail" fi # backslash-escaped $jaildir sjaildir="$(echo ${jaildir} | sed 's#/#\\/#g')" -jls_output="$(jls | grep "[ ^I]${sjaildir}\/${name}\$")" || true +jls_output="$(jls | grep "[ ]${sjaildir}\/${name}\$")" || true if [ -n "${jls_output}" ]; then echo "STARTED" diff --git a/cdist/conf/type/__jail/gencode-remote b/cdist/conf/type/__jail/gencode-remote index 141c8150..c88f3361 100755 --- a/cdist/conf/type/__jail/gencode-remote +++ b/cdist/conf/type/__jail/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2012 Jake Guffey (jake.guffey at eprotex.com) +# 2012,2014 Jake Guffey (jake.guffey at eprotex.com) # # This file is part of cdist. # @@ -104,6 +104,7 @@ stopJail() { # Check $status before issuing command if [ "$status" = "STARTED" ]; then echo "/etc/rc.d/jail stop ${name}" + echo "stop" >> "$__messages_out" fi } @@ -111,6 +112,7 @@ startJail() { # Check $status before issuing command if [ "$status" = "NOTSTART" ]; then echo "/etc/rc.d/jail start ${name}" + echo "start" >> "$__messages_out" fi } @@ -162,6 +164,7 @@ EOF rm -f /etc/rc.conf.bak fi EOF + echo "delete" >> "$__messages_out" } createJail() { @@ -215,6 +218,7 @@ cat <> "$__messages_out" # Create the ro+rw mountpoint entries in fstab cat <> "$__messages_out" fi # Add the normal entries into the jail's rc.conf diff --git a/cdist/conf/type/__jail/man.text b/cdist/conf/type/__jail/man.text index b439e0f5..be27e909 100644 --- a/cdist/conf/type/__jail/man.text +++ b/cdist/conf/type/__jail/man.text @@ -16,7 +16,7 @@ This type is used on FreeBSD to manage jails. REQUIRED PARAMETERS ------------------- state:: - Either "present" or "absent." + Either "present" or "absent", defaults to "present". jailbase:: The location of the .tgz archive containing the base fs for your jails. @@ -67,6 +67,19 @@ be removed then re-added with the correct IP address/netmask or the appropriate line (jail__ip="...") modified within rc.conf through some alternate means. +MESSAGES +-------- +start:: + The jail was started +stop:: + The jail was stopped +create: + The jail was created +delete:: + The jail was deleted +onboot:: + The jail was configured to start on boot + EXAMPLES -------- diff --git a/cdist/conf/type/__jail/manifest b/cdist/conf/type/__jail/manifest index 6a953241..2d29e263 100755 --- a/cdist/conf/type/__jail/manifest +++ b/cdist/conf/type/__jail/manifest @@ -29,8 +29,8 @@ # Can only be used on FreeBSD os="$(cat "$__global/explorer/os")" if [ ! "$os" = "freebsd" ]; then - echo "__jail can only be used on FreeBSD targets!" >&2 - exit 1 + echo "__jail can only be used on FreeBSD targets!" >&2 + exit 1 fi jaildir="$(cat "$__object/parameter/jaildir")" diff --git a/cdist/conf/type/__jail/parameter/default/state b/cdist/conf/type/__jail/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__jail/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__jail/parameter/optional b/cdist/conf/type/__jail/parameter/optional index 08ecd469..b36f0fa5 100644 --- a/cdist/conf/type/__jail/parameter/optional +++ b/cdist/conf/type/__jail/parameter/optional @@ -5,3 +5,4 @@ interface devfs-ruleset jaildir jailbase +state diff --git a/cdist/conf/type/__key_value/explorer/state b/cdist/conf/type/__key_value/explorer/state index 94a5ea7f..b990733d 100755 --- a/cdist/conf/type/__key_value/explorer/state +++ b/cdist/conf/type/__key_value/explorer/state @@ -1,6 +1,7 @@ #!/bin/sh # # 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2014 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. # @@ -18,36 +19,85 @@ # along with cdist. If not, see . # -key="$(cat "$__object/parameter/key" 2>/dev/null \ +export key="$(cat "$__object/parameter/key" 2>/dev/null \ || echo "$__object_id")" -state="$(cat "$__object/parameter/state" 2>/dev/null \ - || echo "present")" -file="$(cat "$__object/parameter/file")" -delimiter="$(cat "$__object/parameter/delimiter")" -value="$(cat "$__object/parameter/value" 2>/dev/null \ - || echo "__CDIST_NOTSET__")" +export state="$(cat "$__object/parameter/state")" -case "$state" in - absent) - if grep -q -E "^$key$delimiter+" "$file"; then - # if the key exists, with whatever value, we will have to remove it - # so report it as present - echo present - else - # key does not exist - echo absent - fi - ;; - present) - if grep -q -E "^$key$delimiter+$value$" "$file"; then - # key exists and value is same - echo present - elif grep -q -E "^$key$delimiter+" "$file"; then - # key exists, but value is empty or different - echo wrongvalue - else - # key does not exist - echo absent - fi - ;; -esac +file="$(cat "$__object/parameter/file")" + +if [ ! -f "$file" ]; then + echo "nosuchfile" + exit +fi + +export delimiter="$(cat "$__object/parameter/delimiter")" +export value="$(cat "$__object/parameter/value" 2>/dev/null \ + || echo "__CDIST_NOTSET__")" +if [ -f "$__object/parameter/exact_delimiter" ]; then + export exact_delimiter=1 +else + export exact_delimiter=0 +fi + +awk -f - "$file" <<"AWK_EOF" +BEGIN { + state=ENVIRON["state"] + key=ENVIRON["key"] + delimiter=ENVIRON["delimiter"] + value=ENVIRON["value"] + exact_delimiter=ENVIRON["exact_delimiter"] + found=0 +} +# enter the main loop +{ + i = index($0,key) + if(i == 1) { + delval = substr($0,length(key)+1) + delpos = index(delval,delimiter) + if(delpos == 0) { + # in this case, the delimiter was not found + next + } + if(delpos > 1) { + spaces = substr(delval,1,delpos-1) + sub(/[ \t]*/,"",spaces) + if( length(spaces) > 0 ) { + # if there are not only spaces between key and delimiter, + # continue since we we are on the wrong line + next + } + if( exact_delimiter == 1) { + # we have key and delimiter, but since additional spaces are not alowed + # return wrongformat + found=1 + print "wrongformat" + exit + } + } + found=1 + if(state == "absent") { + # on state absent, only the ocurance is relevant, so exit here + print "present" + exit + } + linevalue=substr(delval,delpos + length(delimiter)) + if(exact_delimiter == 0){ + #ok, now strip tabs and whitespaces at the beginning of the value + sub(/[ \t]*/,"",linevalue) + } + # Key with separator found + if(linevalue == value) { + # exact match found, so state is present + print "present" + } + else { + print "wrongvalue" + } + exit + } +} +END { + if(found == 0) + print "absent" +} +AWK_EOF diff --git a/cdist/conf/type/__key_value/files/remote_script.sh b/cdist/conf/type/__key_value/files/remote_script.sh new file mode 100644 index 00000000..282ba531 --- /dev/null +++ b/cdist/conf/type/__key_value/files/remote_script.sh @@ -0,0 +1,102 @@ +export key="$(cat "$__object/parameter/key" 2>/dev/null \ + || echo "$__object_id")" +export state="$(cat "$__object/parameter/state")" + +file="$(cat "$__object/parameter/file")" + +export delimiter="$(cat "$__object/parameter/delimiter")" +export value="$(cat "$__object/parameter/value" 2>/dev/null \ + || echo "__CDIST_NOTSET__")" +if [ -f "$__object/parameter/exact_delimiter" ]; then + export exact_delimiter=1 +else + export exact_delimiter=0 +fi + +tmpfile=$(mktemp "${file}.cdist.XXXXXXXXXX") +# preserve ownership and permissions by copying existing file over tmpfile +if [ -f "$file" ]; then + cp -p "$file" "$tmpfile" +else + touch "$file" +fi +awk -f - "$file" >"$tmpfile" <<"AWK_EOF" +BEGIN { + # import variables in a secure way .. + state=ENVIRON["state"] + key=ENVIRON["key"] + delimiter=ENVIRON["delimiter"] + value=ENVIRON["value"] + comment=ENVIRON["comment"] + exact_delimiter=ENVIRON["exact_delimiter"] + inserted=0 + lastline="" + lastlinepopulated=0 + line=key delimiter value +} +# enter the main loop +{ + # I dont use regex, this is by design, so we can match against every value without special meanings of chars ... + i = index($0,key) + if(i == 1) { + delval = substr($0,length(key)+1) + delpos = index(delval,delimiter) + if(delpos > 1) { + spaces = substr(delval,1,delpos-1) + sub(/[ \t]*/,"",spaces) + if( length(spaces) > 0 ) { + # if there are not only spaces between key and delimiter, + # continue since we we are on the wrong line + if(lastlinepopulated == 1) { + print lastline + } + lastline=$0 + lastlinepopulated=1 + next + } + } + if(state == "absent") { + if(lastline == comment) { + # if comment is present, clear lastlinepopulated flag + lastlinepopulated=0 + } + # if absent, simple yump over this line + next + } + else { + # if comment is present and not present in last line + if (lastlinepopulated == 1) { + print lastline + if( comment != "" && lastline != comment) { + print comment + } + lastlinepopulated=0 + } + inserted=1 + # state is present, so insert correct line here + print line + lastline=line + next + } + } + else { + if(lastlinepopulated == 1) { + print lastline + } + lastline=$0 + lastlinepopulated=1 + } +} +END { + if(lastlinepopulated == 1) { + print lastline + } + if(inserted == 0 && state == "present" ) { + if(comment != "" && lastline != comment){ + print comment + } + print line + } +} +AWK_EOF +mv -f "$tmpfile" "$file" diff --git a/cdist/conf/type/__key_value/gencode-remote b/cdist/conf/type/__key_value/gencode-remote index b79d9688..e6815cb6 100755 --- a/cdist/conf/type/__key_value/gencode-remote +++ b/cdist/conf/type/__key_value/gencode-remote @@ -1,7 +1,8 @@ #!/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) +# 2014 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. # @@ -19,52 +20,56 @@ # along with cdist. If not, see . # -key="$__object_id" -[ -f "$__object/parameter/key" ] && key="$(cat "$__object/parameter/key")" state_should="$(cat "$__object/parameter/state")" - -file="$(cat "$__object/parameter/file")" -delimiter="$(cat "$__object/parameter/delimiter")" -# escape double quotes, as that is what we use ourself below -value_escaped="$(cat "$__object/parameter/value" | sed -e "s/\([\"]\)/\\\\\1/g")" state_is="$(cat "$__object/explorer/state")" -[ "$state_is" = "$state_should" ] && exit 0 +if [ "$state_is" = "$state_should" ]; then + exit 0 +fi +# here we check only if the states are valid, +# emmit messages and +# let awk do the work ... case "$state_should" in absent) - # remove lines starting with key - cat << DONE -tmpfile=\$(mktemp ${file}.cdist.XXXXXXXXXX) -# preserve ownership and permissions by copying existing file over tmpfile -cp -p "$file" "\$tmpfile" -sed '/^$key\($delimiter\+\)/d' "$file" > "\$tmpfile" -mv -f "\$tmpfile" "$file" -DONE - ;; - present) case "$state_is" in - absent) - # add new key and value - printf 'echo "%s%s%s" >> "%s"' "$key" "$delimiter" "$value_escaped" "$file" + absent|nosuchfile) + # nothing to do ;; - wrongvalue) - # change exisiting value - cat << DONE -tmpfile=\$(mktemp ${file}.cdist.XXXXXXXXXX) -# preserve ownership and permissions by copying existing file over tmpfile -cp -p "$file" "\$tmpfile" -sed "s|^$key\($delimiter\+\).*|$key\\1$value_escaped|" "$file" > "\$tmpfile" -mv -f "\$tmpfile" "$file" -DONE + wrongformat|wrongvalue|present) + echo "remove" >> "$__messages_out" ;; *) echo "Unknown explorer state: $state_is" >&2 exit 1 + ;; + esac + ;; + present) + case "$state_is" in + nosuchfile) + echo "create" >> "$__messages_out" + ;; + absent) + echo "insert" >> "$__messages_out" + ;; + wrongformated|wrongvalue) + echo "change" >> "$__messages_out" + ;; + present) + # nothing to do + ;; + *) + echo "Unknown explorer state: $state_is" >&2 + exit 1 + ;; esac ;; *) echo "Unknown state: $state_should" >&2 exit 1 + ;; esac + +cat "$__type/files/remote_script.sh" diff --git a/cdist/conf/type/__key_value/man.text b/cdist/conf/type/__key_value/man.text index 1423fc7d..d4c8e2cc 100644 --- a/cdist/conf/type/__key_value/man.text +++ b/cdist/conf/type/__key_value/man.text @@ -25,12 +25,36 @@ delimiter:: OPTIONAL PARAMETERS ------------------- state:: - present or absent, defaults to present. If present, sets the key to value, - if absent, removes the key from the file. + present or absent, defaults to present. If present, sets the key to value, + if absent, removes the key from the file. key:: - The key to change. Defaults to object_id. + The key to change. Defaults to object_id. value:: - The value for the key. Optional if state=absent, required otherwise. + The value for the key. Optional if state=absent, required otherwise. +comment:: + If supplied, the value will be inserted before the line with the key, + but only if the key or value must be changed. + You need to ensure yourself that the line is prefixed with the correct + comment sign. (for example # or ; or wathever ..) + + +BOOLEAN PARAMETERS +------------------ +exact_delimiter:: + If supplied, treat additional whitespaces between key, delimiter and value + as wrong value. + + +MESSAGES +-------- +remove:: + Removed existing key and value +insert:: + Added key and value +change:: + Changed value of existing key +create:: + A new line was inserted in a new file EXAMPLES @@ -46,13 +70,19 @@ __key_value my-fancy-id --file /etc/login.defs --key SYS_UID_MAX --value 666 \ # Enable packet forwarding __key_value net.ipv4.ip_forward --file /etc/sysctl.conf --value 1 \ - --delimiter '=' + --delimiter ' = ' --comment '# my linux kernel should act as a router' # Remove existing key/value __key_value LEGACY_KEY --file /etc/somefile --state absent --delimiter '=' -------------------------------------------------------------------------------- +MORE INFORMATION +---------------- +This type try to handle as many values as possible, so it doesn't use regexes. +So you need to exactly specify the key and delimiter. Delimiter can be of any lenght. + + SEE ALSO -------- - cdist-type(7) diff --git a/cdist/conf/type/__key_value/parameter/boolean b/cdist/conf/type/__key_value/parameter/boolean new file mode 100644 index 00000000..190831c1 --- /dev/null +++ b/cdist/conf/type/__key_value/parameter/boolean @@ -0,0 +1 @@ +exact_delimiter diff --git a/cdist/conf/type/__key_value/parameter/default/comment b/cdist/conf/type/__key_value/parameter/default/comment new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/cdist/conf/type/__key_value/parameter/default/comment @@ -0,0 +1 @@ + diff --git a/cdist/conf/type/__key_value/parameter/optional b/cdist/conf/type/__key_value/parameter/optional index 483e3192..666be2ae 100644 --- a/cdist/conf/type/__key_value/parameter/optional +++ b/cdist/conf/type/__key_value/parameter/optional @@ -1,3 +1,4 @@ key value state +comment diff --git a/cdist/conf/type/__line/gencode-remote b/cdist/conf/type/__line/gencode-remote index 1fadf454..f73444e3 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 || true +mv -f "\$tmpfile" "$file" eof ;; *) diff --git a/cdist/conf/type/__link/explorer/state b/cdist/conf/type/__link/explorer/state index a9220a3c..b8d8fc2b 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,13 @@ 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 + # ignore trailing slashes for comparison + 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..9e7831c7 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" @@ -50,20 +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 + 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 ;; *) diff --git a/cdist/conf/type/__locale/man.text b/cdist/conf/type/__locale/man.text index f76c2059..5ccd3eab 100644 --- a/cdist/conf/type/__locale/man.text +++ b/cdist/conf/type/__locale/man.text @@ -16,7 +16,7 @@ This cdist type allows you to setup locales. OPTIONAL PARAMETERS ------------------- state:: - 'present' or 'absent' + 'present' or 'absent', defaults to present EXAMPLES @@ -43,5 +43,5 @@ SEE ALSO COPYING ------- -Copyright \(C) 2013 Nico Schottelius. Free use of this software is +Copyright \(C) 2013-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/__locale/manifest b/cdist/conf/type/__locale/manifest index 5dd5fd8f..ac953662 100644 --- a/cdist/conf/type/__locale/manifest +++ b/cdist/conf/type/__locale/manifest @@ -1,6 +1,6 @@ #!/bin/sh # -# 2013 Nico Schottelius (nico-cdist at schottelius.org) +# 2013-2014 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -29,4 +29,12 @@ case "$os" in # Debian needs a seperate package __package locales --state present ;; + suse) + : + ;; + *) + echo "Sorry, do not know how to handle os: $os" >&2 + echo "Please edit the type ${__type##*/} to fix this." >&2 + exit 1 + ;; esac diff --git a/cdist/conf/type/__package_pkg_openbsd/gencode-remote b/cdist/conf/type/__package_pkg_openbsd/gencode-remote index 1df87997..08e15e89 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,12 +68,18 @@ case "$state_should" in present) # use this because pkg_add doesn't properly handle errors cat << eof -status=\$(pkg_add "$pkgopts" "$name--$flavor") +export PKG_PATH="$pkg_path" +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 ;; @@ -79,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 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 -------------------------------------------------------------------------------- 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 diff --git a/cdist/conf/type/__package_yum/gencode-remote b/cdist/conf/type/__package_yum/gencode-remote index 5f0e8ac8..32a794a0 100755 --- a/cdist/conf/type/__package_yum/gencode-remote +++ b/cdist/conf/type/__package_yum/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2014 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -27,6 +27,14 @@ else name="$__object_id" fi +# Support installing from an URL +if [ -f "$__object/parameter/url" ]; then + install_name="$(cat "$__object/parameter/url")" +else + install_name="$name" +fi + + state_should="$(cat "$__object/parameter/state")" if grep -q -E "(centos|redhat|amazon)" "$__global/explorer/os"; then @@ -47,7 +55,7 @@ fi case "$state_should" in present) - echo yum $opts install \"$name\" + echo yum $opts install \"$install_name\" ;; absent) echo yum $opts remove \"$name\" diff --git a/cdist/conf/type/__package_yum/man.text b/cdist/conf/type/__package_yum/man.text index d958dd1e..65e1be67 100644 --- a/cdist/conf/type/__package_yum/man.text +++ b/cdist/conf/type/__package_yum/man.text @@ -27,6 +27,8 @@ name:: state:: Either "present" or "absent", defaults to "present" +url:: + URL to use for the package EXAMPLES @@ -41,6 +43,9 @@ __package_yum python --state present --name python2 # Remove obsolete package __package_yum puppet --state absent + +__package epel-release-6-8 \ + --url http://mirror.switch.ch/ftp/mirror/epel/6/i386/epel-release-6-8.noarch.rpm -------------------------------------------------------------------------------- diff --git a/cdist/conf/type/__package_yum/parameter/optional b/cdist/conf/type/__package_yum/parameter/optional index 1b423dc4..9293119d 100644 --- a/cdist/conf/type/__package_yum/parameter/optional +++ b/cdist/conf/type/__package_yum/parameter/optional @@ -1,2 +1,3 @@ name state +url diff --git a/cdist/conf/type/__pf_ruleset/man.text b/cdist/conf/type/__pf_ruleset/man.text index 0dc07f71..29efe065 100644 --- a/cdist/conf/type/__pf_ruleset/man.text +++ b/cdist/conf/type/__pf_ruleset/man.text @@ -16,7 +16,7 @@ This type is used on *BSD systems to manage the pf firewall's ruleset. REQUIRED PARAMETERS ------------------- state:: - Either "absent" (no ruleset at all) or "present" + Either "absent" (no ruleset at all) or "present", defaults to "present". OPTIONAL PARAMETERS diff --git a/cdist/conf/type/__pf_ruleset/parameter/default/state b/cdist/conf/type/__pf_ruleset/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__pf_ruleset/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__pf_ruleset/parameter/optional b/cdist/conf/type/__pf_ruleset/parameter/optional index 5a18cd2f..d77f3048 100644 --- a/cdist/conf/type/__pf_ruleset/parameter/optional +++ b/cdist/conf/type/__pf_ruleset/parameter/optional @@ -1 +1,2 @@ source +state diff --git a/cdist/conf/type/__postgres_database/gencode-remote b/cdist/conf/type/__postgres_database/gencode-remote index 0ffc842a..c097efce 100755 --- a/cdist/conf/type/__postgres_database/gencode-remote +++ b/cdist/conf/type/__postgres_database/gencode-remote @@ -19,8 +19,7 @@ # name="$__object_id" -state_should="present" -[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" +state_should="$(cat "$__object/parameter/state")" state_is="$(cat "$__object/explorer/state")" if [ "$state_should" != "$state_is" ]; then diff --git a/cdist/conf/type/__postgres_database/man.text b/cdist/conf/type/__postgres_database/man.text index 88259b6f..c7c0d3cd 100644 --- a/cdist/conf/type/__postgres_database/man.text +++ b/cdist/conf/type/__postgres_database/man.text @@ -16,7 +16,7 @@ This cdist type allows you to create or drop postgres databases. OPTIONAL PARAMETERS ------------------- state:: - either 'present' or 'absent' + either 'present' or 'absent', defaults to 'present'. owner:: the role owning this database diff --git a/cdist/conf/type/__postgres_database/parameter/default/state b/cdist/conf/type/__postgres_database/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__postgres_database/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__postgres_role/gencode-remote b/cdist/conf/type/__postgres_role/gencode-remote index 65a9d588..0230e48e 100755 --- a/cdist/conf/type/__postgres_role/gencode-remote +++ b/cdist/conf/type/__postgres_role/gencode-remote @@ -20,8 +20,7 @@ name="$__object_id" state_is="$(cat "$__object/explorer/state")" -state_should="present" -[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" +state_should="$(cat "$__object/parameter/state")" [ "$state_is" = "$state_should" ] && exit 0 diff --git a/cdist/conf/type/__postgres_role/parameter/default/state b/cdist/conf/type/__postgres_role/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__postgres_role/parameter/default/state @@ -0,0 +1 @@ +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/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/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 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 diff --git a/cdist/conf/type/__rbenv/man.text b/cdist/conf/type/__rbenv/man.text new file mode 100644 index 00000000..c6ed5de2 --- /dev/null +++ b/cdist/conf/type/__rbenv/man.text @@ -0,0 +1,49 @@ +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" + +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). diff --git a/cdist/conf/type/__rbenv/manifest b/cdist/conf/type/__rbenv/manifest new file mode 100644 index 00000000..767abdba --- /dev/null +++ b/cdist/conf/type/__rbenv/manifest @@ -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 . +# +# + +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" 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/__jail/parameter/required b/cdist/conf/type/__rbenv/parameter/optional similarity index 100% rename from cdist/conf/type/__jail/parameter/required rename to cdist/conf/type/__rbenv/parameter/optional 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 diff --git a/cdist/conf/type/__rvm/man.text b/cdist/conf/type/__rvm/man.text index c1f83e60..0408d125 100644 --- a/cdist/conf/type/__rvm/man.text +++ b/cdist/conf/type/__rvm/man.text @@ -16,7 +16,7 @@ RVM is the Ruby enVironment Manager for the Ruby programming language. REQUIRED PARAMETERS ------------------- state:: - Either "present" or "absent". + Either "present" or "absent", defaults to "present". EXAMPLES diff --git a/cdist/conf/type/__rvm/parameter/default/state b/cdist/conf/type/__rvm/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__rvm/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__pf_ruleset/parameter/required b/cdist/conf/type/__rvm/parameter/optional similarity index 100% rename from cdist/conf/type/__pf_ruleset/parameter/required rename to cdist/conf/type/__rvm/parameter/optional diff --git a/cdist/conf/type/__rvm_gem/man.text b/cdist/conf/type/__rvm_gem/man.text index 2b72e7ae..d7eff3be 100644 --- a/cdist/conf/type/__rvm_gem/man.text +++ b/cdist/conf/type/__rvm_gem/man.text @@ -20,7 +20,7 @@ user:: gemset:: The gemset to use state:: - Either "present" or "absent" + Either "present" or "absent", defaults to "present". OPTIONAL PARAMETERS ------------------- diff --git a/cdist/conf/type/__rvm_gem/parameter/default/state b/cdist/conf/type/__rvm_gem/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__rvm_gem/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__rvm_gem/parameter/optional b/cdist/conf/type/__rvm_gem/parameter/optional index 4ad96d51..96983811 100644 --- a/cdist/conf/type/__rvm_gem/parameter/optional +++ b/cdist/conf/type/__rvm_gem/parameter/optional @@ -1 +1,2 @@ default +state diff --git a/cdist/conf/type/__rvm_gem/parameter/required b/cdist/conf/type/__rvm_gem/parameter/required index 75f60bb8..58243a95 100644 --- a/cdist/conf/type/__rvm_gem/parameter/required +++ b/cdist/conf/type/__rvm_gem/parameter/required @@ -1,3 +1,2 @@ -state gemset user diff --git a/cdist/conf/type/__rvm_gemset/man.text b/cdist/conf/type/__rvm_gemset/man.text index 44c0c555..e85425f3 100644 --- a/cdist/conf/type/__rvm_gemset/man.text +++ b/cdist/conf/type/__rvm_gemset/man.text @@ -18,7 +18,7 @@ REQUIRED PARAMETERS user:: The remote user account to use state:: - Either "present" or "absent". + Either "present" or "absent", defaults to "present". BOOLEAN PARAMETERS ------------------- diff --git a/cdist/conf/type/__rvm_gemset/parameter/default/state b/cdist/conf/type/__rvm_gemset/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__rvm_gemset/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__rvm/parameter/required b/cdist/conf/type/__rvm_gemset/parameter/optional similarity index 100% rename from cdist/conf/type/__rvm/parameter/required rename to cdist/conf/type/__rvm_gemset/parameter/optional diff --git a/cdist/conf/type/__rvm_gemset/parameter/required b/cdist/conf/type/__rvm_gemset/parameter/required index 5aea6f1e..4eb8387f 100644 --- a/cdist/conf/type/__rvm_gemset/parameter/required +++ b/cdist/conf/type/__rvm_gemset/parameter/required @@ -1,2 +1 @@ -state user diff --git a/cdist/conf/type/__rvm_ruby/man.text b/cdist/conf/type/__rvm_ruby/man.text index dbbab85e..6419a4d4 100644 --- a/cdist/conf/type/__rvm_ruby/man.text +++ b/cdist/conf/type/__rvm_ruby/man.text @@ -18,7 +18,7 @@ REQUIRED PARAMETERS user:: The remote user account to use state:: - Either "present" or "absent". + Either "present" or "absent", defaults to "present". BOOLEAN PARAMETERS ------------------ diff --git a/cdist/conf/type/__rvm_ruby/parameter/default/state b/cdist/conf/type/__rvm_ruby/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__rvm_ruby/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__rvm_ruby/parameter/optional b/cdist/conf/type/__rvm_ruby/parameter/optional new file mode 100644 index 00000000..ff72b5c7 --- /dev/null +++ b/cdist/conf/type/__rvm_ruby/parameter/optional @@ -0,0 +1 @@ +state diff --git a/cdist/conf/type/__rvm_ruby/parameter/required b/cdist/conf/type/__rvm_ruby/parameter/required index 5aea6f1e..4eb8387f 100644 --- a/cdist/conf/type/__rvm_ruby/parameter/required +++ b/cdist/conf/type/__rvm_ruby/parameter/required @@ -1,2 +1 @@ -state user 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..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 \ @@ -97,5 +93,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..1c9df208 100755 --- a/cdist/conf/type/__ssh_authorized_keys/manifest +++ b/cdist/conf/type/__ssh_authorized_keys/manifest @@ -1,6 +1,7 @@ #!/bin/sh # -# 2012 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012-2014 Steven Armstrong (steven-cdist at armstrong.cc) +# 2014 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -32,7 +33,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 +57,32 @@ 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 +# FIXME: remove me in 3.2+ __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 +} + +while read key; do + cksum_key="$(_cksum "$key")" + line_id="${owner}-${cksum_key}" + + set -- "$line_id" + set -- "$@" --file "$file" + set -- "$@" --regex ".*$key.*" + if [ "$state" = 'present' ]; then + set -- "$@" --line "$key" + fi + set -- "$@" --state "$state" + # Ensure __line does not read stdin + require="__block/$__object_name" __line "$@" < /dev/null +done < "$__object/parameter/key" 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 diff --git a/cdist/conf/type/__timezone/manifest b/cdist/conf/type/__timezone/manifest index 81de0217..36caab72 100755 --- a/cdist/conf/type/__timezone/manifest +++ b/cdist/conf/type/__timezone/manifest @@ -27,13 +27,18 @@ os=$(cat "$__global/explorer/os") case "$os" in archlinux|debian|ubuntu) - __package tzdata --state present - require="__package/tzdata" __link /etc/localtime \ - --source "/usr/share/zoneinfo/${timezone}" \ - --type symbolic + package=tzdata + ;; + suse) + package=timezone ;; *) echo "Unsupported OS $os" >&2 exit 1 ;; esac + +__package "$package" --state present +require="__package/$package" __link /etc/localtime \ + --source "/usr/share/zoneinfo/${timezone}" \ + --type symbolic 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 diff --git a/cdist/conf/type/__yum_repo/files/repo.template b/cdist/conf/type/__yum_repo/files/repo.template new file mode 100755 index 00000000..3e14c8b6 --- /dev/null +++ b/cdist/conf/type/__yum_repo/files/repo.template @@ -0,0 +1,61 @@ +#!/bin/sh +set -u +cat << DONE +# Created by cdist ${__type##*/} +# Do not change. Changes will be overwritten. +# +[$repo_name] +DONE +# single value properties +single_value='name +metalink +mirrorlist +gpgcakey +gpgcheck +exclude +includepkgs +failovermethod +timeout +http_caching +retries +throttle +bandwidth +sslcacert +sslverify +sslclientcert +sslclientkey +ssl_check_cert_permissions +metadata_expire +mirrorlist_expire +proxy +proxy_username +proxy_password +username +password +cost' +for key in $single_value; do + if [ -f "$__object/parameter/$key" ]; then + printf '%s=%s\n' "$key" "$(cat "$__object/parameter/$key")" + fi +done +# multi value properties +for key in baseurl gpgkey; do + if [ -f "$__object/parameter/$key" ]; then + printf '%s=' "$key" + prefix='' + while read line; do + printf '%s%s\n' "$prefix" "$line" + prefix=' ' + done < "$__object/parameter/$key" + fi +done +# boolean properties +for key in enabled repo_gpgcheck keepalive skip_if_unavailable; do + if [ -f "$__object/parameter/$key" ]; then + printf '%s=1\n' "$key" + fi +done +# special cases +if [ -f "$__object/parameter/disablegroups" ]; then + printf 'enablegroups=0\n' +fi diff --git a/cdist/conf/type/__yum_repo/man.text b/cdist/conf/type/__yum_repo/man.text new file mode 100644 index 00000000..549cf336 --- /dev/null +++ b/cdist/conf/type/__yum_repo/man.text @@ -0,0 +1,91 @@ +cdist-type__yum_repo(7) +======================= +Steven Armstrong + + +NAME +---- +cdist-type__yum_repo - manage yum repositories + + +DESCRIPTION +----------- +For all undocumented parameters see yum.conf(5). + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +state:: + 'present' or 'absent'. Defaults to 'present' +repositoryid:: + Defaults to __object_id. +name:: +baseurl:: + Can be specified multiple times. +metalink:: +mirrorlist:: +gpgkey:: + Can be specified multiple times. +gpgcakey:: +gpgcheck:: +exclude:: +includepkgs:: +failovermethod:: +timeout:: +http_caching:: +retries:: +throttle:: +bandwidth:: +sslcacert:: +sslverify:: +sslclientcert:: +sslclientkey:: +ssl_check_cert_permissions:: +metadata_expire:: +mirrorlist_expire:: +proxy:: +proxy_username:: +proxy_password:: +username:: +password:: +cost:: + + +BOOLEAN PARAMETERS +------------------ +enabled:: +repo_gpgcheck:: +disablegroups:: + ! enablegroups +keepalive:: +skip_if_unavailable:: + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__yum_repo epel \ + --name 'Extra Packages for Enterprise Linux 6 - $basearch' \ + --mirrorlist 'https://mirrors.fedoraproject.org/metalink?repo=epel-$releasever&arch=$basearch' \ + --failovermethod priority \ + --enabled \ + --gpgcheck 1 \ + --gpgkey https://fedoraproject.org/static/0608B895.txt +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 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/__yum_repo/manifest b/cdist/conf/type/__yum_repo/manifest new file mode 100755 index 00000000..9bb63c3c --- /dev/null +++ b/cdist/conf/type/__yum_repo/manifest @@ -0,0 +1,40 @@ +#!/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 . +# + +os=$(cat "$__global/explorer/os") +state="$(cat "$__object/parameter/state")" + +case "$os" in + centos) + repo_name="$__object_id" + export repo_name + repo_file="/etc/yum.repos.d/${repo_name}.repo" + "$__type/files/repo.template" | \ + __file "$repo_file" \ + --owner root --group root --mode 644 \ + --state "$state" \ + --source - + ;; + *) + echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 + echo "Please contribute an implementation for it if you can." >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__yum_repo/notes b/cdist/conf/type/__yum_repo/notes new file mode 100644 index 00000000..67fa617b --- /dev/null +++ b/cdist/conf/type/__yum_repo/notes @@ -0,0 +1,3 @@ +https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/sec-Configuring_Yum_and_Yum_Repositories.html +https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux_OpenStack_Platform/2/html/Getting_Started_Guide/sect-Configuring_Software_Repositories.html +http://docs.puppetlabs.com/references/latest/type.html#yumrepo diff --git a/cdist/conf/type/__yum_repo/parameter/boolean b/cdist/conf/type/__yum_repo/parameter/boolean new file mode 100644 index 00000000..2eb49a93 --- /dev/null +++ b/cdist/conf/type/__yum_repo/parameter/boolean @@ -0,0 +1,5 @@ +enabled +repo_gpgcheck +disablegroups +keepalive +skip_if_unavailable diff --git a/cdist/conf/type/__yum_repo/parameter/default/state b/cdist/conf/type/__yum_repo/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__yum_repo/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__yum_repo/parameter/optional b/cdist/conf/type/__yum_repo/parameter/optional new file mode 100644 index 00000000..7e185701 --- /dev/null +++ b/cdist/conf/type/__yum_repo/parameter/optional @@ -0,0 +1,27 @@ +bandwidth +cost +exclude +failovermethod +gpgcakey +gpgcheck +http_caching +includepkgs +metadata_expire +mirrorlist +mirrorlist_expire +name +password +proxy +proxy_password +proxy_username +repositoryid +retries +sslcacert +ssl_check_cert_permissions +sslclientcert +sslclientkey +sslverify +state +throttle +timeout +username diff --git a/cdist/conf/type/__yum_repo/parameter/optional_multiple b/cdist/conf/type/__yum_repo/parameter/optional_multiple new file mode 100644 index 00000000..6467915b --- /dev/null +++ b/cdist/conf/type/__yum_repo/parameter/optional_multiple @@ -0,0 +1,2 @@ +baseurl +gpgkey diff --git a/cdist/conf/type/__zypper_repo/explorer/repo_id b/cdist/conf/type/__zypper_repo/explorer/repo_id index 83a698b7..be0b9771 100644 --- a/cdist/conf/type/__zypper_repo/explorer/repo_id +++ b/cdist/conf/type/__zypper_repo/explorer/repo_id @@ -18,11 +18,11 @@ # along with cdist. If not, see . # # -# Retrieve the id from the repo with the uri from parameter repo_uri - parsed zypper output +# Retrieve the id from the repo with the uri from parameter uri - parsed zypper output # # -if [ -f "$__object/parameter/repo_uri" ]; then - uri="$(cat "$__object/parameter/repo_uri")" +if [ -f "$__object/parameter/uri" ]; then + uri="$(cat "$__object/parameter/uri")" else uri="$__object_id" fi diff --git a/cdist/conf/type/__zypper_repo/gencode-remote b/cdist/conf/type/__zypper_repo/gencode-remote index f678552b..26199c75 100644 --- a/cdist/conf/type/__zypper_repo/gencode-remote +++ b/cdist/conf/type/__zypper_repo/gencode-remote @@ -25,7 +25,7 @@ #exec >&2 #set -x -zypper_def_opts=" -q " +zypper_def_opts=" -q --non-interactive --gpg-auto-import-keys " if [ -f "$__object/parameter/repo_desc" ]; then desc="$(cat "$__object/parameter/repo_desc")" @@ -33,8 +33,8 @@ else desc="$__object_id" fi -if [ -f "$__object/parameter/repo_uri" ]; then - uri="$(cat "$__object/parameter/repo_uri")" +if [ -f "$__object/parameter/uri" ]; then + uri="$(cat "$__object/parameter/uri")" else uri="$__object_id" fi @@ -65,7 +65,7 @@ fi case "$state" in present) if [ -z "$desc" ] || [ -z "$uri" ]; then - echo "parameter repo_desc and repo_uri for $state needed" >&2 + echo "parameter repo_desc and uri for $state needed" >&2 exit 4 fi if [ -z "$repo_id" ]; then diff --git a/cdist/conf/type/__zypper_repo/man.text b/cdist/conf/type/__zypper_repo/man.text index 6ea88f16..e8024ce5 100644 --- a/cdist/conf/type/__zypper_repo/man.text +++ b/cdist/conf/type/__zypper_repo/man.text @@ -22,13 +22,13 @@ OPTIONAL PARAMETERS ------------------- state:: Either "present" or "absent" or "enabled" or "disabled", defaults to "present" + - #present# - make sure that the repo is aviable, needs repo_uri and repo_desc + - for all following states, the repo can be searched via repo_id or repo_uri + + #present# - make sure that the repo is aviable, needs uri and repo_desc + + for all following states, the repo can be searched via repo_id or uri + #absent# - drop the repo if found + #enabled# - a repo can have state disabled if installed via zypper service (ris), in this case, you can enable the repo + #disabled# - instead of absent (drop), a repo can also set to disabled, wich makes it inaccessible + -repo_uri:: +uri:: If supplied, use the uri and not the object id as repo uri. repo_desc:: @@ -43,10 +43,10 @@ EXAMPLES -------------------------------------------------------------------------------- # Ensure testrepo in installed -__zypper_repo testrepo --state present --repo_uri http://url.to.your.repo/with/path +__zypper_repo testrepo --state present --uri http://url.to.your.repo/with/path # Drop repo by repo uri -__zypper_repo testrepo --state absent --repo_uri http://url.to.your.repo/with/path +__zypper_repo testrepo --state absent --uri http://url.to.your.repo/with/path # Drop repo by id number (attention: repos are always numbered from 1 to max) __zypper_repo testrepo --state absent --repo_id 1 @@ -55,7 +55,7 @@ __zypper_repo testrepo --state absent --repo_id 1 __zypper_repo testrepo2 --state enabled --repo_id 2 # enable repo by uri -__zypper_repo testrepo3 --state enabled --repo_uri http://url.to.your.repo/with/path +__zypper_repo testrepo3 --state enabled --uri http://url.to.your.repo/with/path # disable a repo works like enabling it __zypper_repo testrepo4 --state disabled --repo_id 4 diff --git a/cdist/conf/type/__zypper_repo/parameter/optional b/cdist/conf/type/__zypper_repo/parameter/optional index 6f5a8325..fe40e350 100644 --- a/cdist/conf/type/__zypper_repo/parameter/optional +++ b/cdist/conf/type/__zypper_repo/parameter/optional @@ -1,4 +1,4 @@ state -repo_uri +uri repo_desc repo_id diff --git a/cdist/conf/type/__zypper_service/explorer/service_id b/cdist/conf/type/__zypper_service/explorer/service_id index 9c3d3a2d..bf5f0260 100644 --- a/cdist/conf/type/__zypper_service/explorer/service_id +++ b/cdist/conf/type/__zypper_service/explorer/service_id @@ -20,8 +20,8 @@ # # Manage services with Zypper (mostly suse) # -if [ -f "$__object/parameter/service_uri" ]; then - uri="$(cat "$__object/parameter/service_uri")" +if [ -f "$__object/parameter/uri" ]; then + uri="$(cat "$__object/parameter/uri")" else uri="/$__object_id" fi diff --git a/cdist/conf/type/__zypper_service/explorer/service_uri b/cdist/conf/type/__zypper_service/explorer/service_uri index 2f4f8960..bcad4ec8 100644 --- a/cdist/conf/type/__zypper_service/explorer/service_uri +++ b/cdist/conf/type/__zypper_service/explorer/service_uri @@ -20,8 +20,8 @@ # # Manage services with Zypper (mostly suse) # -if [ -f "$__object/parameter/service_uri" ]; then - uri="$(cat "$__object/parameter/service_uri")" +if [ -f "$__object/parameter/uri" ]; then + uri="$(cat "$__object/parameter/uri")" else uri="/$__object_id" fi diff --git a/cdist/conf/type/__zypper_service/gencode-remote b/cdist/conf/type/__zypper_service/gencode-remote index df8d1660..d16ba8ee 100644 --- a/cdist/conf/type/__zypper_service/gencode-remote +++ b/cdist/conf/type/__zypper_service/gencode-remote @@ -25,7 +25,7 @@ #exec >&2 #set -x -zypper_def_opts=" -q " +zypper_def_opts=" -q --non-interactive --gpg-auto-import-keys " if [ -f "$__object/parameter/service_desc" ]; then desc="$(cat "$__object/parameter/service_desc")" @@ -33,8 +33,8 @@ else desc="$__object_id" fi -if [ -f "$__object/parameter/service_uri" ]; then - uri="$(cat "$__object/parameter/service_uri")" +if [ -f "$__object/parameter/uri" ]; then + uri="$(cat "$__object/parameter/uri")" else uri="$__object_id" fi @@ -73,10 +73,12 @@ case "$state_should" in present) echo zypper $zypper_def_opts addservice -t "$stype" "$uri" \"$desc\" echo zypper $zypper_def_opts refs + echo zypper $zypper_def_opts ref ;; absent) echo zypper $zypper_def_opts removeservice "$service_id" echo zypper $zypper_def_opts refs + echo zypper $zypper_def_opts ref ;; *) echo "Unknown state: $state_should" >&2 diff --git a/cdist/conf/type/__zypper_service/man.text b/cdist/conf/type/__zypper_service/man.text index 31543d93..b6bba660 100644 --- a/cdist/conf/type/__zypper_service/man.text +++ b/cdist/conf/type/__zypper_service/man.text @@ -15,7 +15,7 @@ zypper is usually used on SuSE systems to manage services. REQUIRED PARAMETERS ------------------- -service_uri:: +uri:: Uri of the service @@ -45,13 +45,13 @@ EXAMPLES -------------------------------------------------------------------------------- # Ensure that internal SLES11 SP3 RIS is in installed and all other services and repos are discarded -__zypper_service INTERNAL_SLES11_SP3 --service_desc "Internal SLES11 SP3 RIS" --service_uri "http://path/to/your/ris/dir" --remove-all-other-services --remove-all-repos +__zypper_service INTERNAL_SLES11_SP3 --service_desc "Internal SLES11 SP3 RIS" --uri "http://path/to/your/ris/dir" --remove-all-other-services --remove-all-repos # Ensure that internal SLES11 SP3 RIS is in installed, no changes to ohter services or repos -__zypper_service INTERNAL_SLES11_SP3 --service_desc "Internal SLES11 SP3 RIS" --service_uri "http://path/to/your/ris/dir" +__zypper_service INTERNAL_SLES11_SP3 --service_desc "Internal SLES11 SP3 RIS" --uri "http://path/to/your/ris/dir" # Drop service by uri, no changes to ohter services or repos -__zypper_service INTERNAL_SLES11_SP3 --state absent --service_uri "http://path/to/your/ris/dir" +__zypper_service INTERNAL_SLES11_SP3 --state absent --uri "http://path/to/your/ris/dir" -------------------------------------------------------------------------------- diff --git a/cdist/conf/type/__zypper_service/manifest b/cdist/conf/type/__zypper_service/manifest index aa4a39a3..7f853b3b 100644 --- a/cdist/conf/type/__zypper_service/manifest +++ b/cdist/conf/type/__zypper_service/manifest @@ -25,10 +25,9 @@ #exec >&2 #set -x -zypper_def_opts=" -q " -if [ -f "$__object/parameter/service_uri" ]; then - uri="$(cat "$__object/parameter/service_uri")" +if [ -f "$__object/parameter/uri" ]; then + uri="$(cat "$__object/parameter/uri")" else uri="$__object_id" fi diff --git a/cdist/conf/type/__zypper_service/parameter/required b/cdist/conf/type/__zypper_service/parameter/required index 2b4645ee..c7954952 100644 --- a/cdist/conf/type/__zypper_service/parameter/required +++ b/cdist/conf/type/__zypper_service/parameter/required @@ -1 +1 @@ -service_uri +uri diff --git a/cdist/core/code.py b/cdist/core/code.py index f128697f..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. # @@ -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) diff --git a/cdist/emulator.py b/cdist/emulator.py index 5b706220..5c062a7f 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -189,7 +189,8 @@ class Emulator(object): def record_requirements(self): """record requirements""" - if "CDIST_ORDER_DEPENDENCY" in self.env: + # Inject the predecessor, but not if its an override (this would leed to an circular dependency) + if "CDIST_ORDER_DEPENDENCY" in self.env and not 'CDIST_OVERRIDE' in self.env: # load object name created bevor this one from typeorder file ... with open(self.typeorder_path, 'r') as typecreationfile: typecreationorder = typecreationfile.readlines() diff --git a/cdist/test/cdist_object/__init__.py b/cdist/test/cdist_object/__init__.py index 28f2455b..3c25a959 100644 --- a/cdist/test/cdist_object/__init__.py +++ b/cdist/test/cdist_object/__init__.py @@ -49,7 +49,7 @@ class ObjectClassTestCase(test.CdistTestCase): self.expected_objects = [] for cdist_object_name in self.expected_object_names: - cdist_type, cdist_object_id = cdist_object_name.split("/", maxsplit=1) + cdist_type, cdist_object_id = cdist_object_name.split("/", 1) cdist_object = core.CdistObject(core.CdistType(type_base_path, cdist_type), object_base_path, cdist_object_id) self.expected_objects.append(cdist_object) diff --git a/cdist/test/config/__init__.py b/cdist/test/config/__init__.py index 80a45d9b..70501c89 100644 --- a/cdist/test/config/__init__.py +++ b/cdist/test/config/__init__.py @@ -2,6 +2,7 @@ # # 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) # 2012-2013 Nico Schottelius (nico-cdist at schottelius.org) +# 2014 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. # @@ -137,6 +138,22 @@ class ConfigRunTestCase(test.CdistTestCase): with self.assertRaises(cdist.core.cdist_object.MissingObjectIdError): self.config.iterate_until_finished() + + def test_dryrun(self): + """Test if the dryrun option is working like expected""" + drylocal = cdist.exec.local.Local( + target_host=self.target_host, + base_path=self.local_dir, + #exec_path can not derivated from sys.argv in case of unittest ... + exec_path=os.path.abspath(os.path.join(my_dir,'../../../scripts/cdist')), + initial_manifest=os.path.join(fixtures, 'manifest/dryrun_manifest'), + add_conf_dirs=[ fixtures ] ) + + dryrun = cdist.config.Config(drylocal, self.remote, dry_run=True) + dryrun.run() + # if we are here, dryrun works like expected + + # Currently the resolving code will simply detect that this object does # not exist. It should probably check if the type is a singleton as well # - but maybe only in the emulator - to be discussed. diff --git a/cdist/test/config/fixtures/manifest/dryrun_manifest b/cdist/test/config/fixtures/manifest/dryrun_manifest new file mode 100644 index 00000000..53bb9aa5 --- /dev/null +++ b/cdist/test/config/fixtures/manifest/dryrun_manifest @@ -0,0 +1 @@ +__dryrun_test testit diff --git a/cdist/test/config/fixtures/type/__dryrun_test/.keep b/cdist/test/config/fixtures/type/__dryrun_test/.keep new file mode 100644 index 00000000..e69de29b diff --git a/cdist/test/config/fixtures/type/__dryrun_test/gencode-local b/cdist/test/config/fixtures/type/__dryrun_test/gencode-local new file mode 100644 index 00000000..ccd584bd --- /dev/null +++ b/cdist/test/config/fixtures/type/__dryrun_test/gencode-local @@ -0,0 +1,3 @@ +# this type is only for testing the dryrun feature, it does nothing usefull +echo 'echo "This gencode-local script should never be executed >&2"' +echo 'exit 1' diff --git a/cdist/test/config/fixtures/type/__dryrun_test/gencode-remote b/cdist/test/config/fixtures/type/__dryrun_test/gencode-remote new file mode 100644 index 00000000..e57e4e27 --- /dev/null +++ b/cdist/test/config/fixtures/type/__dryrun_test/gencode-remote @@ -0,0 +1,3 @@ +# this type is only for testing the dryrun feature, it does nothing usefull +echo 'echo "this gencode-remote script should never be executed >&2"' +echo 'exit 1' diff --git a/cdist/test/emulator/__init__.py b/cdist/test/emulator/__init__.py index 95c189d6..870d6245 100644 --- a/cdist/test/emulator/__init__.py +++ b/cdist/test/emulator/__init__.py @@ -103,6 +103,31 @@ class EmulatorTestCase(test.CdistTestCase): emu = emulator.Emulator(argv, env=self.env) # if we get here all is fine + def test_requirement_via_order_dependency(self): + self.env['CDIST_ORDER_DEPENDENCY'] = 'on' + argv = ['__planet', 'erde'] + emu = emulator.Emulator(argv, env=self.env) + emu.run() + argv = ['__planet', 'mars'] + emu = emulator.Emulator(argv, env=self.env) + emu.run() + # In real world, this is not shared over instances + del self.env['require'] + argv = ['__file', '/tmp/cdisttest'] + emu = emulator.Emulator(argv, env=self.env) + emu.run() + # now load the objects and verify the require parameter of the objects + cdist_type = core.CdistType(self.local.type_path, '__planet') + erde_object = core.CdistObject(cdist_type, self.local.object_path, 'erde') + mars_object = core.CdistObject(cdist_type, self.local.object_path, 'mars') + cdist_type = core.CdistType(self.local.type_path, '__file') + file_object = core.CdistObject(cdist_type, self.local.object_path, '/tmp/cdisttest') + # now test the recorded requirements + self.assertTrue(len(erde_object.requirements) == 0) + self.assertEqual(list(mars_object.requirements), ['__planet/erde']) + self.assertEqual(list(file_object.requirements), ['__planet/mars']) + # if we get here all is fine + class AutoRequireEmulatorTestCase(test.CdistTestCase): diff --git a/cdist/test/fixtures/remote/copy b/cdist/test/fixtures/remote/copy index a4627716..05f43eb1 100755 --- a/cdist/test/fixtures/remote/copy +++ b/cdist/test/fixtures/remote/copy @@ -1,7 +1,7 @@ #!/bin/sh # # 2012-2013 Nico Schottelius (nico-cdist schottelius.org) -# 2013 Steven Armstrong (steven-cdist armstrong.cc) +# 2013-2014 Steven Armstrong (steven-cdist armstrong.cc) # # This file is part of cdist. # @@ -20,4 +20,4 @@ # code="$(echo "$@" | sed "s|\([[:space:]]\)$__target_host:|\1|g")" -cp --dereference $code +cp -L $code diff --git a/cdist/util/fsproperty.py b/cdist/util/fsproperty.py index 49d4a32d..98de09f8 100644 --- a/cdist/util/fsproperty.py +++ b/cdist/util/fsproperty.py @@ -143,6 +143,9 @@ class DirectoryDict(collections.MutableMapping): fd.write(str(v) + '\n') else: fd.write(str(value)) + # ensure file ends with a single newline + if value and value[-1] != '\n': + fd.write('\n') except EnvironmentError as e: raise cdist.Error(str(e)) @@ -281,7 +284,7 @@ class FileStringProperty(FileBasedProperty): value = "" try: with open(path, "r") as fd: - value = fd.read() + value = fd.read().rstrip('\n') except EnvironmentError: pass return value @@ -292,6 +295,9 @@ class FileStringProperty(FileBasedProperty): try: with open(path, "w") as fd: fd.write(str(value)) + # ensure file ends with a single newline + if value[-1] != '\n': + fd.write('\n') except EnvironmentError as e: raise cdist.Error(str(e)) else: diff --git a/docs/changelog b/docs/changelog index 6aef1891..094e140e 100644 --- a/docs/changelog +++ b/docs/changelog @@ -5,8 +5,71 @@ Changelog * Exception: No braces means author == Nico Schottelius -3.0.8: +3.1.6: + * Type __package_yum: Support retrieving package via URL + * Type __hostname: Support SuSE and have CentOS use sysconfig value + * Type __locale: Support SuSE + * Type __timezone: Support SuSE + * Type __file: Support MacOS X (Manuel Hutter) + +3.1.5: 2014-05-05 + * Type __zypper_repo: Automatically import gpg keys (Daniel Heule) + * Type __zypper_service: Automatically import gpg keys (Daniel Heule) + +3.1.4: 2014-05-04 + * Core: Ensure all created files end in \n (Steven Armstrong) + * Documentation: Cleanup up, added HTML links (Tomas Pospisek) + * Explorer interfaces: Remove test output (Daniel Heule) + * Type __jail: Add messaging support (Jake Guffey) + +3.1.3: 2014-04-29 + * New Type: __yum_repo (Steven Armstrong) + * Type __hostname: Add support for CentOS + +3.1.2: 2014-04-12 + * Documentation: Add missing environment variables to reference + * Type __qemu_img: size is optional, if state is not present + * Type __key_value: Rewrite using awk (Daniel Heule) + * 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) + * 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) + * Type __package_pkg_openbsd: Improve error handling (og) + +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) + * 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) + +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) + * Type __locale: Error out in case of unsupported OS + * Type __jail: Use default parameters for state (Daniel Heule) + * Type __pf_ruleset: Use default parameters for state (Daniel Heule) + * Type __postgres_database: Use default parameters for state (Daniel Heule) + * Type __postgres_role: Use default parameters for state (Daniel Heule) + * Type __rvm: Use default parameters for state (Daniel Heule) + * Type __rvm_gem: Use default parameters for state (Daniel Heule) + * 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) + * Core: Add unit tests for dry run (Daniel Heule) 3.0.7: 2014-02-08 * Core: Allow dependencies to be created based execution order (Daniel Heule) 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 ... 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 diff --git a/docs/dev/logs/2014-02-13.discussion b/docs/dev/logs/2014-02-13.discussion new file mode 100644 index 00000000..70c0f4fc --- /dev/null +++ b/docs/dev/logs/2014-02-13.discussion @@ -0,0 +1,86 @@ +With Steven + +t marker .cdist breaks + - use random marker that starts with .cdist- + - has fixed number of following characters (like 6 or 10) + - write marker name to $__global/marker + - export $__global/marker path as $__marker + - document variable in cdist-reference + - also document the pattern how the marker is built + so that other people may be able to dig into the structure + from outside + +t save method + - in $__global/method + - values + - config + - install + - document path and description in cdist-reference + +t save whole runtime in cache + - missing items + - initial manifest may be specified on commandline + - always save the initial manifest to $__global/initial-manifest + - currently it is a lost tempfile + - remote exec / remote copy + - save to $__global/remote_exec + - save to $__global/remote_copy + - stdout and stderr of everything + - need to implement Steven's patch of stderr/stdout capturing + - exit code of cdist + - if it is complete, we can use it for replay / reconfigure + +- new idea: replay / reconfig / reinstall + - --from-cache? + +t stderr/stdout + - capture all messages + - prefix with target_host + - implementation exists in one of Steven's branches + - ping steven for updated pull request + +x on error dump all information about the failing object + - where created + - stderr + - stdout + - parameter (+values) + - everything known [tm] + +t multiple versions of cache + - see #298 + +t absolute path of types, explorer + - resolve instead of using the temporary link name + - #305 + +t report command + - from cache? + - #306 + +t add session to "run directories" + - instead of /var/lib/cdist (remote) + - instead of static dir in cache + - same id remote and local + - maybe timestamp + - in or excluding the pid of cdist? + +- cache + - also save when cdist fails + - save exit code + - be able to restore config + +- new command: cdist clean-cache + - --since + - --keep-versions --keep-lala $num + +- cdist 4.0.0pre2 + - cleanup in preos + +- logging for types + cdist log ...? + + - cdist logserver + - $__global/log.socket + - fifo? + echo into logpipe? + 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 + diff --git a/docs/man/cdist-reference.text.sh b/docs/man/cdist-reference.text.sh index 88a002df..7081e762 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) +# 2010-2014 Nico Schottelius (nico-cdist at schottelius.org) +# 2014 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. # @@ -209,10 +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 + 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 + 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. @@ -236,7 +237,13 @@ The following environment variables influence the behaviour of cdist: require:: Setup dependencies between objects (see cdist-manifest(7)) -CDIST_ALLOW_OVERRIDE:: +CDIST_LOCAL_SHELL:: + Use this shell locally instead of /bin/sh to execute scripts + +CDIST_REMOTE_SHELL:: + Use this shell remotely instead of /bin/sh to execute scripts + +CDIST_OVERRIDE:: Allow overwriting type parameters (see cdist-manifest(7)) CDIST_ORDER_DEPENDENCY:: diff --git a/docs/man/man1/cdist.text b/docs/man/man1/cdist.text index e8c12991..c09d8f41 100644 --- a/docs/man/man1/cdist.text +++ b/docs/man/man1/cdist.text @@ -26,7 +26,7 @@ cdist supports different subcommands as explained below. GENERAL ------- -All commands except the following options: +All commands accept the following options: -d, --debug:: Set log level to debug @@ -34,7 +34,7 @@ All commands except the following options: -h, --help:: Show the help screen --v, --verbose: +-v, --verbose:: Set log level to info, be more verbose -V, --version:: @@ -72,10 +72,10 @@ Configure one or more hosts -s, --sequential:: Operate on multiple hosts sequentially ---remote-copy REMOTE_COPY: +--remote-copy REMOTE_COPY:: Command to use for remote copy (should behave like scp) ---remote-exec REMOTE_EXEC: +--remote-exec REMOTE_EXEC:: Command to use for remote execution (should behave like ssh) SHELL diff --git a/docs/man/man7/cdist-bootstrap.text b/docs/man/man7/cdist-bootstrap.text index 985d0f53..5852bad0 100644 --- a/docs/man/man7/cdist-bootstrap.text +++ b/docs/man/man7/cdist-bootstrap.text @@ -25,7 +25,7 @@ location. For starters, having cdist (which includes the configuration database) on your notebook should be fine. Additionally an external copy of the git repository the configuration -relies in is recommended, for use as backup as well to allow easy collaboration +relies on is recommended, for use as backup as well as to allow easy collaboration with others. For more sophisticated setups developing cdist configurations with multiple diff --git a/docs/man/man7/cdist-manifest.text b/docs/man/man7/cdist-manifest.text index 25637242..96346c08 100644 --- a/docs/man/man7/cdist-manifest.text +++ b/docs/man/man7/cdist-manifest.text @@ -13,7 +13,7 @@ DESCRIPTION Manifests are used to define which objects to create. Objects are instances of **types**, like in object oriented programming languages. An object is represented by the combination of -**type + slash + object name**: **__file/etc/cdist-configured** is an +**type + slash + object name**: **\__file/etc/cdist-configured** is an object of the type ***__file*** with the name ***etc/cdist-configured***. All available types can be found in the **cdist/conf/type/** directory, @@ -29,7 +29,7 @@ at an example: __package apache2 --state absent # Same with the __directory type - __directory /tmp/cdist --state present +__directory /tmp/cdist --state present -------------------------------------------------------------------------------- These two lines create objects, which will later be used to realise the @@ -89,7 +89,7 @@ SPLITTING UP THE INITIAL MANIFEST --------------------------------- If you want to split up your initial manifest, you can create other shell scripts in **cdist/conf/manifest/** and include them in **cdist/conf/manifest/init**. -Cdist provides the environment variable ***__manifest*** to reference to +Cdist provides the environment variable ***__manifest*** to reference the directory containing the initial manifest (see cdist-reference(7)). The following example would include every file with a **.sh** suffix: @@ -110,24 +110,39 @@ setup the variable "require" to contain the requirements. Multiple requirements can be added white space separated. -------------------------------------------------------------------------------- -# No dependency -__file /etc/cdist-configured - -# Require above object -require="__file/etc/cdist-configured" __link /tmp/cdist-testfile \ - --source /etc/cdist-configured --type symbolic - -# Require two objects -require="__file/etc/cdist-configured __link/tmp/cdist-testfile" \ - __file /tmp/cdist-another-testfile + 1 # No dependency + 2 __file /etc/cdist-configured + 3 + 4 # Require above object + 5 require="__file/etc/cdist-configured" __link /tmp/cdist-testfile \ + 6 --source /etc/cdist-configured --type symbolic + 7 + 8 # Require two objects + 9 require="__file/etc/cdist-configured __link/tmp/cdist-testfile" \ +10 __file /tmp/cdist-another-testfile -------------------------------------------------------------------------------- +Above the "require" variable is only set for the command that is +immediately following it. Dependencies should allways be declared that way. + +On line 4 you can see that the instantion of a type "__link" object needs +the object "__file/etc/cdist-configured" to be present, before it can proceed. + +This also means that the "__link" command must make sure, that either +"__file/etc/cdist-configured" allready is present, or, if it's not, it needs +to be created. The task of cdist is to make sure, that the dependency will be +resolved appropriately and thus "__file/etc/cdist-configured" be created +if necessary before "__link" proceeds (or to abort execution with an error). + All objects that are created in a type manifest are automatically required from the type that is calling them. This is called "autorequirement" in cdist jargon. +You can find an more in depth description of the flow execution of manifests +in cdist-stages(7) and of how types work in cdist-type(7). + CREATE DEPENDENCIES FROM EXECUTION ORDER ----------------------------------------- You can tell cdist to execute all types in the order in which they are created @@ -138,8 +153,6 @@ automatically depends on the previously created object. It essentially helps you to build up blocks of code that build upon each other (like first creating the directory xyz than the file below the directory). -THIS IS A BETA FEATURE AND MAY BE REMOVED OR CHANGED AT ANY TIME. - OVERRIDES --------- @@ -149,10 +162,12 @@ If you whish, you can setup the environment variable CDIST_OVERRIDE (any value or even empty is ok) to tell cdist, that this object override is wanted and should be accepted. ATTENTION: Only use this feature if you are 100% sure in which order -cdist encounter the affected objects, otherwhise this results -into an undefined situation. +cdist encounters the affected objects, otherwhise this results +in an undefined situation. -THIS IS A BETA FEATURE AND MAY BE REMOVED OR CHANGED AT ANY TIME. +If CDIST_OVERRIDE and CDIST_ORDER_DEPENDENCY are set for an object, +CDIST_ORDER_DEPENDENCY will be ignored, because adding a dependency in case of +overrides would result in circular dependencies, which is an error. @@ -194,7 +209,7 @@ How to override objects: -------------------------------------------------------------------------------- # for example in the inital manifest -# reate user account foobar with some hash for password +# create user account foobar with some hash for password __user foobar --password 'some_fancy_hash' --home /home/foobarexample # ... many statements and includes in the manifest later ... @@ -206,8 +221,8 @@ __user foobar --password 'some_other_hash' # this tells cdist, that you know that this is an override and should be accepted CDIST_OVERRIDE=yes __user foobar --password 'some_other_hash' -# its only an override, means the parameter --home is not touched -# and stay at the original value of /home/foobarexample +# it's only an override, means the parameter --home is not touched +# and stays at the original value of /home/foobarexample -------------------------------------------------------------------------------- Dependencies defined by execution order work as following: diff --git a/docs/man/man7/cdist-type.text b/docs/man/man7/cdist-type.text index 8415f991..323fc130 100644 --- a/docs/man/man7/cdist-type.text +++ b/docs/man/man7/cdist-type.text @@ -25,7 +25,7 @@ to use. HOW TO USE A TYPE ----------------- You can use types from the initial manifest or the type manifest like a -normal command: +normal shell command: -------------------------------------------------------------------------------- # Creates empty file /etc/cdist-configured @@ -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 diff --git a/docs/speeches/2014-05-08_linuxtag_berlin.odp b/docs/speeches/2014-05-08_linuxtag_berlin.odp new file mode 100644 index 00000000..0cf6374c Binary files /dev/null and b/docs/speeches/2014-05-08_linuxtag_berlin.odp differ diff --git a/docs/speeches/2014-05-08_linuxtag_berlin.pdf b/docs/speeches/2014-05-08_linuxtag_berlin.pdf new file mode 100644 index 00000000..88fbeb6e Binary files /dev/null and b/docs/speeches/2014-05-08_linuxtag_berlin.pdf differ diff --git a/docs/speeches/2014-05-19_cdi.st-zkb_linux_erfa.odp b/docs/speeches/2014-05-19_cdi.st-zkb_linux_erfa.odp new file mode 100644 index 00000000..f722a9cc Binary files /dev/null and b/docs/speeches/2014-05-19_cdi.st-zkb_linux_erfa.odp differ diff --git a/docs/speeches/2014-05-19_cdi.st-zkb_linux_erfa.pdf b/docs/speeches/2014-05-19_cdi.st-zkb_linux_erfa.pdf new file mode 100644 index 00000000..9c169a84 Binary files /dev/null and b/docs/speeches/2014-05-19_cdi.st-zkb_linux_erfa.pdf differ 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.