diff --git a/.gitignore b/.gitignore index baf9b6f2..2a193c2a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,8 +8,8 @@ docs/man/man7/*.7 docs/man/man*/*.html docs/man/man*/*.xml docs/man/man*/docbook-xsl.css -docs/man/man7/cdist-type__*.text -docs/man/man7/cdist-reference.text +docs/man/man7/cdist-type__*.rst +docs/man/man7/cdist-reference.rst # Ignore cdist cache for version control /cache/ @@ -20,6 +20,9 @@ MANIFEST dist/ cdist/version.py +#sphinx build dir +_build/ + # Packaging: Archlinux /PKGBUILD /cdist-*.pkg.tar.xz diff --git a/.version b/.version deleted file mode 100644 index 71f08595..00000000 --- a/.version +++ /dev/null @@ -1 +0,0 @@ -2.1.0-pre1 diff --git a/Makefile b/Makefile index 9502c989..e584fc63 100644 --- a/Makefile +++ b/Makefile @@ -18,8 +18,6 @@ # # -A2XM=a2x -f manpage --no-xmllint -a encoding=UTF-8 -A2XH=a2x -f xhtml --no-xmllint -a encoding=UTF-8 helper=./bin/build-helper MANDIR=docs/man @@ -28,7 +26,7 @@ TYPEDIR=cdist/conf/type WEBSRCDIR=docs/web -WEBDIR=$$HOME/www.nico.schottelius.org +WEBDIR=$$HOME/vcs/www.nico.schottelius.org WEBBLOG=$(WEBDIR)/blog WEBBASE=$(WEBDIR)/software/cdist WEBPAGE=$(WEBBASE).mdwn @@ -38,6 +36,8 @@ CHANGELOG_FILE=docs/changelog PYTHON_VERSION=cdist/version.py +SPHINXM=make -C $(MANDIR) man +SPHINXH=make -C $(MANDIR) html ################################################################################ # Manpages # @@ -45,64 +45,48 @@ MAN1DSTDIR=$(MANDIR)/man1 MAN7DSTDIR=$(MANDIR)/man7 # Manpages #1: Types -# Use shell / ls to get complete list - $(TYPEDIR)/*/man.text does not work -MANTYPESRC=$(shell ls $(TYPEDIR)/*/man.text) - -# replace first path component +# Use shell / ls to get complete list - $(TYPEDIR)/*/man.rst does not work +MANTYPESRC=$(shell ls $(TYPEDIR)/*/man.rst) MANTYPEPREFIX=$(subst $(TYPEDIR)/,$(MAN7DSTDIR)/cdist-type,$(MANTYPESRC)) +MANTYPES=$(subst /man.rst,.rst,$(MANTYPEPREFIX)) -# replace man.text with .7 or .html -MANTYPEMAN=$(subst /man.text,.7,$(MANTYPEPREFIX)) -MANTYPEHTML=$(subst /man.text,.html,$(MANTYPEPREFIX)) -MANTYPEALL=$(MANTYPEMAN) $(MANTYPEHTML) - -# Link manpage so A2XH does not create man.html but correct named file -$(MAN7DSTDIR)/cdist-type%.text: $(TYPEDIR)/%/man.text +# Link manpage: do not create man.html but correct named file +$(MAN7DSTDIR)/cdist-type%.rst: $(TYPEDIR)/%/man.rst ln -sf "../../../$^" $@ # Manpages #2: reference -MANREF=$(MAN7DSTDIR)/cdist-reference.text -MANREFSH=$(MANDIR)/cdist-reference.text.sh -MANREFMAN=$(MANREF:.text=.7) -MANREFHTML=$(MANREF:.text=.html) -MANREFALL=$(MANREFMAN) $(MANREFHTML) +MANREF=$(MAN7DSTDIR)/cdist-reference.rst +MANREFSH=$(MANDIR)/cdist-reference.rst.sh $(MANREF): $(MANREFSH) $(MANREFSH) -# Manpages #3: static pages -MAN1STATIC=$(shell ls $(MAN1DSTDIR)/*.text) -MAN7STATIC=$(shell ls $(MAN7DSTDIR)/*.text) -MANSTATICMAN=$(MAN1STATIC:.text=.1) $(MAN7STATIC:.text=.7) -MANSTATICHTML=$(MAN1STATIC:.text=.html) $(MAN7STATIC:.text=.html) -MANSTATICALL=$(MANSTATICMAN) $(MANSTATICHTML) +# Manpages #3: generic part +mansphinxman: $(MANTYPES) $(MANREF) + $(SPHINXM) -# Manpages #4: generic part +mansphinxhtml: $(MANTYPES) $(MANREF) + $(SPHINXH) -# Creating the type manpage -%.1 %.7: %.text - $(A2XM) $^ - -# Creating the type html page -%.html: %.text - $(A2XH) $^ - -man: $(MANTYPEALL) $(MANREFALL) $(MANSTATICALL) +man: mansphinxman mansphinxhtml # Manpages #5: release part MANWEBDIR=$(WEBBASE)/man/$(CHANGELOG_VERSION) +MANBUILDDIR=$(MANDIR)/_build/html -man-dist: man check-date +man-dist: man rm -rf "${MANWEBDIR}" - mkdir -p "${MANWEBDIR}/man1" "${MANWEBDIR}/man7" - cp ${MAN1DSTDIR}/*.html ${MAN1DSTDIR}/*.css ${MANWEBDIR}/man1 - cp ${MAN7DSTDIR}/*.html ${MAN7DSTDIR}/*.css ${MANWEBDIR}/man7 + mkdir -p "${MANWEBDIR}" + # mkdir -p "${MANWEBDIR}/man1" "${MANWEBDIR}/man7" + # cp ${MAN1DSTDIR}/*.html ${MAN1DSTDIR}/*.css ${MANWEBDIR}/man1 + # cp ${MAN7DSTDIR}/*.html ${MAN7DSTDIR}/*.css ${MANWEBDIR}/man7 + cp -R ${MANBUILDDIR}/* ${MANWEBDIR} cd ${MANWEBDIR} && git add . && git commit -m "cdist manpages update: $(CHANGELOG_VERSION)" || true 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" + ssh staticweb.ungleich.ch \ + "cd /home/services/www/nico/nico.schottelius.org/www/software/cdist/man/ && rm -f latest && ln -sf "$(CHANGELOG_VERSION)" latest" ################################################################################ # Speeches @@ -162,17 +146,6 @@ $(ML_FILE): $(CHANGELOG_FILE) ml-release: $(ML_FILE) -################################################################################ -# Release: Freecode -# -FREECODE_FILE=.lock-freecode - -$(FREECODE_FILE): $(CHANGELOG_FILE) - $(helper) freecode-release $(CHANGELOG_VERSION) - touch $@ - -freecode-release: $(FREECODE_FILE) - ################################################################################ # pypi # @@ -189,7 +162,7 @@ ARCHLINUX_FILE=.lock-archlinux ARCHLINUXTAR=cdist-$(CHANGELOG_VERSION)-1.src.tar.gz $(ARCHLINUXTAR): PKGBUILD - makepkg -c --source + umask 022; mkaurball PKGBUILD: PKGBUILD.in $(PYTHON_VERSION) ./PKGBUILD.in $(CHANGELOG_VERSION) @@ -219,15 +192,13 @@ release: # clean: - rm -f $(MAN7DSTDIR)/cdist-reference.text + rm -f $(MAN7DSTDIR)/cdist-reference.rst find "$(MANDIR)" -mindepth 2 -type l \ - -o -name "*.1" \ - -o -name "*.7" \ - -o -name "*.html" \ - -o -name "*.xml" \ | xargs rm -f + make -C $(MANDIR) clean + find * -name __pycache__ | xargs rm -rf # Archlinux @@ -246,10 +217,7 @@ distclean: clean # The pub is Nico's "push to all git remotes" way ("make pub") pub: - for remote in "" github sf; do \ - echo "Pushing to $$remote"; \ - git push --mirror $$remote; \ - done + git push --mirror test: $(helper) $@ diff --git a/PKGBUILD.in b/PKGBUILD.in index e3ae4619..c967249d 100755 --- a/PKGBUILD.in +++ b/PKGBUILD.in @@ -17,7 +17,13 @@ source=("http://pypi.python.org/packages/source/c/cdist/cdist-\${pkgver}.tar.gz" package() { cd cdist-\${pkgver} python3 setup.py build install --root="\${pkgdir}" + find "\$pkgdir" -type d -exec chmod 0755 {} \; + find "\$pkgdir" -type f -exec chmod a+r {} \; } eof makepkg -g >> "${outfile}" + +# Fix this issue: +# error: failed to upload cdist-3.1.6-1.src.tar.gz: Error - all files must have permissions of 644 or 755. +chmod a+r "${outfile}" diff --git a/bin/build-helper b/bin/build-helper index 93401d3b..31789a2e 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 @@ -140,39 +145,6 @@ 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 - - ;; - release-git-tag) target_version=$($0 changelog-version) if git rev-parse --verify refs/tags/$target_version 2>/dev/null; then @@ -271,9 +243,6 @@ eof # Archlinux release is based on pypi make archlinux-release - # Announce change on Freecode - make freecode-release - # Announce change on ML make ml-release diff --git a/cdist/__init__.py b/cdist/__init__.py index 20c76b31..4454a3ac 100644 --- a/cdist/__init__.py +++ b/cdist/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# 2010-2012 Nico Schottelius (nico-cdist at schottelius.org) +# 2010-2015 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -41,8 +41,6 @@ BANNER = """ "P' "" "" """ -DOT_CDIST = ".cdist" - REMOTE_COPY = "scp -o User=root -q" REMOTE_EXEC = "ssh -o User=root -q" diff --git a/cdist/conf/explorer/cpu_cores b/cdist/conf/explorer/cpu_cores index efabc848..7f7a955e 100755 --- a/cdist/conf/explorer/cpu_cores +++ b/cdist/conf/explorer/cpu_cores @@ -22,10 +22,19 @@ # 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 +os=$("$__explorer/os") +case "$os" in + "macosx") + echo "$(sysctl -n hw.physicalcpu)" + ;; + + *) + if [ -r /proc/cpuinfo ]; then + cores="$(grep "core id" /proc/cpuinfo | sort | uniq | wc -l)" + if [ ${cores} -eq 0 ]; then + cores="1" + fi + echo "$cores" + fi + ;; +esac diff --git a/cdist/conf/explorer/cpu_sockets b/cdist/conf/explorer/cpu_sockets index 98836cec..8a8194df 100755 --- a/cdist/conf/explorer/cpu_sockets +++ b/cdist/conf/explorer/cpu_sockets @@ -22,10 +22,19 @@ # 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)" +os=$("$__explorer/os") +case "$os" in + "macosx") + echo "$(system_profiler SPHardwareDataType | grep "Number of Processors" | awk -F': ' '{print $2}')" + ;; + + *) + if [ -r /proc/cpuinfo ]; then + sockets="$(grep "physical id" /proc/cpuinfo | sort | uniq | wc -l)" + if [ ${sockets} -eq 0 ]; then + sockets="$(cat /proc/cpuinfo | grep "processor" | wc -l)" + fi + echo "${sockets}" fi - echo "${sockets}" -fi + ;; +esac diff --git a/cdist/conf/explorer/init b/cdist/conf/explorer/init new file mode 100755 index 00000000..2693a0d3 --- /dev/null +++ b/cdist/conf/explorer/init @@ -0,0 +1,35 @@ +#!/bin/sh +# +# 2016 Daniel Heule (hda 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 . +# +# +# Returns the process name of pid 1 ( normaly the init system ) +# for example at linux this value is "init" or "systemd" in most cases +# + +uname_s="$(uname -s)" + +case "$uname_s" in + Linux|FreeBSD) + ps -o comm= -p 1 || true + ;; + *) + # return a empty string as unknown value + echo "" + ;; +esac 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/memory b/cdist/conf/explorer/memory index 982b5dfa..05db865f 100755 --- a/cdist/conf/explorer/memory +++ b/cdist/conf/explorer/memory @@ -22,6 +22,15 @@ # FIXME: other system types (not linux ...) -if [ -r /proc/meminfo ]; then - echo "$(cat /proc/meminfo | grep "MemTotal:" | awk '{print $2}')" -fi +os=$("$__explorer/os") +case "$os" in + "macosx") + echo "$(sysctl -n hw.memsize)/1024" | bc + ;; + + *) + if [ -r /proc/meminfo ]; then + grep "MemTotal:" /proc/meminfo | awk '{print $2}' + fi + ;; +esac diff --git a/cdist/conf/explorer/os b/cdist/conf/explorer/os index 053177eb..de1d29c3 100755 --- a/cdist/conf/explorer/os +++ b/cdist/conf/explorer/os @@ -49,6 +49,11 @@ if [ -f /etc/debian_version ]; then echo debian exit 0 fi + +if [ -f /etc/devuan_version ]; then + echo devuan + exit 0 +fi ### if [ -f /etc/gentoo-release ]; then @@ -77,6 +82,11 @@ if grep -q ^Fedora /etc/redhat-release 2>/dev/null; then exit 0 fi +if grep -q ^Mitel /etc/redhat-release 2>/dev/null; then + echo mitel + exit 0 +fi + if [ -f /etc/redhat-release ]; then echo redhat exit 0 diff --git a/cdist/conf/explorer/os_version b/cdist/conf/explorer/os_version index 50889429..6c7becdc 100755 --- a/cdist/conf/explorer/os_version +++ b/cdist/conf/explorer/os_version @@ -33,6 +33,9 @@ case "$($__explorer/os)" in debian) cat /etc/debian_version ;; + devuan) + cat /etc/devuan_version + ;; fedora) cat /etc/fedora-release ;; @@ -51,7 +54,7 @@ case "$($__explorer/os)" in owl) cat /etc/owl-release ;; - redhat|centos) + redhat|centos|mitel) cat /etc/redhat-release ;; slackware) diff --git a/cdist/conf/type/__apt_key/man.text b/cdist/conf/type/__apt_key/man.rst similarity index 52% rename from cdist/conf/type/__apt_key/man.text rename to cdist/conf/type/__apt_key/man.rst index 1a33e732..43dc89b1 100644 --- a/cdist/conf/type/__apt_key/man.text +++ b/cdist/conf/type/__apt_key/man.rst @@ -1,13 +1,10 @@ cdist-type__apt_key(7) ====================== +Manage the list of keys used by apt + Steven Armstrong -NAME ----- -cdist-type__apt_key - manage the list of keys used by apt - - DESCRIPTION ----------- Manages the list of keys used by apt to authenticate packages. @@ -20,13 +17,13 @@ None. OPTIONAL PARAMETERS ------------------- -state:: +state 'present' or 'absent'. Defaults to 'present' -keyid:: +keyid the id of the key to add. Defaults to __object_id -keyserver:: +keyserver the keyserver from which to fetch the key. If omitted the default set in ./parameter/default/keyserver is used. @@ -34,25 +31,25 @@ keyserver:: EXAMPLES -------- --------------------------------------------------------------------------------- -# Add Ubuntu Archive Automatic Signing Key -__apt_key 437D05B5 -# Same thing -__apt_key 437D05B5 --state present -# Get rid of it -__apt_key 437D05B5 --state absent +.. code-block:: sh -# same thing with human readable name and explicit keyid -__apt_key UbuntuArchiveKey --keyid 437D05B5 + # Add Ubuntu Archive Automatic Signing Key + __apt_key 437D05B5 + # Same thing + __apt_key 437D05B5 --state present + # Get rid of it + __apt_key 437D05B5 --state absent -# same thing with other keyserver -__apt_key UbuntuArchiveKey --keyid 437D05B5 --keyserver keyserver.ubuntu.com --------------------------------------------------------------------------------- + # same thing with human readable name and explicit keyid + __apt_key UbuntuArchiveKey --keyid 437D05B5 + + # same thing with other keyserver + __apt_key UbuntuArchiveKey --keyid 437D05B5 --keyserver keyserver.ubuntu.com SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__apt_key/parameter/default/keyserver b/cdist/conf/type/__apt_key/parameter/default/keyserver index f851282c..0d189916 100644 --- a/cdist/conf/type/__apt_key/parameter/default/keyserver +++ b/cdist/conf/type/__apt_key/parameter/default/keyserver @@ -1 +1 @@ -subkeys.pgp.net +pool.sks-keyservers.net diff --git a/cdist/conf/type/__apt_key_uri/man.text b/cdist/conf/type/__apt_key_uri/man.rst similarity index 61% rename from cdist/conf/type/__apt_key_uri/man.text rename to cdist/conf/type/__apt_key_uri/man.rst index fe9c3a25..a235e13a 100644 --- a/cdist/conf/type/__apt_key_uri/man.text +++ b/cdist/conf/type/__apt_key_uri/man.rst @@ -1,13 +1,10 @@ cdist-type__apt_key_uri(7) ========================== +Add apt key from uri + Steven Armstrong -NAME ----- -cdist-type__apt_key_uri - add apt key from uri - - DESCRIPTION ----------- Download a key from an uri and add it to the apt keyring. @@ -15,16 +12,16 @@ Download a key from an uri and add it to the apt keyring. REQUIRED PARAMETERS ------------------- -uri:: +uri the uri from which to download the key OPTIONAL PARAMETERS ------------------- -state:: +state 'present' or 'absent', defaults to 'present' -name:: +name a name for this key, used when testing if it is already installed. Defaults to __object_id @@ -32,17 +29,17 @@ name:: EXAMPLES -------- --------------------------------------------------------------------------------- -__apt_key_uri rabbitmq \ - --name 'RabbitMQ Release Signing Key ' \ - --uri http://www.rabbitmq.com/rabbitmq-signing-key-public.asc \ - --state present --------------------------------------------------------------------------------- +.. code-block:: sh + + __apt_key_uri rabbitmq \ + --name 'RabbitMQ Release Signing Key ' \ + --uri http://www.rabbitmq.com/rabbitmq-signing-key-public.asc \ + --state present SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__apt_norecommends/man.text b/cdist/conf/type/__apt_norecommends/man.rst similarity index 63% rename from cdist/conf/type/__apt_norecommends/man.text rename to cdist/conf/type/__apt_norecommends/man.rst index 3b65e72f..232bb166 100644 --- a/cdist/conf/type/__apt_norecommends/man.text +++ b/cdist/conf/type/__apt_norecommends/man.rst @@ -1,13 +1,10 @@ cdist-type__apt_norecommends(7) =============================== +Configure apt to not install recommended packages + Steven Armstrong -NAME ----- -cdist-type__apt_norecommends - configure apt to not install recommended packages - - DESCRIPTION ----------- Configure apt to not install any recommended or suggested packages. @@ -26,14 +23,14 @@ None. EXAMPLES -------- --------------------------------------------------------------------------------- -__apt_norecommends --------------------------------------------------------------------------------- +.. code-block:: sh + + __apt_norecommends SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__apt_norecommends/manifest b/cdist/conf/type/__apt_norecommends/manifest index 881c2427..9e633308 100755 --- a/cdist/conf/type/__apt_norecommends/manifest +++ b/cdist/conf/type/__apt_norecommends/manifest @@ -22,7 +22,7 @@ os=$(cat "$__global/explorer/os") case "$os" in - ubuntu|debian) + ubuntu|debian|devuan) # No stinking recommends thank you very much. # If I want something installed I will do so myself. __file /etc/apt/apt.conf.d/99-no-recommends \ @@ -30,6 +30,8 @@ case "$os" in --source - << DONE APT::Install-Recommends "0"; APT::Install-Suggests "0"; +APT::AutoRemove::RecommendsImportant "0"; +APT::AutoRemove::SuggestsImportant "0"; DONE ;; *) diff --git a/cdist/conf/type/__apt_ppa/man.text b/cdist/conf/type/__apt_ppa/man.rst similarity index 55% rename from cdist/conf/type/__apt_ppa/man.text rename to cdist/conf/type/__apt_ppa/man.rst index da18e9f0..e39bd6b2 100644 --- a/cdist/conf/type/__apt_ppa/man.text +++ b/cdist/conf/type/__apt_ppa/man.rst @@ -1,13 +1,10 @@ cdist-type__apt_ppa(7) ====================== +Manage ppa repositories + Steven Armstrong -NAME ----- -cdist-type__apt_ppa - Manage ppa repositories - - DESCRIPTION ----------- This cdist type allows manage ubuntu ppa repositories. @@ -15,7 +12,7 @@ This cdist type allows manage ubuntu ppa repositories. REQUIRED PARAMETERS ------------------- -state:: +state The state the ppa should be in, either 'present' or 'absent'. Defaults to 'present' @@ -28,20 +25,20 @@ None. EXAMPLES -------- --------------------------------------------------------------------------------- -# Enable a ppa repository -__apt_ppa ppa:sans-intern/missing-bits -# same as -__apt_ppa ppa:sans-intern/missing-bits --state present +.. code-block:: sh -# Disable a ppa repository -__apt_ppa ppa:sans-intern/missing-bits --state absent --------------------------------------------------------------------------------- + # Enable a ppa repository + __apt_ppa ppa:sans-intern/missing-bits + # same as + __apt_ppa ppa:sans-intern/missing-bits --state present + + # Disable a ppa repository + __apt_ppa ppa:sans-intern/missing-bits --state absent SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__apt_ppa/manifest b/cdist/conf/type/__apt_ppa/manifest index 1d90e9c4..a67c7613 100755 --- a/cdist/conf/type/__apt_ppa/manifest +++ b/cdist/conf/type/__apt_ppa/manifest @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011-2014 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011-2016 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -21,9 +21,8 @@ name="$__object_id" __package software-properties-common -__package python-software-properties -require="__package/software-properties-common __package/python-software-properties" \ +require="__package/software-properties-common" \ __file /usr/local/bin/remove-apt-repository \ --source "$__type/files/remove-apt-repository" \ --mode 0755 diff --git a/cdist/conf/type/__apt_source/man.text b/cdist/conf/type/__apt_source/man.rst similarity index 60% rename from cdist/conf/type/__apt_source/man.text rename to cdist/conf/type/__apt_source/man.rst index 03b2b311..70649c4b 100644 --- a/cdist/conf/type/__apt_source/man.text +++ b/cdist/conf/type/__apt_source/man.rst @@ -1,13 +1,10 @@ cdist-type__apt_source(7) ========================= +Manage apt sources + Steven Armstrong -NAME ----- -cdist-type__apt_source - manage apt sources - - DESCRIPTION ----------- This cdist type allows you to manage apt sources. @@ -15,52 +12,52 @@ This cdist type allows you to manage apt sources. REQUIRED PARAMETERS ------------------- -uri:: +uri the uri to the apt repository OPTIONAL PARAMETERS ------------------- -arch:: +arch set this if you need to force and specific arch (ubuntu specific) -state:: +state 'present' or 'absent', defaults to 'present' -distribution:: +distribution the distribution codename to use. Defaults to DISTRIB_CODENAME from the targets /etc/lsb-release -component:: +component space delimited list of components to enable. Defaults to an empty string. BOOLEAN PARAMETERS ------------------ -include-src:: +include-src include deb-src entries EXAMPLES -------- --------------------------------------------------------------------------------- -__apt_source rabbitmq \ - --uri http://www.rabbitmq.com/debian/ \ - --distribution testing \ - --component main \ - --include-src \ - --state present +.. code-block:: sh -__apt_source canonical_partner \ - --uri http://archive.canonical.com/ \ - --component partner --state present --------------------------------------------------------------------------------- + __apt_source rabbitmq \ + --uri http://www.rabbitmq.com/debian/ \ + --distribution testing \ + --component main \ + --include-src \ + --state present + + __apt_source canonical_partner \ + --uri http://archive.canonical.com/ \ + --component partner --state present SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__apt_source/manifest b/cdist/conf/type/__apt_source/manifest index 0e782716..59c7c567 100755 --- a/cdist/conf/type/__apt_source/manifest +++ b/cdist/conf/type/__apt_source/manifest @@ -27,11 +27,9 @@ if [ -f "$__object/parameter/distribution" ]; then else distribution="$(cat "$__global/explorer/lsb_codename")" fi -if [ -f "$__object/parameter/component" ]; then - component="$(cat "$__object/parameter/component")" -else - component="" -fi + +component="$(cat "$__object/parameter/component")" + if [ -f "$__object/parameter/arch" ]; then forcedarch="[arch=$(cat "$__object/parameter/arch")]" else diff --git a/cdist/test/cdist_object/fixtures/object/__first/.keep b/cdist/conf/type/__apt_source/parameter/default/component similarity index 100% rename from cdist/test/cdist_object/fixtures/object/__first/.keep rename to cdist/conf/type/__apt_source/parameter/default/component diff --git a/cdist/conf/type/__apt_update_index/man.text b/cdist/conf/type/__apt_update_index/man.rst similarity index 65% rename from cdist/conf/type/__apt_update_index/man.text rename to cdist/conf/type/__apt_update_index/man.rst index 778af508..2fc66c65 100644 --- a/cdist/conf/type/__apt_update_index/man.text +++ b/cdist/conf/type/__apt_update_index/man.rst @@ -1,13 +1,10 @@ cdist-type__apt_update_index(7) =============================== +Update apt's package index + Steven Armstrong -NAME ----- -cdist-type__apt_update_index - update apt's package index - - DESCRIPTION ----------- This cdist type runs apt-get update whenever any apt sources have changed. @@ -25,14 +22,14 @@ None. EXAMPLES -------- --------------------------------------------------------------------------------- -__apt_update_index --------------------------------------------------------------------------------- +.. code-block:: sh + + __apt_update_index SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__block/explorer/block b/cdist/conf/type/__block/explorer/block index 6c35bc46..e1ca3441 100755 --- a/cdist/conf/type/__block/explorer/block +++ b/cdist/conf/type/__block/explorer/block @@ -1,5 +1,24 @@ #!/bin/sh -# 2013 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 2013 Steven Armstrong (steven-cdist armstrong.cc) +# 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 . +# + file="$(cat "$__object/parameter/file" 2>/dev/null || echo "/$__object_id")" @@ -8,12 +27,12 @@ file="$(cat "$__object/parameter/file" 2>/dev/null || echo "/$__object_id")" prefix=$(cat "$__object/parameter/prefix" 2>/dev/null || echo "#cdist:__block/$__object_id") suffix=$(cat "$__object/parameter/suffix" 2>/dev/null || echo "#/cdist:__block/$__object_id") -awk -v prefix="$prefix" -v suffix="$suffix" '{ - if (index($0,prefix)) { +awk -v prefix="^$prefix\$" -v suffix="^$suffix\$" '{ + if (match($0,prefix)) { triggered=1 } if (triggered) { - if (index($0,suffix)) { + if (match($0,suffix)) { triggered=0 } print diff --git a/cdist/conf/type/__block/gencode-remote b/cdist/conf/type/__block/gencode-remote index 0a5eea18..2e2147e5 100755 --- a/cdist/conf/type/__block/gencode-remote +++ b/cdist/conf/type/__block/gencode-remote @@ -46,13 +46,13 @@ tmpfile=\$(mktemp ${file}.cdist.XXXXXXXXXX) if [ -f "$file" ]; then cp -p "$file" "\$tmpfile" fi -awk -v prefix="$prefix" -v suffix="$suffix" ' +awk -v prefix="^$prefix\$" -v suffix="^$suffix\$" ' { - if (index(\$0,prefix)) { + if (match(\$0,prefix)) { triggered=1 } if (triggered) { - if (index(\$0,suffix)) { + if (match(\$0,suffix)) { triggered=0 } } else { diff --git a/cdist/conf/type/__block/man.text b/cdist/conf/type/__block/man.rst similarity index 64% rename from cdist/conf/type/__block/man.text rename to cdist/conf/type/__block/man.rst index 2312d293..4b7d61dc 100644 --- a/cdist/conf/type/__block/man.text +++ b/cdist/conf/type/__block/man.rst @@ -1,13 +1,10 @@ cdist-type__block(7) ==================== +Manage blocks of text in files + Steven Armstrong -NAME ----- -cdist-type__block - Manage blocks of text in files - - DESCRIPTION ----------- Manage a block of text in an existing file. @@ -18,62 +15,62 @@ of text. REQUIRED PARAMETERS ------------------- -text:: +text the text to manage. If text is '-' (dash), take what was written to stdin as the text. OPTIONAL PARAMETERS ------------------- -file:: +file the file in which to manage the text block. Defaults to object_id. -prefix:: +prefix the prefix to add before the text. Defaults to #cdist:__block/$__object_id -suffix:: - the prefix to add after the text. +suffix + the suffix to add after the text. Defaults to #/cdist:__block/$__object_id -state:: +state 'present' or 'absent', defaults to 'present' MESSAGES -------- -add:: +add block was added -update:: +update block was updated/changed -remove:: +remove block was removed EXAMPLES -------- --------------------------------------------------------------------------------- -# text from argument -__block /path/to/file \ - --prefix '#start' \ - --suffix '#end' \ - --text 'some\nblock of\ntext' +.. code-block:: sh -# text from stdin -__block some-id \ - --file /path/to/file \ - --text - << DONE -here some block -of text -DONE --------------------------------------------------------------------------------- + # text from argument + __block /path/to/file \ + --prefix '#start' \ + --suffix '#end' \ + --text 'some\nblock of\ntext' + + # text from stdin + __block some-id \ + --file /path/to/file \ + --text - << DONE + here some block + of text + DONE SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__block/manifest b/cdist/conf/type/__block/manifest index 1fc9ec79..bf96181c 100755 --- a/cdist/conf/type/__block/manifest +++ b/cdist/conf/type/__block/manifest @@ -31,6 +31,6 @@ echo "$prefix" > "$block" if [ "$text" = "-" ]; then cat "$__object/stdin" >> "$block" else - cat "$text" >> "$block" + echo "$text" >> "$block" fi echo "$suffix" >> "$block" diff --git a/cdist/conf/type/__ccollect_source/explorer/stat b/cdist/conf/type/__ccollect_source/explorer/stat index 298221b7..9b5ad75b 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"|"netbsd"|"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/__ccollect_source/man.text b/cdist/conf/type/__ccollect_source/man.rst similarity index 65% rename from cdist/conf/type/__ccollect_source/man.text rename to cdist/conf/type/__ccollect_source/man.rst index 32a7467e..12fb8f42 100644 --- a/cdist/conf/type/__ccollect_source/man.text +++ b/cdist/conf/type/__ccollect_source/man.rst @@ -1,59 +1,58 @@ cdist-type__ccollect_source(7) ============================== +Manage ccollect sources + Nico Schottelius -NAME ----- -cdist-type__ccollect_source - Manage ccollect sources - - DESCRIPTION ----------- This cdist type allows you to create or delete ccollect sources. + REQUIRED PARAMETERS ------------------- -source:: +source The source from which to backup -destination:: +destination The destination directory OPTIONAL PARAMETERS ------------------- -state:: +state 'present' or 'absent', defaults to 'present' -ccollectconf:: +ccollectconf The CCOLLECT_CONF directory. Defaults to /etc/ccollect. OPTIONAL MULTIPLE PARAMETERS ---------------------------- -exclude:: +exclude Paths to exclude of backup + BOOLEAN PARAMETERS ------------------ -verbose:: +verbose Whether to report backup verbosely + EXAMPLES -------- --------------------------------------------------------------------------------- -__ccollect_source doc.ungleich.ch \ - --source doc.ungleich.ch:/ \ - --destination /backup/doc.ungleich.ch \ - --exclude '/proc/*' --exclude '/sys/*' \ - --verbose +.. code-block:: sh --------------------------------------------------------------------------------- + __ccollect_source doc.ungleich.ch \ + --source doc.ungleich.ch:/ \ + --destination /backup/doc.ungleich.ch \ + --exclude '/proc/*' --exclude '/sys/*' \ + --verbose SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ - ccollect(1) - http://www.nico.schottelius.org/software/ccollect/ diff --git a/cdist/conf/type/__cdist/man.text b/cdist/conf/type/__cdist/man.rst similarity index 67% rename from cdist/conf/type/__cdist/man.text rename to cdist/conf/type/__cdist/man.rst index 0805598e..f15d3b73 100644 --- a/cdist/conf/type/__cdist/man.text +++ b/cdist/conf/type/__cdist/man.rst @@ -1,13 +1,10 @@ cdist-type__cdist(7) ==================== +Manage cdist installations + Nico Schottelius -NAME ----- -cdist-type__cdist - Manage cdist installations - - DESCRIPTION ----------- This cdist type allows you to easily setup cdist @@ -26,16 +23,16 @@ REQUIRED PARAMETERS OPTIONAL PARAMETERS ------------------- -username:: +username Select the user to create for the cdist installation. Defaults to "cdist". -source:: +source Select the source from which to clone cdist from. Defaults to "git://github.com/telmich/cdist.git". -branch:: +branch Select the branch to checkout from. Defaults to "master". @@ -43,18 +40,18 @@ branch:: EXAMPLES -------- --------------------------------------------------------------------------------- -# Install cdist for user cdist in her home as subfolder cdist -__cdist /home/cdist/cdist +.. code-block:: sh -# Use alternative source -__cdist --source "git://git.schottelius.org/cdist" /home/cdist/cdist --------------------------------------------------------------------------------- + # Install cdist for user cdist in her home as subfolder cdist + __cdist /home/cdist/cdist + + # Use alternative source + __cdist --source "git://git.schottelius.org/cdist" /home/cdist/cdist SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__cdistmarker/gencode-remote b/cdist/conf/type/__cdistmarker/gencode-remote index e332df38..92ea582b 100755 --- a/cdist/conf/type/__cdistmarker/gencode-remote +++ b/cdist/conf/type/__cdistmarker/gencode-remote @@ -19,19 +19,11 @@ # # The marker file is established in the docs, but it isn't obligatory. -if [ -f "$__object/parameter/destination" ]; then - destination="$(cat "$__object/parameter/destination")" -else - destination='/etc/cdist-configured' -fi +destination="$(cat "$__object/parameter/destination")" # The basic output of date is usually good enough, but variety is the # spice of life... -if [ -f "$__object/parameter/format" ]; then - format="$(cat "$__object/parameter/format")" -else - format='-u' -fi +format="$(cat "$__object/parameter/format")" # Dump the timestamp in UTC to the marker echo "date $format > $destination" diff --git a/cdist/conf/type/__cdistmarker/man.text b/cdist/conf/type/__cdistmarker/man.rst similarity index 67% rename from cdist/conf/type/__cdistmarker/man.text rename to cdist/conf/type/__cdistmarker/man.rst index ca5611a7..22e711b6 100644 --- a/cdist/conf/type/__cdistmarker/man.text +++ b/cdist/conf/type/__cdistmarker/man.rst @@ -1,13 +1,10 @@ cdist-type__cdistmarker(7) ========================== +Add a timestamped cdist marker. + Daniel Maher -NAME ----- -cdist-type__cdistmarker - Add a timestamped cdist marker. - - DESCRIPTION ----------- This type is used to add a common marker file which indicates that a given @@ -23,11 +20,11 @@ None. OPTIONAL PARAMETERS ------------------- -destination:: +destination The path and filename of the marker. Default: /etc/cdist-configured -format:: +format The format of the timestamp. This is passed directly to system 'date'. Default: -u @@ -35,18 +32,18 @@ format:: EXAMPLES -------- --------------------------------------------------------------------------------- -# Creates the marker as normal. -__cdistmarker +.. code-block:: sh -# Creates the marker differently. -__cdistmarker --file /tmp/cdist_marker --format '+%s' --------------------------------------------------------------------------------- + # Creates the marker as normal. + __cdistmarker + + # Creates the marker differently. + __cdistmarker --destination /tmp/cdist_marker --format '+%s' SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__cdistmarker/parameter/default/destination b/cdist/conf/type/__cdistmarker/parameter/default/destination new file mode 100644 index 00000000..bd3a112f --- /dev/null +++ b/cdist/conf/type/__cdistmarker/parameter/default/destination @@ -0,0 +1 @@ +/etc/cdist-configured diff --git a/cdist/conf/type/__cdistmarker/parameter/default/format b/cdist/conf/type/__cdistmarker/parameter/default/format new file mode 100644 index 00000000..5dc9e6ec --- /dev/null +++ b/cdist/conf/type/__cdistmarker/parameter/default/format @@ -0,0 +1 @@ +-u diff --git a/cdist/conf/type/__config_file/gencode-remote b/cdist/conf/type/__config_file/gencode-remote new file mode 100755 index 00000000..e9b38c35 --- /dev/null +++ b/cdist/conf/type/__config_file/gencode-remote @@ -0,0 +1,34 @@ +#!/bin/sh +# +# 2015 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 . +# + +destination="$__object_id" +state="$(cat "$__object/parameter/state")" + +if [ "$state" = "absent" ]; then + # nothing to do + exit 0 +fi + +if [ -f "$__object/parameter/onchange" ]; then + if grep -q "^__file/${destination}" "$__messages_in"; then + cat "$__object/parameter/onchange" + fi +fi + diff --git a/cdist/conf/type/__config_file/man.rst b/cdist/conf/type/__config_file/man.rst new file mode 100644 index 00000000..49b63984 --- /dev/null +++ b/cdist/conf/type/__config_file/man.rst @@ -0,0 +1,57 @@ +cdist-type__config_file(7) +========================== +Manages config files + +Steven Armstrong + + +DESCRIPTION +----------- +Deploy config files using the file type. +Run the given code if the files changes. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +group + see cdist-type__file +mode + see cdist-type__file +onchange + the code to run if the file changes +owner + see cdist-type__file +source + Path to the config file. + If source is '-' (dash), take what was written to stdin as the config file content. +state + see cdist-type__file + + +EXAMPLES +-------- + +.. code-block:: sh + + __config_file /etc/consul/conf.d/watch_foo.json \ + --owner root --group consul --mode 640 \ + --source "$__type/files/watch_foo.json" \ + --state present \ + --onchange 'service consul status >/dev/null && service consul reload || true' + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__file(7) `_ + + +COPYING +------- +Copyright \(C) 2015 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/__config_file/manifest b/cdist/conf/type/__config_file/manifest new file mode 100755 index 00000000..29add8b7 --- /dev/null +++ b/cdist/conf/type/__config_file/manifest @@ -0,0 +1,41 @@ +#!/bin/sh +# +# 2015 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 . +# + +set -- "/${__object_id}" +for param in $(ls "$__object/parameter/"); do + case "$param" in + source) + source="$(cat "$__object/parameter/source")" + if [ "$source" = "-" ]; then + source="$__object/stdin" + fi + set -- "$@" --source "$source" + ;; + owner|group|mode|state) + set -- "$@" "--${param}" "$(cat "$__object/parameter/$param")" + ;; + *) + # ignore unknown parameters + : + ;; + esac +done + +__file "$@" diff --git a/cdist/conf/type/__config_file/parameter/default/state b/cdist/conf/type/__config_file/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__config_file/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__config_file/parameter/optional b/cdist/conf/type/__config_file/parameter/optional new file mode 100644 index 00000000..085c7725 --- /dev/null +++ b/cdist/conf/type/__config_file/parameter/optional @@ -0,0 +1,6 @@ +group +mode +onchange +owner +source +state diff --git a/cdist/conf/type/__consul/files/versions/0.4.1/cksum b/cdist/conf/type/__consul/files/versions/0.4.1/cksum new file mode 100644 index 00000000..edba1a68 --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.4.1/cksum @@ -0,0 +1 @@ +428915666 15738724 consul diff --git a/cdist/conf/type/__consul/files/versions/0.4.1/source b/cdist/conf/type/__consul/files/versions/0.4.1/source new file mode 100644 index 00000000..b1e9908d --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.4.1/source @@ -0,0 +1 @@ +https://dl.bintray.com/mitchellh/consul/0.4.1_linux_amd64.zip diff --git a/cdist/conf/type/__consul/files/versions/0.5.0/cksum b/cdist/conf/type/__consul/files/versions/0.5.0/cksum new file mode 100644 index 00000000..fe9888ae --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.5.0/cksum @@ -0,0 +1 @@ +131560372 17734417 consul diff --git a/cdist/conf/type/__consul/files/versions/0.5.0/source b/cdist/conf/type/__consul/files/versions/0.5.0/source new file mode 100644 index 00000000..00a209a5 --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.5.0/source @@ -0,0 +1 @@ +https://dl.bintray.com/mitchellh/consul/0.5.0_linux_amd64.zip diff --git a/cdist/conf/type/__consul/files/versions/0.5.1/cksum b/cdist/conf/type/__consul/files/versions/0.5.1/cksum new file mode 100644 index 00000000..a176ed43 --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.5.1/cksum @@ -0,0 +1 @@ +2564582176 18232733 consul diff --git a/cdist/conf/type/__consul/files/versions/0.5.1/source b/cdist/conf/type/__consul/files/versions/0.5.1/source new file mode 100644 index 00000000..f02a1103 --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.5.1/source @@ -0,0 +1 @@ +https://dl.bintray.com/mitchellh/consul/0.5.1_linux_amd64.zip diff --git a/cdist/conf/type/__consul/files/versions/0.5.2/cksum b/cdist/conf/type/__consul/files/versions/0.5.2/cksum new file mode 100644 index 00000000..1c077266 --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.5.2/cksum @@ -0,0 +1 @@ +2207534901 18245010 consul diff --git a/cdist/conf/type/__consul/files/versions/0.5.2/source b/cdist/conf/type/__consul/files/versions/0.5.2/source new file mode 100644 index 00000000..43b43d55 --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.5.2/source @@ -0,0 +1 @@ +https://releases.hashicorp.com/consul/0.5.2/consul_0.5.2_linux_amd64.zip diff --git a/cdist/conf/type/__consul/files/versions/0.6.0/cksum b/cdist/conf/type/__consul/files/versions/0.6.0/cksum new file mode 100644 index 00000000..bf41a9b8 --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.6.0/cksum @@ -0,0 +1 @@ +688442448 19798264 consul diff --git a/cdist/conf/type/__consul/files/versions/0.6.0/source b/cdist/conf/type/__consul/files/versions/0.6.0/source new file mode 100644 index 00000000..691f2a87 --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.6.0/source @@ -0,0 +1 @@ +https://releases.hashicorp.com/consul/0.6.0/consul_0.6.0_linux_amd64.zip diff --git a/cdist/conf/type/__consul/files/versions/0.6.1/cksum b/cdist/conf/type/__consul/files/versions/0.6.1/cksum new file mode 100644 index 00000000..aa354351 --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.6.1/cksum @@ -0,0 +1 @@ +3100584780 20416856 consul diff --git a/cdist/conf/type/__consul/files/versions/0.6.1/source b/cdist/conf/type/__consul/files/versions/0.6.1/source new file mode 100644 index 00000000..3b20388f --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.6.1/source @@ -0,0 +1 @@ +https://releases.hashicorp.com/consul/0.6.1/consul_0.6.1_linux_amd64.zip diff --git a/cdist/conf/type/__consul/files/versions/0.6.2/cksum b/cdist/conf/type/__consul/files/versions/0.6.2/cksum new file mode 100644 index 00000000..9c0b35c5 --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.6.2/cksum @@ -0,0 +1 @@ +2124180907 20416920 consul diff --git a/cdist/conf/type/__consul/files/versions/0.6.2/source b/cdist/conf/type/__consul/files/versions/0.6.2/source new file mode 100644 index 00000000..b0c6eeed --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.6.2/source @@ -0,0 +1 @@ +https://releases.hashicorp.com/consul/0.6.2/consul_0.6.2_linux_amd64.zip diff --git a/cdist/conf/type/__consul/files/versions/0.6.3/cksum b/cdist/conf/type/__consul/files/versions/0.6.3/cksum new file mode 100644 index 00000000..886d01bb --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.6.3/cksum @@ -0,0 +1 @@ +1832669072 20417720 consul diff --git a/cdist/conf/type/__consul/files/versions/0.6.3/source b/cdist/conf/type/__consul/files/versions/0.6.3/source new file mode 100644 index 00000000..fef668be --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.6.3/source @@ -0,0 +1 @@ +https://releases.hashicorp.com/consul/0.6.3/consul_0.6.3_linux_amd64.zip diff --git a/cdist/conf/type/__consul/files/versions/0.6.4/cksum b/cdist/conf/type/__consul/files/versions/0.6.4/cksum new file mode 100644 index 00000000..1124b7aa --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.6.4/cksum @@ -0,0 +1 @@ +3832641574 23002736 consul diff --git a/cdist/conf/type/__consul/files/versions/0.6.4/source b/cdist/conf/type/__consul/files/versions/0.6.4/source new file mode 100644 index 00000000..96879b8d --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.6.4/source @@ -0,0 +1 @@ +https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip diff --git a/cdist/conf/type/__consul/man.rst b/cdist/conf/type/__consul/man.rst new file mode 100644 index 00000000..77fae852 --- /dev/null +++ b/cdist/conf/type/__consul/man.rst @@ -0,0 +1,51 @@ +cdist-type__consul(7) +===================== +Install consul + +Steven Armstrong + + +DESCRIPTION +----------- +Downloads and installs the consul binary from https://dl.bintray.com/mitchellh/consul. +Note that the consul binary is downloaded on the server (the machine running +cdist) and then deployed to the target host using the __file type. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +state + either 'present' or 'absent'. Defaults to 'present' + +version + which version of consul to install. See ./files/versions for a list of + supported versions. Defaults to the latest known version. + + +EXAMPLES +-------- + +.. code-block:: sh + + # just install using defaults + __consul + + # specific version + __consul \ + --version 0.4.1 + + +SEE ALSO +-------- +- `cdist-type(7) `_ + + +COPYING +------- +Copyright \(C) 2015 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/__consul/manifest b/cdist/conf/type/__consul/manifest new file mode 100755 index 00000000..0187d959 --- /dev/null +++ b/cdist/conf/type/__consul/manifest @@ -0,0 +1,55 @@ +#!/bin/sh +# +# 2015 Steven Armstrong (steven-cdist at armstrong.cc) +# 2016 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 . +# + + +os=$(cat "$__global/explorer/os") + +case "$os" in + centos|redhat|ubuntu|debian|archlinux|gentoo) + # any linux should work + : + ;; + *) + 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 + +versions_dir="$__type/files/versions" +version="$(cat "$__object/parameter/version")" +version_dir="$versions_dir/$version" + +if [ ! -d "$version_dir" ]; then + echo "Unknown consul version '$version'. Expected one of:" >&2 + ls "$versions_dir" >&2 + exit 1 +fi + +__staged_file /usr/local/bin/consul \ + --source "$(cat "$version_dir/source")" \ + --cksum "$(cat "$version_dir/cksum")" \ + --fetch-command 'curl -s -L "%s"' \ + --prepare-command 'unzip -p "%s"' \ + --state "$(cat "$__object/parameter/state")" \ + --group root \ + --owner root \ + --mode 755 diff --git a/cdist/conf/type/__consul/parameter/default/state b/cdist/conf/type/__consul/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul/parameter/default/version b/cdist/conf/type/__consul/parameter/default/version new file mode 100644 index 00000000..d2b13eb6 --- /dev/null +++ b/cdist/conf/type/__consul/parameter/default/version @@ -0,0 +1 @@ +0.6.4 diff --git a/cdist/conf/type/__consul/parameter/optional b/cdist/conf/type/__consul/parameter/optional new file mode 100644 index 00000000..4d595ed7 --- /dev/null +++ b/cdist/conf/type/__consul/parameter/optional @@ -0,0 +1,2 @@ +state +version diff --git a/cdist/test/cdist_object/fixtures/object/__first/child/.cdist/.keep b/cdist/conf/type/__consul/singleton similarity index 100% rename from cdist/test/cdist_object/fixtures/object/__first/child/.cdist/.keep rename to cdist/conf/type/__consul/singleton diff --git a/cdist/conf/type/__consul_agent/files/consul-prepare.upstart b/cdist/conf/type/__consul_agent/files/consul-prepare.upstart new file mode 100644 index 00000000..569220d1 --- /dev/null +++ b/cdist/conf/type/__consul_agent/files/consul-prepare.upstart @@ -0,0 +1,9 @@ +start on starting consul + +task + +script + mkdir -p /var/run/consul + chown consul:consul /var/run/consul + chmod 2770 /var/run/consul +end script diff --git a/cdist/conf/type/__consul_agent/files/consul.systemd b/cdist/conf/type/__consul_agent/files/consul.systemd new file mode 100644 index 00000000..8d5fd323 --- /dev/null +++ b/cdist/conf/type/__consul_agent/files/consul.systemd @@ -0,0 +1,22 @@ +[Unit] +Description=Consul Agent +Wants=basic.target +After=basic.target network.target + +[Service] +User=consul +Group=consul +Environment="GOMAXPROCS=2" +# Run ExecStartPre with root-permissions +PermissionsStartOnly=true +ExecStartPre=/usr/bin/mkdir -p /var/run/consul +ExecStartPre=/usr/bin/chown consul:consul /var/run/consul +ExecStartPre=/usr/bin/chmod 2770 /var/run/consul +ExecStart=/usr/local/bin/consul agent -config-dir /etc/consul/conf.d +ExecReload=/bin/kill -HUP $MAINPID +KillMode=process +Restart=on-failure +RestartSec=42s + +[Install] +WantedBy=multi-user.target diff --git a/cdist/conf/type/__consul_agent/files/consul.sysv-debian b/cdist/conf/type/__consul_agent/files/consul.sysv-debian new file mode 100644 index 00000000..a75c555d --- /dev/null +++ b/cdist/conf/type/__consul_agent/files/consul.sysv-debian @@ -0,0 +1,81 @@ +#!/bin/sh +# +# 2015 Nico Schottelius (nico-cdist at schottelius.org) +# 2015 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 . +# + +if [ -f "/etc/default/consul" ]; then + . /etc/default/consul +fi + +. /lib/lsb/init-functions + +NAME=consul +CONSUL=/usr/local/bin/consul +CONFIG=/etc/$NAME/conf.d +PID_FILE=/var/run/$NAME/pidfile + +mkdir -p /var/run/$NAME +chown consul:consul /var/run/$NAME +chmod 2770 /var/run/$NAME + +export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" + +case "$1" in + start) + log_daemon_msg "Starting consul agent" "consul" || true + if start-stop-daemon --start --quiet --oknodo \ + --pidfile "$PID_FILE" --background \ + --exec $CONSUL -- agent -pid-file="$PID_FILE" -config-dir "$CONFIG"; then + log_end_msg 0 || true + else + log_end_msg 1 || true + fi + ;; + + stop) + log_daemon_msg "Stopping consul agent" "consul" || true + if start-stop-daemon --stop --quiet --oknodo --pidfile $PID_FILE; then + log_end_msg 0 || true + else + log_end_msg 1 || true + fi + ;; + + reload) + log_daemon_msg "Reloading consul agent" "consul" || true + if start-stop-daemon --stop --signal HUP --quiet --oknodo --pidfile $PID_FILE --exec $CONSUL; then + log_end_msg 0 || true + else + log_end_msg 1 || true + fi + ;; + + restart) + $0 stop && $0 start + ;; + + status) + status_of_proc -p $PID_FILE $CONSUL consul && exit 0 || exit $? + ;; + + *) + log_action_msg "Usage: /etc/init.d/consul {start|stop|reload|restart|status}" + exit 1 + ;; +esac diff --git a/cdist/conf/type/__consul_agent/files/consul.sysv-redhat b/cdist/conf/type/__consul_agent/files/consul.sysv-redhat new file mode 100644 index 00000000..13dafd2e --- /dev/null +++ b/cdist/conf/type/__consul_agent/files/consul.sysv-redhat @@ -0,0 +1,95 @@ +#!/bin/bash +# +# /etc/rc.d/init.d/consul +# +# Daemonize the consul agent. +# +# chkconfig: 2345 95 95 +# description: Service discovery and configuration made easy. \ +# Distributed, highly available, and datacenter-aware. +# processname: consul +# pidfile: /var/run/consul/pidfile + +# Source function library. +. /etc/init.d/functions +NAME=consul +CONSUL=/usr/local/bin/consul +CONFIG=/etc/$NAME/conf.d +PID_FILE=/var/run/$NAME/pidfile +LOG_FILE=/var/log/$NAME + +[ -e /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME +export GOMAXPROCS=${GOMAXPROCS:-2} + +mkdir -p /var/run/$NAME +chown consul:consul /var/run/$NAME +chmod 2770 /var/run/$NAME + + +start() { + echo -n "Starting $NAME: " + daemon --user=consul \ + --pidfile="$PID_FILE" \ + "$CONSUL" agent -pid-file="$PID_FILE" -config-dir "$CONFIG" >> "$LOG_FILE" & + retcode=$? + touch /var/lock/subsys/$NAME + return $retcode +} + +stop() { + echo -n "Shutting down $NAME: " + killproc -p "$PID_FILE" $NAME + retcode=$? + rm -f /var/lock/subsys/$NAME + return $retcode +} + +case "$1" in + start) + if $(status -p "$PID_FILE" $NAME >/dev/null); then + echo "$NAME already running" + else + start + fi + ;; + stop) + if $(status -p "$PID_FILE" $NAME >/dev/null); then + stop + else + echo "$NAME not running" + fi + ;; + info) + "$CONSUL" info + ;; + status) + status -p "$PID_FILE" $NAME + exit $? + ;; + restart) + if $(status -p "$PID_FILE" $NAME >/dev/null); then + stop + fi + start + ;; + reload) + if $(status -p "$PID_FILE" $NAME >/dev/null); then + kill -HUP `cat $PID_FILE` + else + echo "$NAME not running" + fi + ;; + condrestart) + if [ -f /var/lock/subsys/$NAME ]; then + if $(status -p "$PID_FILE" $NAME >/dev/null); then + stop + fi + start + fi + ;; + *) + echo "Usage: $NAME {start|stop|status|reload|restart|condrestart|info}" + exit 1 + ;; +esac +exit $? diff --git a/cdist/conf/type/__consul_agent/files/consul.upstart b/cdist/conf/type/__consul_agent/files/consul.upstart new file mode 100644 index 00000000..ed0c7b8e --- /dev/null +++ b/cdist/conf/type/__consul_agent/files/consul.upstart @@ -0,0 +1,13 @@ +description "Consul Agent" +start on (local-filesystems and net-device-up IFACE!=lo) +stop on runlevel [06] + +setuid consul +setgid consul + +respawn +respawn limit 10 10 +kill timeout 10 + +exec /usr/local/bin/consul agent -config-dir /etc/consul/conf.d + diff --git a/cdist/conf/type/__consul_agent/gencode-remote b/cdist/conf/type/__consul_agent/gencode-remote new file mode 100755 index 00000000..04662967 --- /dev/null +++ b/cdist/conf/type/__consul_agent/gencode-remote @@ -0,0 +1,31 @@ +#!/bin/sh +# +# 2015 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 . +# + +service="consul" +state="$(cat "$__object/parameter/state")" + +case "$state" in + present) + : + ;; + absent) + echo "service $service stop || true" + ;; +esac diff --git a/cdist/conf/type/__consul_agent/man.rst b/cdist/conf/type/__consul_agent/man.rst new file mode 100644 index 00000000..8285cb25 --- /dev/null +++ b/cdist/conf/type/__consul_agent/man.rst @@ -0,0 +1,174 @@ +cdist-type__consul_agent(7) +=========================== +Manage the consul agent + +Steven Armstrong + + +DESCRIPTION +----------- +Configure and manage the consul agent. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +acl-datacenter + only used by servers. This designates the datacenter which is authoritative + for ACL information. + +acl-default-policy + either "allow" or "deny"; defaults to "allow". The default policy controls the + behavior of a token when there is no matching rule. + +acl-down-policy + either "allow", "deny" or "extend-cache"; "extend-cache" is the default. + +acl-master-token + only used for servers in the acl_datacenter. This token will be created with + management-level permissions if it does not exist. It allows operators to + bootstrap the ACL system with a token ID that is well-known. + +acl-token + when provided, the agent will use this token when making requests to the + Consul servers. + +acl-ttl + used to control Time-To-Live caching of ACLs. + +bind-addr + sets the bind address for cluster communication + +bootstrap-expect + sets server to expect bootstrap mode + +ca-file-source + path to a PEM encoded certificate authority file which will be uploaded and + configure using the ca_file config option. + +cert-file-source + path to a PEM encoded certificate file which will be uploaded and + configure using the cert_file config option. + +client-addr + sets the address to bind for client access + +datacenter + datacenter of the agent + +encrypt + provides the gossip encryption key + +group + the primary group for the agent + +json-config + path to a partial json config file without leading { and trailing }. + If json-config is '-' (dash), take what was written to stdin as the file content. + +key-file-source + path to a PEM encoded private key file which will be uploaded and + configure using the key_file config option. + +node-name + name of this node. Must be unique in the cluster + +retry-join + address to attempt joining every retry_interval until at least one join works. + Can be specified multiple times. + +user + the user to run the agent as + +state + if the agent is 'present' or 'absent'. Defaults to 'present'. + Currently state=absent is not working due to some dependency issues. + + +BOOLEAN PARAMETERS +------------------ +disable-remote-exec + disables support for remote execution. When set to true, the agent will ignore any incoming remote exec requests. + +disable-update-check + disables automatic checking for security bulletins and new version releases + +leave-on-terminate + gracefully leave cluster on SIGTERM + +rejoin-after-leave + rejoin the cluster using the previous state after leaving + +server + used to control if an agent is in server or client mode + +syslog + enables logging to syslog + +verify-incoming + enforce the use of TLS and verify a client's authenticity on incomming connections + +verify-outgoing + enforce the use of TLS and verify the peers authenticity on outgoing connections + + +EXAMPLES +-------- + +.. code-block:: sh + + # configure as server, bootstrap and rejoin + hostname="$(cat "$__global/explorer/hostname")" + __consul_agent \ + --datacenter dc1 \ + --node-name "${hostname%%.*}" \ + --disable-update-check \ + --server \ + --rejoin-after-leave \ + --bootstrap-expect 3 \ + --retry-join consul-01 \ + --retry-join consul-02 \ + --retry-join consul-03 + + # configure as server, bootstrap and rejoin with ssl support + hostname="$(cat "$__global/explorer/hostname")" + __consul_agent \ + --datacenter dc1 \ + --node-name "${hostname%%.*}" \ + --disable-update-check \ + --server \ + --rejoin-after-leave \ + --bootstrap-expect 3 \ + --retry-join consul-01 \ + --retry-join consul-02 \ + --retry-join consul-03 \ + --ca-file-source /path/to/ca.pem \ + --cert-file-source /path/to/cert.pem \ + --key-file-source /path/to/key.pem \ + --verify-incoming \ + --verify-outgoing + + # configure as client and try joining existing cluster + __consul_agent \ + --datacenter dc1 \ + --node-name "${hostname%%.*}" \ + --disable-update-check \ + --retry-join consul-01 \ + --retry-join consul-02 \ + --retry-join consul-03 + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- http://www.consul.io/docs/agent/options.html + + +COPYING +------- +Copyright \(C) 2015 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/__consul_agent/manifest b/cdist/conf/type/__consul_agent/manifest new file mode 100755 index 00000000..b4d1d75c --- /dev/null +++ b/cdist/conf/type/__consul_agent/manifest @@ -0,0 +1,221 @@ +#!/bin/sh +# +# 2015 Steven Armstrong (steven-cdist at armstrong.cc) +# 2015 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 . +# + + +os=$(cat "$__global/explorer/os") + +case "$os" in + centos|debian|redhat|ubuntu) + # whitelist safeguard + : + ;; + *) + 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 + +state="$(cat "$__object/parameter/state")" +user="$(cat "$__object/parameter/user")" +group="$(cat "$__object/parameter/group")" +data_dir="/var/lib/consul" +conf_dir="/etc/consul/conf.d" +conf_file="config.json" + +# FIXME: there has got to be a better way to handle the dependencies in this case +case "$state" in + present) + __group "$group" --system --state "$state" + require="__group/$group" \ + __user "$user" --system --gid "$group" \ + --home "$data_dir" --state "$state" + export require="__user/consul" + ;; + absent) + echo "Sorry, state=absent currently not supported :-(" >&2 + exit 1 + require="$__object_name" \ + __user "$user" --system --gid "$group" --state "$state" + require="__user/$user" \ + __group "$group" --system --state "$state" + ;; +esac + +__directory /etc/consul \ + --owner root --group "$group" --mode 750 --state "$state" +require="__directory/etc/consul" \ + __directory "$conf_dir" \ + --owner root --group "$group" --mode 750 --state "$state" + +if [ -f "$__object/parameter/ca-file-source" -o -f "$__object/parameter/cert-file-source" -o -f "$__object/parameter/key-file-source" ]; then + # create directory for ssl certs + require="__directory/etc/consul" \ + __directory /etc/consul/ssl \ + --owner root --group "$group" --mode 750 --state "$state" +fi + +__directory "$data_dir" \ + --owner "$user" --group "$group" --mode 770 --state "$state" + + +# Generate json config file +( +echo "{" + +# parameters we define ourself +printf ' "data_dir": "%s"\n' "$data_dir" + +for param in $(ls "$__object/parameter/"); do + case "$param" in + state|user|group|json-config) continue ;; + ca-file-source|cert-file-source|key-file-source) + source="$(cat "$__object/parameter/$param")" + destination="/etc/consul/ssl/${source##*/}" + require="__directory/etc/consul/ssl" \ + __file "$destination" \ + --owner root --group consul --mode 640 \ + --source "$source" \ + --state "$state" + key="$(echo "${param%-*}" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$destination" + ;; + disable-remote-exec|disable-update-check|leave-on-terminate|rejoin-after-leave|server|syslog|verify-incoming|verify-outgoing) + # handle boolean parameters + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": true\n' "$key" + ;; + retry-join) + # join multiple parameters into json array + retry_join="$(awk '{printf "\""$1"\","}' "$__object/parameter/retry-join")" + # remove trailing , + printf ' ,"retry_join": [%s]\n' "${retry_join%*,}" + ;; + retry-join-wan) + # join multiple parameters into json array over wan + retry_join_wan="$(awk '{printf "\""$1"\","}' "$__object/parameter/retry-join-wan")" + # remove trailing , + printf ' ,"retry_join_wan": [%s]\n' "${retry_join_wan%*,}" + ;; + bootstrap-expect) + # integer key=value parameters + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": %s\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + *) + # string key=value parameters + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +if [ -f "$__object/parameter/json-config" ]; then + json_config="$(cat "$__object/parameter/json-config")" + if [ "$json_config" = "-" ]; then + json_config="$__object/stdin" + fi + # remove leading and trailing whitespace and commas from first and last line + # indent each line with 3 spaces for consistency + json=$(sed -e 's/^[ \t]*/ /' -e '1s/^[ \t,]*//' -e '$s/[ \t,]*$//' "$json_config") + printf ' ,%s\n' "$json" +fi +echo "}" +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group "$group" --mode 640 \ + --state "$state" \ + --onchange 'service consul status >/dev/null && service consul reload || true' \ + --source - + +init_sysvinit() +{ + __file /etc/init.d/consul \ + --owner root --group root --mode 0755 \ + --state "$state" \ + --source "$__type/files/consul.sysv-$1" + require="__file/etc/init.d/consul" __start_on_boot consul +} + +init_systemd() +{ + __file /lib/systemd/system/consul.service \ + --owner root --group root --mode 0644 \ + --state "$state" \ + --source "$__type/files/consul.systemd" + require="__file/lib/systemd/system/consul.service" __start_on_boot consul +} + +init_upstart() +{ + __file /etc/init/consul-prepare.conf \ + --owner root --group root --mode 0644 \ + --state "$state" \ + --source "$__type/files/consul-prepare.upstart" + require="__file/etc/init/consul-prepare.conf" \ + __file /etc/init/consul.conf \ + --owner root --group root --mode 0644 \ + --state "$state" \ + --source "$__type/files/consul.upstart" + require="__file/etc/init/consul.conf" __start_on_boot consul +} + +# Install init script to start on boot +case "$os" in + centos|redhat) + os_version="$(sed 's/[^0-9.]//g' "$__global/explorer/os_version")" + major_version="${os_version%%.*}" + case "$major_version" in + [456]) + init_sysvinit redhat + ;; + 7) + init_systemd + ;; + *) + echo "Unsupported CentOS/Redhat version: $os_version" >&2 + exit 1 + ;; + esac + ;; + + debian) + os_version=$(cat "$__global/explorer/os_version") + major_version="${os_version%%.*}" + + case "$major_version" in + [567]) + init_sysvinit debian + ;; + 8) + init_systemd + ;; + *) + echo "Unsupported Debian version $os_version" >&2 + exit 1 + ;; + esac + ;; + + ubuntu) + init_upstart + ;; +esac diff --git a/cdist/conf/type/__consul_agent/parameter/boolean b/cdist/conf/type/__consul_agent/parameter/boolean new file mode 100644 index 00000000..9efecf49 --- /dev/null +++ b/cdist/conf/type/__consul_agent/parameter/boolean @@ -0,0 +1,8 @@ +disable-remote-exec +disable-update-check +leave-on-terminate +rejoin-after-leave +server +syslog +verify-incoming +verify-outgoing diff --git a/cdist/conf/type/__consul_agent/parameter/default/group b/cdist/conf/type/__consul_agent/parameter/default/group new file mode 100644 index 00000000..7d22c92b --- /dev/null +++ b/cdist/conf/type/__consul_agent/parameter/default/group @@ -0,0 +1 @@ +consul diff --git a/cdist/conf/type/__consul_agent/parameter/default/state b/cdist/conf/type/__consul_agent/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_agent/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_agent/parameter/default/user b/cdist/conf/type/__consul_agent/parameter/default/user new file mode 100644 index 00000000..7d22c92b --- /dev/null +++ b/cdist/conf/type/__consul_agent/parameter/default/user @@ -0,0 +1 @@ +consul diff --git a/cdist/conf/type/__consul_agent/parameter/optional b/cdist/conf/type/__consul_agent/parameter/optional new file mode 100644 index 00000000..37aad8c1 --- /dev/null +++ b/cdist/conf/type/__consul_agent/parameter/optional @@ -0,0 +1,20 @@ +acl-datacenter +acl-default-policy +acl-down-policy +acl-master-token +acl-token +acl-ttl +bind-addr +bootstrap-expect +ca-file-source +cert-file-source +client-addr +datacenter +encrypt +group +json-config +key-file-source +node-name +user +state +advertise-wan diff --git a/cdist/conf/type/__consul_agent/parameter/optional_multiple b/cdist/conf/type/__consul_agent/parameter/optional_multiple new file mode 100644 index 00000000..740e4d7f --- /dev/null +++ b/cdist/conf/type/__consul_agent/parameter/optional_multiple @@ -0,0 +1,2 @@ +retry-join +retry-join-wan diff --git a/cdist/test/cdist_object/fixtures/object/__first/dog/.cdist/.keep b/cdist/conf/type/__consul_agent/singleton similarity index 100% rename from cdist/test/cdist_object/fixtures/object/__first/dog/.cdist/.keep rename to cdist/conf/type/__consul_agent/singleton diff --git a/cdist/conf/type/__consul_check/man.rst b/cdist/conf/type/__consul_check/man.rst new file mode 100644 index 00000000..1de65358 --- /dev/null +++ b/cdist/conf/type/__consul_check/man.rst @@ -0,0 +1,71 @@ +cdist-type__consul_check(7) +============================= +Manages consul checks + +Steven Armstrong + + +DESCRIPTION +----------- +Generate and deploy check definitions for a consul agent. +See http://www.consul.io/docs/agent/checks.html for parameter documentation. + +Use either script toghether with interval, or use ttl. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +interval + the interval in which the script given with --script should be run + +script + the shell command to run every --interval + +ttl + how long a check is considered healthy without being updated through the + HTTP interfave + +id + Defaults to --name + +name + The name of this check. Defaults to __object_id + +notes + human readable description + +state + if this check is 'present' or 'absent'. Defaults to 'present'. + + +EXAMPLES +-------- + +.. code-block:: sh + + __consul_check redis \ + --script /usr/local/bin/check_redis.py \ + --interval 10s + + __consul_check some-object-id \ + --id web-app \ + --name "Web App Status" \ + --notes "Web app does a curl internally every 10 seconds" \ + --ttl 30s + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__consul_agent(7) `_ + + +COPYING +------- +Copyright \(C) 2015 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/__consul_check/manifest b/cdist/conf/type/__consul_check/manifest new file mode 100755 index 00000000..3004f319 --- /dev/null +++ b/cdist/conf/type/__consul_check/manifest @@ -0,0 +1,64 @@ +#!/bin/sh +# +# 2015 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 . +# + +name="$(cat "$__object/parameter/name" 2>/dev/null || echo "$__object_id")" +conf_dir="/etc/consul/conf.d" +conf_file="check_${name}.json" +state="$(cat "$__object/parameter/state")" + +# Sanity checks +if [ -f "$__object/parameter/script" -a -f "$__object/parameter/ttl" ]; then + echo "Use either --script together with --interval OR --ttl, but not both" >&2 + exit 1 +fi +if [ -f "$__object/parameter/script" -a ! -f "$__object/parameter/interval" ]; then + echo "When using --script you must also define --interval" >&2 + exit 1 +fi + +# Generate json config file +( +echo "{" +printf ' "check": {\n' +printf ' "name": "%s"\n' "$name" +for param in $(ls "$__object/parameter/"); do + case "$param" in + state|name|interval) continue ;; + script) + printf ' ,"script": "%s"\n' "$(cat "$__object/parameter/script")" + printf ' ,"interval": "%s"\n' "$(cat "$__object/parameter/interval")" + ;; + *) + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +# end check +echo " }" +# end json file +echo "}" +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group consul --mode 640 \ + --state "$state" \ + --onchange 'service consul status >/dev/null && service consul reload || true' \ + --source - diff --git a/cdist/conf/type/__consul_check/parameter/default/state b/cdist/conf/type/__consul_check/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_check/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_check/parameter/optional b/cdist/conf/type/__consul_check/parameter/optional new file mode 100644 index 00000000..f6c3a6e4 --- /dev/null +++ b/cdist/conf/type/__consul_check/parameter/optional @@ -0,0 +1,7 @@ +id +interval +name +notes +script +state +ttl diff --git a/cdist/conf/type/__consul_reload/gencode-remote b/cdist/conf/type/__consul_reload/gencode-remote new file mode 100755 index 00000000..9369db73 --- /dev/null +++ b/cdist/conf/type/__consul_reload/gencode-remote @@ -0,0 +1,24 @@ +#!/bin/sh +# +# 2015 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 . +# + +service="consul" +if grep -q "^__file/etc/consul/conf.d/" "$__messages_in"; then + echo "service $service status && service $service reload || true" +fi diff --git a/cdist/conf/type/__consul_reload/man.rst b/cdist/conf/type/__consul_reload/man.rst new file mode 100644 index 00000000..f66bb545 --- /dev/null +++ b/cdist/conf/type/__consul_reload/man.rst @@ -0,0 +1,39 @@ +cdist-type__consul_reload(7) +============================ +Reload consul + +Steven Armstrong + + +DESCRIPTION +----------- +Reload consul after configuration changes. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +None. + + +EXAMPLES +-------- + +.. code-block:: sh + + __consul_reload + + +SEE ALSO +-------- +- `cdist-type(7) `_ + + +COPYING +------- +Copyright \(C) 2015 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/test/cdist_object/fixtures/object/__first/man/.cdist/.keep b/cdist/conf/type/__consul_reload/singleton similarity index 100% rename from cdist/test/cdist_object/fixtures/object/__first/man/.cdist/.keep rename to cdist/conf/type/__consul_reload/singleton diff --git a/cdist/conf/type/__consul_service/man.rst b/cdist/conf/type/__consul_service/man.rst new file mode 100644 index 00000000..9a8efaab --- /dev/null +++ b/cdist/conf/type/__consul_service/man.rst @@ -0,0 +1,75 @@ +cdist-type__consul_service(7) +============================= +Manages consul services + +Steven Armstrong + + +DESCRIPTION +----------- +Generate and deploy service definitions for a consul agent. +See http://www.consul.io/docs/agent/services.html for parameter documentation. + +Use either script together with interval, or use ttl. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +check-interval + the interval in which the script given with --check-script should be run + +check-script + the shell command to run every --check-interval + +check-ttl + how long a service is considered healthy without being updated through the + HTTP interfave + +id + Defaults to --name + +name + The name of this service. Defaults to __object_id + +port + the port at which this service can be reached + +state + if this service is 'present' or 'absent'. Defaults to 'present'. + +tag + a tag to add to this service. Can be specified multiple times. + + +EXAMPLES +-------- + +.. code-block:: sh + + __consul_service redis \ + --tag master \ + --tag production \ + --port 8000 \ + --check-script /usr/local/bin/check_redis.py \ + --check-interval 10s + + __consul_service webapp \ + --port 80 \ + --check-ttl 10s + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__consul_agent(7) `_ + + +COPYING +------- +Copyright \(C) 2015 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/__consul_service/manifest b/cdist/conf/type/__consul_service/manifest new file mode 100755 index 00000000..9ba64141 --- /dev/null +++ b/cdist/conf/type/__consul_service/manifest @@ -0,0 +1,83 @@ +#!/bin/sh +# +# 2015 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 . +# + +name="$(cat "$__object/parameter/name" 2>/dev/null || echo "$__object_id")" +conf_dir="/etc/consul/conf.d" +conf_file="service_${name}.json" +state="$(cat "$__object/parameter/state")" + +# Sanity checks +if [ -f "$__object/parameter/check-script" -a -f "$__object/parameter/check-ttl" ]; then + echo "Use either --check-script together with --check-interval OR --check-ttl, but not both" >&2 + exit 1 +fi +if [ -f "$__object/parameter/check-script" -a ! -f "$__object/parameter/check-interval" ]; then + echo "When using --check-script you must also define --check-interval" >&2 + exit 1 +fi + +# Generate json config file +( +echo "{" +printf ' "service": {\n' +printf ' "name": "%s"\n' "$name" +for param in $(ls "$__object/parameter/"); do + case "$param" in + state|name|check-interval) continue ;; + check-script) + printf ' ,"check": {\n' + printf ' "script": "%s"\n' "$(cat "$__object/parameter/check-script")" + printf ' ,"interval": "%s"\n' "$(cat "$__object/parameter/check-interval")" + printf ' }\n' + ;; + check-ttl) + printf ' ,"check": {\n' + printf ' "ttl": "%s"\n' "$(cat "$__object/parameter/check-ttl")" + printf ' }\n' + ;; + tag) + # create json array from newline delimited file + tags="$(awk '{printf "\""$1"\","}' "$__object/parameter/tag")" + # remove trailing , + printf ' ,"tags": [%s]\n' "${tags%*,}" + ;; + port) + # integer key=value parameters + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": %s\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + *) + # string key=value parameters + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +# end service +echo " }" +# end json file +echo "}" +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group consul --mode 640 \ + --state "$state" \ + --onchange 'service consul status >/dev/null && service consul reload || true' \ + --source - diff --git a/cdist/conf/type/__consul_service/parameter/default/state b/cdist/conf/type/__consul_service/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_service/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_service/parameter/optional b/cdist/conf/type/__consul_service/parameter/optional new file mode 100644 index 00000000..496e31a3 --- /dev/null +++ b/cdist/conf/type/__consul_service/parameter/optional @@ -0,0 +1,7 @@ +check-interval +check-script +check-ttl +id +name +port +state diff --git a/cdist/conf/type/__consul_service/parameter/optional_multiple b/cdist/conf/type/__consul_service/parameter/optional_multiple new file mode 100644 index 00000000..42c7c82c --- /dev/null +++ b/cdist/conf/type/__consul_service/parameter/optional_multiple @@ -0,0 +1 @@ +tag diff --git a/cdist/conf/type/__consul_template/files/consul-template.systemd b/cdist/conf/type/__consul_template/files/consul-template.systemd new file mode 100644 index 00000000..c67eaab5 --- /dev/null +++ b/cdist/conf/type/__consul_template/files/consul-template.systemd @@ -0,0 +1,19 @@ +[Unit] +Description=Consul-Template Daemon +Wants=basic.target +After=basic.target network.target + +[Service] +User=root +Group=root +Environment="CONSUL_TEMPLATE_LOG=info" +Environment="GOMAXPROCS=2" +ExecStart=/usr/local/bin/consul-template -config /etc/consul-template/conf.d +ExecReload=/bin/kill -HUP $MAINPID +KillMode=process +Restart=on-failure +RestartSec=10s +LimitNOFILE=4096 + +[Install] +WantedBy=multi-user.target diff --git a/cdist/conf/type/__consul_template/files/consul-template.sysv b/cdist/conf/type/__consul_template/files/consul-template.sysv new file mode 100644 index 00000000..0a463020 --- /dev/null +++ b/cdist/conf/type/__consul_template/files/consul-template.sysv @@ -0,0 +1,89 @@ +#!/bin/bash +# +# /etc/rc.d/init.d/consul-template +# +# Daemonize the consul-template agent. +# +# chkconfig: 2345 95 95 +# description: Generic template rendering and notifications with Consul +# processname: consul-template +# pidfile: /var/run/consul-template/pidfile + +# Source function library. +. /etc/init.d/functions +NAME=consul-template +CONSUL_TEMPLATE=/usr/local/bin/consul-template +CONFIG=/etc/$NAME/conf.d +PID_FILE=/var/run/$NAME/pidfile +LOG_FILE=/var/log/$NAME + +[ -e /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME +export CONSUL_TEMPLATE_LOG=${CONSUL_TEMPLATE_LOG:-info} +export GOMAXPROCS=${GOMAXPROCS:-2} + +mkdir -p /var/run/$NAME + +start() { + echo -n "Starting $NAME: " + daemon --pidfile="$PID_FILE" \ + "$CONSUL_TEMPLATE" -config "$CONFIG" >> "$LOG_FILE" 2>&1 & + echo $! > "$PID_FILE" + retcode=$? + touch /var/lock/subsys/$NAME + return $retcode +} + +stop() { + echo -n "Shutting down $NAME: " + killproc -p $PID_FILE $CONSUL_TEMPLATE + retcode=$? + rm -f /var/lock/subsys/$NAME + return $retcode +} + +case "$1" in + start) + if $(status -p "$PID_FILE" $NAME >/dev/null); then + echo "$NAME already running" + else + start + fi + ;; + stop) + if $(status -p "$PID_FILE" $NAME >/dev/null); then + stop + else + echo "$NAME not running" + fi + ;; + status) + status -p "$PID_FILE" $NAME + exit $? + ;; + restart) + if $(status -p "$PID_FILE" $NAME >/dev/null); then + stop + fi + start + ;; + reload) + if $(status -p "$PID_FILE" $NAME >/dev/null); then + kill -HUP `cat $PID_FILE` + else + echo "$NAME not running" + fi + ;; + condrestart) + if [ -f /var/lock/subsys/$NAME ]; then + if $(status -p "$PID_FILE" $NAME >/dev/null); then + stop + fi + start + fi + ;; + *) + echo "Usage: $NAME {start|stop|status|reload|restart}" + exit 1 + ;; +esac +exit $? diff --git a/cdist/conf/type/__consul_template/files/consul-template.upstart b/cdist/conf/type/__consul_template/files/consul-template.upstart new file mode 100644 index 00000000..b81a2818 --- /dev/null +++ b/cdist/conf/type/__consul_template/files/consul-template.upstart @@ -0,0 +1,12 @@ +description "Consul-Template Daemon" +start on (local-filesystems and net-device-up IFACE!=lo) +stop on runlevel [06] + +env CONSUL_TEMPLATE_LOG=info +env GOMAXPROCS=${GOMAXPROCS} + +exec /usr/local/bin/consul-template -config /etc/consul-template/conf.d >> /var/log/consul-template 2>&1 + +respawn +respawn limit 10 10 +kill timeout 10 diff --git a/cdist/conf/type/__consul_template/files/versions/0.10.0/cksum b/cdist/conf/type/__consul_template/files/versions/0.10.0/cksum new file mode 100644 index 00000000..bbf394db --- /dev/null +++ b/cdist/conf/type/__consul_template/files/versions/0.10.0/cksum @@ -0,0 +1 @@ +3401777891 9273880 consul-template diff --git a/cdist/conf/type/__consul_template/files/versions/0.10.0/source b/cdist/conf/type/__consul_template/files/versions/0.10.0/source new file mode 100644 index 00000000..7fa074b5 --- /dev/null +++ b/cdist/conf/type/__consul_template/files/versions/0.10.0/source @@ -0,0 +1 @@ +https://github.com/hashicorp/consul-template/releases/download/v0.10.0/consul-template_0.10.0_linux_amd64.tar.gz diff --git a/cdist/conf/type/__consul_template/man.rst b/cdist/conf/type/__consul_template/man.rst new file mode 100644 index 00000000..bcdb94e3 --- /dev/null +++ b/cdist/conf/type/__consul_template/man.rst @@ -0,0 +1,134 @@ +cdist-type__consul_template(7) +============================== +Manage the consul-template service + +Steven Armstrong + + +DESCRIPTION +----------- +Downloads and installs the consul-template binary from +https://github.com/hashicorp/consul-template/releases/download/. +Generates a global config file and creates directory for per template config files. +Note that the consul-template binary is downloaded on the server (the machine running +cdist) and then deployed to the target host using the __file type. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +auth-username + specify a username for basic authentication. + +auth-password + specify a password for basic authentication. + +batch-size + the size of the batch when polling multiple dependencies. + +consul + the location of the Consul instance to query (may be an IP address or FQDN) with port. + Defaults to 'localhost:8500'. + +log-level + The log level for output. This applies to the stdout/stderr logging as well + as syslog logging (if enabled). Valid values are "debug", "info", "warn", + and "err". The default value is "warn". + +max-stale + the maximum staleness of a query. If specified, Consul will distribute work among all + servers instead of just the leader. + +retry + the amount of time to wait if Consul returns an error when communicating + with the API. + +state + either 'present' or 'absent'. Defaults to 'present' + +ssl-cert + Path to an SSL client certificate to use to authenticate to the consul server. + Useful if the consul server "verify_incoming" option is set. + +ssl-ca-cert + Path to a CA certificate file, containing one or more CA certificates to + use to validate the certificate sent by the consul server to us. This is a + handy alternative to setting --ssl-no-verify if you are using your own CA. + +syslog-facility + The facility to use when sending to syslog. This requires the use of --syslog. + The default value is LOCAL0. + +token + the Consul API token. + +vault-address + the location of the Vault instance to query (may be an IP address or FQDN) with port. + +vault-token + the Vault API token. + +vault-ssl-cert + Path to an SSL client certificate to use to authenticate to the vault server. + +vault-ssl-ca-cert + Path to a CA certificate file, containing one or more CA certificates to + use to validate the certificate sent by the vault server to us. + +version + which version of consul-template to install. See ./files/versions for a list of + supported versions. Defaults to the latest known version. + +wait + the minimum(:maximum) to wait before rendering a new template to disk and + triggering a command, separated by a colon (:). If the optional maximum + value is omitted, it is assumed to be 4x the required minimum value. + + +BOOLEAN PARAMETERS +------------------ +ssl + use HTTPS while talking to Consul. Requires the Consul server to be configured to serve secure connections. + +ssl-no-verify + ignore certificate warnings. Only used if ssl is enabled. + +syslog + Send log output to syslog (in addition to stdout and stderr). + +vault-ssl + use HTTPS while talking to Vault. Requires the Vault server to be configured to serve secure connections. + +vault-ssl-no-verify + ignore certificate warnings. Only used if vault is enabled. + + +EXAMPLES +-------- + +.. code-block:: sh + + __consul_template \ + --consul consul.service.consul:8500 \ + --retry 30s + + # specific version + __consul_template \ + --version 0.6.5 \ + --retry 30s + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- https://github.com/hashicorp/consul-template + + +COPYING +------- +Copyright \(C) 2015 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/__consul_template/manifest b/cdist/conf/type/__consul_template/manifest new file mode 100755 index 00000000..cedcb413 --- /dev/null +++ b/cdist/conf/type/__consul_template/manifest @@ -0,0 +1,190 @@ +#!/bin/sh +# +# 2015 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") + +case "$os" in + centos|redhat) + # whitelist safeguard + service_onchange='service consul-template status >/dev/null && service consul-template reload || true' \ + ;; + archlinux) + service_onchange="systemctl status consul-template >/dev/null && systemctl reload consul-template || true" + ;; + *) + 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 + +versions_dir="$__type/files/versions" +version="$(cat "$__object/parameter/version")" +version_dir="$versions_dir/$version" + +if [ ! -d "$version_dir" ]; then + echo "Unknown consul-template version '$version'. Expected one of:" >&2 + ls "$versions_dir" >&2 + exit 1 +fi + +state="$(cat "$__object/parameter/state")" + +__staged_file /usr/local/bin/consul-template \ + --source "$(cat "$version_dir/source")" \ + --cksum "$(cat "$version_dir/cksum")" \ + --fetch-command 'curl -s -L "%s"' \ + --prepare-command 'tar -xzf "%s"; cat consul-template_*/consul-template' \ + --state "$state" \ + --group root \ + --owner root \ + --mode 755 + + +conf_dir="/etc/consul-template/conf.d" +conf_file="config.hcl" +template_dir="/etc/consul-template/template" + +__directory /etc/consul-template \ + --owner root --group root --mode 750 +require="__directory/etc/consul-template" \ + __directory "$conf_dir" \ + --owner root --group root --mode 750 +require="__directory/etc/consul-template" \ + __directory "$template_dir" \ + --owner root --group root --mode 750 + + +# Generate hcl config file +( +for param in $(ls "$__object/parameter/"); do + case "$param" in + auth-password|state|ssl-*|syslog-*|version|vault-token|vault-ssl*) continue ;; + auth-username) + printf 'auth {\n' + printf ' enabled = true\n' + printf ' username = "%s"\n' "$(cat "$__object/parameter/auth-username")" + if [ -f "$__object/parameter/auth-password" ]; then + printf ' password = %s\n' "$(cat "$__object/parameter/auth-password")" + fi + printf '}\n' + ;; + ssl) + printf 'ssl {\n' + printf ' enabled = true\n' + if [ -f "$__object/parameter/ssl-no-verify" ]; then + printf ' verify = false\n' + fi + if [ -f "$__object/parameter/ssl-cert" ]; then + printf ' cert = "%s"\n' "$(cat "$__object/parameter/ssl-cert")" + fi + if [ -f "$__object/parameter/ssl-ca-cert" ]; then + printf ' ca_cert = "%s"\n' "$(cat "$__object/parameter/ssl-ca-cert")" + fi + printf '}\n' + ;; + syslog) + printf 'syslog {\n' + printf ' enabled = true\n' + if [ -f "$__object/parameter/syslog-facility" ]; then + printf ' facility = "%s"\n' "$(cat "$__object/parameter/syslog-facility")" + fi + printf '}\n' + ;; + vault-address) + printf 'vault {\n' + printf ' address = "%s"\n' "$(cat "$__object/parameter/vault-address")" + if [ -f "$__object/parameter/vault-token" ]; then + printf ' token = "%s"\n' "$(cat "$__object/parameter/vault-token")" + fi + if [ -f "$__object/parameter/vault-ssl" ]; then + printf ' ssl {\n' + printf ' enabled = true\n' + if [ -f "$__object/parameter/vault-ssl-no-verify" ]; then + printf ' verify = false\n' + fi + if [ -f "$__object/parameter/vault-ssl-cert" ]; then + printf ' cert = "%s"\n' "$(cat "$__object/parameter/vault-ssl-cert")" + fi + if [ -f "$__object/parameter/vault-ssl-ca-cert" ]; then + printf ' ca_cert = "%s"\n' "$(cat "$__object/parameter/vault-ssl-ca-cert")" + fi + printf ' }\n' + fi + printf '}\n' + ;; + *) + # string key=value parameters + key="$(echo "$param" | tr '-' '_')" + printf '%s = "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group root --mode 640 \ + --state "$state" \ + --onchange "$service_onchange" \ + --source - + + +# Install init script to start on boot +service="consul-template" +case "$os" in + centos|redhat) + os_version="$(sed 's/[^0-9.]//g' "$__global/explorer/os_version")" + major_version="${os_version%%.*}" + case "$major_version" in + 7) + __file "/lib/systemd/system/${service}.service" \ + --owner root --group root --mode 0555 \ + --state "$state" \ + --source "$__type/files/${service}.systemd" + export require="__file/lib/systemd/system/${service}.service" + ;; + *) + __file "/etc/init.d/${service}" \ + --owner root --group root --mode 0555 \ + --state "$state" \ + --source "$__type/files/${service}.sysv" + export require="__file/etc/init.d/${service}" + ;; + esac + __start_on_boot "$service" --state "$state" + ;; + ubuntu) + __file "/etc/init/${service}.conf" \ + --owner root --group root --mode 0644 \ + --state "$state" \ + --source "$__type/files/${service}.upstart" + export require="__file/etc/init/${service}.conf" + __start_on_boot "$service" --state "$state" + ;; + archlinux) + __file "/lib/systemd/system/${service}.service" \ + --owner root --group root --mode 0555 \ + --state "$state" \ + --source "$__type/files/${service}.systemd" + export require="__file/lib/systemd/system/${service}.service" + __start_on_boot "$service" --state "$state" + ;; +esac diff --git a/cdist/conf/type/__consul_template/notes b/cdist/conf/type/__consul_template/notes new file mode 100644 index 00000000..fc7cca11 --- /dev/null +++ b/cdist/conf/type/__consul_template/notes @@ -0,0 +1,93 @@ +# < 0.7.0 +ssl = true +ssl_no_verify = true + +# >= 0.7.0 +ssl { + enabled = true + verify = false +} + +# >= 0.9.0 +ssl-cert +ssl-ca-cert + + + +-------------------------------------------------------------------------------- +### from docs + + +ssl { + enabled = true + verify = false + cert = "/path/to/client/cert.pem" + ca_cert = "/path/to/ca/cert.pem" +} + + +ssl + Use HTTPS while talking to Consul. Requires the Consul server to be configured to serve secure connections. The default value is false. + +ssl-verify + Verify certificates when connecting via SSL. This requires the use of -ssl. The default value is true. + +ssl-cert + Path to an SSL client certificate to use to authenticate to the consul server. Useful if the consul server "verify_incoming" option is set. + +ssl-ca-cert + Path to a CA certificate file, containing one or more CA certificates to use to validate the certificate sent by the consul server to us. This is a handy alternative to setting --ssl-verify=false if you are using your own CA. + +-------------------------------------------------------------------------------- + +### example config file from docs + +consul = "127.0.0.1:8500" +token = "abcd1234" // May also be specified via the envvar CONSUL_TOKEN +retry = "10s" +max_stale = "10m" +log_level = "warn" +pid_file = "/path/to/pid" + +vault { + address = "https://vault.service.consul:8200" + token = "abcd1234" // May also be specified via the envvar VAULT_TOKEN + ssl { + enabled = true + verify = true + cert = "/path/to/client/cert.pem" + ca_cert = "/path/to/ca/cert.pem" + } +} + + +--auth-username +--auth-password +# if any are given enabled = true +auth { + enabled = true + username = "test" + password = "test" +} + +ssl { + enabled = true + verify = false + cert = "/path/to/client/cert.pem" + ca_cert = "/path/to/ca/cert.pem" +} + +syslog { + enabled = true + facility = "LOCAL5" +} + +template { + source = "/path/on/disk/to/template" + destination = "/path/on/disk/where/template/will/render" + command = "optional command to run when the template is updated" +} + +template { + // Multiple template definitions are supported +} diff --git a/cdist/conf/type/__consul_template/parameter/boolean b/cdist/conf/type/__consul_template/parameter/boolean new file mode 100644 index 00000000..10057e46 --- /dev/null +++ b/cdist/conf/type/__consul_template/parameter/boolean @@ -0,0 +1,5 @@ +ssl +ssl-no-verify +syslog +vault-ssl +vault-ssl-no-verify diff --git a/cdist/conf/type/__consul_template/parameter/default/consul b/cdist/conf/type/__consul_template/parameter/default/consul new file mode 100644 index 00000000..42dfa616 --- /dev/null +++ b/cdist/conf/type/__consul_template/parameter/default/consul @@ -0,0 +1 @@ +localhost:8500 diff --git a/cdist/conf/type/__consul_template/parameter/default/log-level b/cdist/conf/type/__consul_template/parameter/default/log-level new file mode 100644 index 00000000..1ef71804 --- /dev/null +++ b/cdist/conf/type/__consul_template/parameter/default/log-level @@ -0,0 +1 @@ +warn diff --git a/cdist/conf/type/__consul_template/parameter/default/state b/cdist/conf/type/__consul_template/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_template/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_template/parameter/default/syslog-facility b/cdist/conf/type/__consul_template/parameter/default/syslog-facility new file mode 100644 index 00000000..f32df182 --- /dev/null +++ b/cdist/conf/type/__consul_template/parameter/default/syslog-facility @@ -0,0 +1 @@ +LOCAL0 diff --git a/cdist/conf/type/__consul_template/parameter/default/version b/cdist/conf/type/__consul_template/parameter/default/version new file mode 100644 index 00000000..78bc1abd --- /dev/null +++ b/cdist/conf/type/__consul_template/parameter/default/version @@ -0,0 +1 @@ +0.10.0 diff --git a/cdist/conf/type/__consul_template/parameter/optional b/cdist/conf/type/__consul_template/parameter/optional new file mode 100644 index 00000000..8bc528ac --- /dev/null +++ b/cdist/conf/type/__consul_template/parameter/optional @@ -0,0 +1,18 @@ +auth-username +auth-password +batch-size +consul +log-level +max-stale +retry +state +ssl-cert +ssl-ca-cert +syslog-facility +token +vault-address +vault-token +vault-ssl-cert +vault-ssl-ca-cert +version +wait diff --git a/cdist/test/cdist_object/fixtures/object/__first/woman/.cdist/.keep b/cdist/conf/type/__consul_template/singleton similarity index 100% rename from cdist/test/cdist_object/fixtures/object/__first/woman/.cdist/.keep rename to cdist/conf/type/__consul_template/singleton diff --git a/cdist/conf/type/__consul_template_template/man.rst b/cdist/conf/type/__consul_template_template/man.rst new file mode 100644 index 00000000..20d0a619 --- /dev/null +++ b/cdist/conf/type/__consul_template_template/man.rst @@ -0,0 +1,69 @@ +cdist-type__consul_template_template(7) +======================================= +Manage consul-template templates + +Steven Armstrong + + +DESCRIPTION +----------- +Generate and deploy template definitions for a consul-template. +See https://github.com/hashicorp/consul-template#examples for documentation. +Templates are written in the Go template format. +Either the --source or the --source-file parameter must be given. + + +REQUIRED PARAMETERS +------------------- +destination + the destination where the generated file should go. + + +OPTIONAL PARAMETERS +------------------- +command + an optional command to run after rendering the template to its destination. + +source + path to the template source. Conflicts --source-file. + +source-file + path to a local file which is uploaded using the __file type and configured + as the source. + If source is '-' (dash), take what was written to stdin as the file content. + Conflicts --source. + +state + if this template is 'present' or 'absent'. Defaults to 'present'. + + +EXAMPLES +-------- + +.. code-block:: sh + + # configure template on the target + __consul_template_template nginx \ + --source /etc/my-consul-templates/nginx.ctmpl \ + --destination /etc/nginx/nginx.conf \ + --command 'service nginx restart' + + + # upload a local file to the target and configure it + __consul_template_template nginx \ + --source-file "$__manifest/files/nginx.ctmpl" \ + --destination /etc/nginx/nginx.conf \ + --command 'service nginx restart' + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__consul_template(7) `_ +- `cdist-type__consul_template_config(7) `_ + + +COPYING +------- +Copyright \(C) 2015 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/__consul_template_template/manifest b/cdist/conf/type/__consul_template_template/manifest new file mode 100755 index 00000000..c997a2c8 --- /dev/null +++ b/cdist/conf/type/__consul_template_template/manifest @@ -0,0 +1,74 @@ +#!/bin/sh +# +# 2015 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 . +# + +name="$(cat "$__object/parameter/name" 2>/dev/null || echo "$__object_id")" +state="$(cat "$__object/parameter/state")" +conf_dir="/etc/consul-template/conf.d" +conf_file="template_${name}.hcl" +template_dir="/etc/consul-template/template" +require="" + +# Sanity checks +if [ -f "$__object/parameter/source" -a -f "$__object/parameter/source-file" ]; then + echo "Use either --source OR --source-file, but not both." >&2 + exit 1 +fi +if [ ! -f "$__object/parameter/source" -a ! -f "$__object/parameter/source-file" ]; then + echo "Either --source OR --source-file must be given." >&2 + exit 1 +fi + +# Generate hcl config file +( +printf 'template {\n' +for param in $(ls "$__object/parameter/"); do + case "$param" in + source-file) + source="$(cat "$__object/parameter/$param")" + if [ "$source" = "-" ]; then + source="$__object/stdin" + fi + destination="${template_dir}/${name}" + require="__directory${template_dir}" \ + __file "$destination" \ + --owner root --group root --mode 640 \ + --source "$source" \ + --state "$state" + export require="__file${destination}" + printf ' source = "%s"\n' "$destination" + + ;; + source|destination|command) + printf ' %s = "%s"\n' "$param" "$(cat "$__object/parameter/$param")" + ;; + *) + # ignore unknown parameters + : + ;; + esac +done +printf '}\n' +) | \ +require="$require __directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group root --mode 640 \ + --state "$state" \ + --onchange 'service consul-template status >/dev/null && service consul-template reload || true' \ + --source - diff --git a/cdist/conf/type/__consul_template_template/parameter/default/state b/cdist/conf/type/__consul_template_template/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_template_template/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_template_template/parameter/optional b/cdist/conf/type/__consul_template_template/parameter/optional new file mode 100644 index 00000000..229f6c89 --- /dev/null +++ b/cdist/conf/type/__consul_template_template/parameter/optional @@ -0,0 +1,4 @@ +command +source +source-file +state diff --git a/cdist/conf/type/__consul_template_template/parameter/required b/cdist/conf/type/__consul_template_template/parameter/required new file mode 100644 index 00000000..ac459b09 --- /dev/null +++ b/cdist/conf/type/__consul_template_template/parameter/required @@ -0,0 +1 @@ +destination diff --git a/cdist/conf/type/__consul_watch_checks/man.rst b/cdist/conf/type/__consul_watch_checks/man.rst new file mode 100644 index 00000000..c1e8c0a7 --- /dev/null +++ b/cdist/conf/type/__consul_watch_checks/man.rst @@ -0,0 +1,65 @@ +cdist-type__consul_watch_checks(7) +================================== +Manages consul checks watches + +Steven Armstrong + + +DESCRIPTION +----------- +Generate and deploy watch definitions of type 'checks' for a consul agent. +See http://www.consul.io/docs/agent/watches.html for parameter documentation. + + +REQUIRED PARAMETERS +------------------- +handler + the handler to invoke when the data view updates + + +OPTIONAL PARAMETERS +------------------- +datacenter + can be provided to override the agent's default datacenter + +filter-service + filter to a specific service. Conflicts with --filter-state. + +filter-state + filter to a specific state. Conflicts with --filter-service. + +state + if this watch is 'present' or 'absent'. Defaults to 'present'. + +token + can be provided to override the agent's default ACL token + + +EXAMPLES +-------- + +.. code-block:: sh + + __consul_watch_checks some-id \ + --handler /usr/bin/my-handler.sh + + __consul_watch_checks some-id \ + --filter-service consul \ + --handler /usr/bin/my-handler.sh + + __consul_watch_checks some-id \ + --filter-state passing \ + --handler /usr/bin/my-handler.sh + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__consul_agent(7) `_ +- http://www.consul.io/docs/agent/watches.html + + +COPYING +------- +Copyright \(C) 2015 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/__consul_watch_checks/manifest b/cdist/conf/type/__consul_watch_checks/manifest new file mode 100755 index 00000000..c05ae9eb --- /dev/null +++ b/cdist/conf/type/__consul_watch_checks/manifest @@ -0,0 +1,61 @@ +#!/bin/sh +# +# 2015 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 . +# + +cdist_type="${__type##*/}" +watch_type="${cdist_type##*_}" +conf_dir="/etc/consul/conf.d" +conf_file="watch_${watch_type}_${__object_id}.json" +state="$(cat "$__object/parameter/state")" + +# Sanity checks +if [ -f "$__object/parameter/filter-service" -a -f "$__object/parameter/filter-state" ]; then + echo "Use either --filter-service or --filter-state but not both." >&2 + exit 1 +fi + +# Generate json config file +( +echo "{" +printf ' "watches": [{\n' +printf ' "type": "%s"\n' "$watch_type" +for param in $(ls "$__object/parameter/"); do + case "$param" in + state) continue ;; + filter-*) + key="${param##*-}" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + *) + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +# end watches +echo " }]" +# end json file +echo "}" +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group consul --mode 640 \ + --state "$state" \ + --onchange 'service consul status >/dev/null && service consul reload || true' \ + --source - diff --git a/cdist/conf/type/__consul_watch_checks/parameter/default/state b/cdist/conf/type/__consul_watch_checks/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_watch_checks/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_watch_checks/parameter/optional b/cdist/conf/type/__consul_watch_checks/parameter/optional new file mode 100644 index 00000000..d37fd557 --- /dev/null +++ b/cdist/conf/type/__consul_watch_checks/parameter/optional @@ -0,0 +1,5 @@ +datacenter +filter-service +filter-state +state +token diff --git a/cdist/conf/type/__consul_watch_checks/parameter/required b/cdist/conf/type/__consul_watch_checks/parameter/required new file mode 100644 index 00000000..64b916c1 --- /dev/null +++ b/cdist/conf/type/__consul_watch_checks/parameter/required @@ -0,0 +1 @@ +handler diff --git a/cdist/conf/type/__consul_watch_event/man.rst b/cdist/conf/type/__consul_watch_event/man.rst new file mode 100644 index 00000000..ea9bc61a --- /dev/null +++ b/cdist/conf/type/__consul_watch_event/man.rst @@ -0,0 +1,58 @@ +cdist-type__consul_watch_event(7) +================================= +Manages consul event watches + +Steven Armstrong + + +DESCRIPTION +----------- +Generate and deploy watch definitions of type 'event' for a consul agent. +See http://www.consul.io/docs/agent/watches.html for parameter documentation. + + +REQUIRED PARAMETERS +------------------- +handler + the handler to invoke when the data view updates + + +OPTIONAL PARAMETERS +------------------- +datacenter + can be provided to override the agent's default datacenter + +name + restrict the watch to only events with the given name + +state + if this watch is 'present' or 'absent'. Defaults to 'present'. + +token + can be provided to override the agent's default ACL token + + +EXAMPLES +-------- + +.. code-block:: sh + + __consul_watch_event some-id \ + --handler /usr/bin/my-handler.sh + + __consul_watch_event some-id \ + --name web-deploy \ + --handler /usr/bin/my-handler.sh + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__consul_agent(7) `_ +- http://www.consul.io/docs/agent/watches.html + + +COPYING +------- +Copyright \(C) 2015 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/__consul_watch_event/manifest b/cdist/conf/type/__consul_watch_event/manifest new file mode 100755 index 00000000..4e36a10d --- /dev/null +++ b/cdist/conf/type/__consul_watch_event/manifest @@ -0,0 +1,51 @@ +#!/bin/sh +# +# 2015 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 . +# + +cdist_type="${__type##*/}" +watch_type="${cdist_type##*_}" +conf_dir="/etc/consul/conf.d" +conf_file="watch_${watch_type}_${__object_id}.json" +state="$(cat "$__object/parameter/state")" + +# Generate json config file +( +echo "{" +printf ' "watches": [{\n' +printf ' "type": "%s"\n' "$watch_type" +for param in $(ls "$__object/parameter/"); do + case "$param" in + state) continue ;; + *) + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +# end watches +echo " }]" +# end json file +echo "}" +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group consul --mode 640 \ + --state "$state" \ + --onchange 'service consul status >/dev/null && service consul reload || true' \ + --source - diff --git a/cdist/conf/type/__consul_watch_event/parameter/default/state b/cdist/conf/type/__consul_watch_event/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_watch_event/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_watch_event/parameter/optional b/cdist/conf/type/__consul_watch_event/parameter/optional new file mode 100644 index 00000000..ac808c47 --- /dev/null +++ b/cdist/conf/type/__consul_watch_event/parameter/optional @@ -0,0 +1,4 @@ +datacenter +name +state +token diff --git a/cdist/conf/type/__consul_watch_event/parameter/required b/cdist/conf/type/__consul_watch_event/parameter/required new file mode 100644 index 00000000..64b916c1 --- /dev/null +++ b/cdist/conf/type/__consul_watch_event/parameter/required @@ -0,0 +1 @@ +handler diff --git a/cdist/conf/type/__consul_watch_key/man.rst b/cdist/conf/type/__consul_watch_key/man.rst new file mode 100644 index 00000000..90e952b8 --- /dev/null +++ b/cdist/conf/type/__consul_watch_key/man.rst @@ -0,0 +1,55 @@ +cdist-type__consul_watch_key(7) +=============================== +Manages consul key watches + +Steven Armstrong + + +DESCRIPTION +----------- +Generate and deploy watch definitions of type 'key' for a consul agent. +See http://www.consul.io/docs/agent/watches.html for parameter documentation. + + +REQUIRED PARAMETERS +------------------- +handler + the handler to invoke when the data view updates + +key + the key to watch for changes + + +OPTIONAL PARAMETERS +------------------- +datacenter + can be provided to override the agent's default datacenter + +state + if this watch is 'present' or 'absent'. Defaults to 'present'. + +token + can be provided to override the agent's default ACL token + + +EXAMPLES +-------- + +.. code-block:: sh + + __consul_watch_key some-id \ + --key foo/bar/baz \ + --handler /usr/bin/my-key-handler.sh + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__consul_agent(7) `_ +- http://www.consul.io/docs/agent/watches.html + + +COPYING +------- +Copyright \(C) 2015 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/__consul_watch_key/manifest b/cdist/conf/type/__consul_watch_key/manifest new file mode 100755 index 00000000..4e36a10d --- /dev/null +++ b/cdist/conf/type/__consul_watch_key/manifest @@ -0,0 +1,51 @@ +#!/bin/sh +# +# 2015 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 . +# + +cdist_type="${__type##*/}" +watch_type="${cdist_type##*_}" +conf_dir="/etc/consul/conf.d" +conf_file="watch_${watch_type}_${__object_id}.json" +state="$(cat "$__object/parameter/state")" + +# Generate json config file +( +echo "{" +printf ' "watches": [{\n' +printf ' "type": "%s"\n' "$watch_type" +for param in $(ls "$__object/parameter/"); do + case "$param" in + state) continue ;; + *) + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +# end watches +echo " }]" +# end json file +echo "}" +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group consul --mode 640 \ + --state "$state" \ + --onchange 'service consul status >/dev/null && service consul reload || true' \ + --source - diff --git a/cdist/conf/type/__consul_watch_key/parameter/default/state b/cdist/conf/type/__consul_watch_key/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_watch_key/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_watch_key/parameter/optional b/cdist/conf/type/__consul_watch_key/parameter/optional new file mode 100644 index 00000000..bfce8305 --- /dev/null +++ b/cdist/conf/type/__consul_watch_key/parameter/optional @@ -0,0 +1,3 @@ +datacenter +state +token diff --git a/cdist/conf/type/__consul_watch_key/parameter/required b/cdist/conf/type/__consul_watch_key/parameter/required new file mode 100644 index 00000000..a7ae5b65 --- /dev/null +++ b/cdist/conf/type/__consul_watch_key/parameter/required @@ -0,0 +1,2 @@ +handler +key diff --git a/cdist/conf/type/__consul_watch_keyprefix/man.rst b/cdist/conf/type/__consul_watch_keyprefix/man.rst new file mode 100644 index 00000000..8ee5822d --- /dev/null +++ b/cdist/conf/type/__consul_watch_keyprefix/man.rst @@ -0,0 +1,55 @@ +cdist-type__consul_watch_keyprefix(7) +===================================== +Manages consul keyprefix watches + +Steven Armstrong + + +DESCRIPTION +----------- +Generate and deploy watch definitions of type 'keyprefix' for a consul agent. +See http://www.consul.io/docs/agent/watches.html for parameter documentation. + + +REQUIRED PARAMETERS +------------------- +handler + the handler to invoke when the data view updates + +prefix + the prefix of keys to watch for changes + + +OPTIONAL PARAMETERS +------------------- +datacenter + can be provided to override the agent's default datacenter + +state + if this watch is 'present' or 'absent'. Defaults to 'present'. + +token + can be provided to override the agent's default ACL token + + +EXAMPLES +-------- + +.. code-block:: sh + + __consul_watch_keyprefix some-id \ + --prefix foo/ \ + --handler /usr/bin/my-prefix-handler.sh + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__consul_agent(7) `_ +- http://www.consul.io/docs/agent/watches.html + + +COPYING +------- +Copyright \(C) 2015 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/__consul_watch_keyprefix/manifest b/cdist/conf/type/__consul_watch_keyprefix/manifest new file mode 100755 index 00000000..4e36a10d --- /dev/null +++ b/cdist/conf/type/__consul_watch_keyprefix/manifest @@ -0,0 +1,51 @@ +#!/bin/sh +# +# 2015 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 . +# + +cdist_type="${__type##*/}" +watch_type="${cdist_type##*_}" +conf_dir="/etc/consul/conf.d" +conf_file="watch_${watch_type}_${__object_id}.json" +state="$(cat "$__object/parameter/state")" + +# Generate json config file +( +echo "{" +printf ' "watches": [{\n' +printf ' "type": "%s"\n' "$watch_type" +for param in $(ls "$__object/parameter/"); do + case "$param" in + state) continue ;; + *) + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +# end watches +echo " }]" +# end json file +echo "}" +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group consul --mode 640 \ + --state "$state" \ + --onchange 'service consul status >/dev/null && service consul reload || true' \ + --source - diff --git a/cdist/conf/type/__consul_watch_keyprefix/parameter/default/state b/cdist/conf/type/__consul_watch_keyprefix/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_watch_keyprefix/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_watch_keyprefix/parameter/optional b/cdist/conf/type/__consul_watch_keyprefix/parameter/optional new file mode 100644 index 00000000..bfce8305 --- /dev/null +++ b/cdist/conf/type/__consul_watch_keyprefix/parameter/optional @@ -0,0 +1,3 @@ +datacenter +state +token diff --git a/cdist/conf/type/__consul_watch_keyprefix/parameter/required b/cdist/conf/type/__consul_watch_keyprefix/parameter/required new file mode 100644 index 00000000..6223b4de --- /dev/null +++ b/cdist/conf/type/__consul_watch_keyprefix/parameter/required @@ -0,0 +1,2 @@ +handler +keyprefix diff --git a/cdist/conf/type/__consul_watch_nodes/man.rst b/cdist/conf/type/__consul_watch_nodes/man.rst new file mode 100644 index 00000000..b5f0a5ce --- /dev/null +++ b/cdist/conf/type/__consul_watch_nodes/man.rst @@ -0,0 +1,51 @@ +cdist-type__consul_watch_nodes(7) +================================= +Manages consul nodes watches + +Steven Armstrong + + +DESCRIPTION +----------- +Generate and deploy watch definitions of type 'nodes' for a consul agent. +See http://www.consul.io/docs/agent/watches.html for parameter documentation. + + +REQUIRED PARAMETERS +------------------- +handler + the handler to invoke when the data view updates + + +OPTIONAL PARAMETERS +------------------- +datacenter + can be provided to override the agent's default datacenter + +state + if this watch is 'present' or 'absent'. Defaults to 'present'. + +token + can be provided to override the agent's default ACL token + + +EXAMPLES +-------- + +.. code-block:: sh + + __consul_watch_nodes some-id \ + --handler /usr/bin/my-key-handler.sh + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__consul_agent(7) `_ +- http://www.consul.io/docs/agent/watches.html + + +COPYING +------- +Copyright \(C) 2015 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/__consul_watch_nodes/manifest b/cdist/conf/type/__consul_watch_nodes/manifest new file mode 100755 index 00000000..4e36a10d --- /dev/null +++ b/cdist/conf/type/__consul_watch_nodes/manifest @@ -0,0 +1,51 @@ +#!/bin/sh +# +# 2015 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 . +# + +cdist_type="${__type##*/}" +watch_type="${cdist_type##*_}" +conf_dir="/etc/consul/conf.d" +conf_file="watch_${watch_type}_${__object_id}.json" +state="$(cat "$__object/parameter/state")" + +# Generate json config file +( +echo "{" +printf ' "watches": [{\n' +printf ' "type": "%s"\n' "$watch_type" +for param in $(ls "$__object/parameter/"); do + case "$param" in + state) continue ;; + *) + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +# end watches +echo " }]" +# end json file +echo "}" +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group consul --mode 640 \ + --state "$state" \ + --onchange 'service consul status >/dev/null && service consul reload || true' \ + --source - diff --git a/cdist/conf/type/__consul_watch_nodes/parameter/default/state b/cdist/conf/type/__consul_watch_nodes/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_watch_nodes/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_watch_nodes/parameter/optional b/cdist/conf/type/__consul_watch_nodes/parameter/optional new file mode 100644 index 00000000..bfce8305 --- /dev/null +++ b/cdist/conf/type/__consul_watch_nodes/parameter/optional @@ -0,0 +1,3 @@ +datacenter +state +token diff --git a/cdist/conf/type/__consul_watch_nodes/parameter/required b/cdist/conf/type/__consul_watch_nodes/parameter/required new file mode 100644 index 00000000..64b916c1 --- /dev/null +++ b/cdist/conf/type/__consul_watch_nodes/parameter/required @@ -0,0 +1 @@ +handler diff --git a/cdist/conf/type/__consul_watch_service/man.rst b/cdist/conf/type/__consul_watch_service/man.rst new file mode 100644 index 00000000..1cc2c00d --- /dev/null +++ b/cdist/conf/type/__consul_watch_service/man.rst @@ -0,0 +1,75 @@ +cdist-type__consul_watch_service(7) +=================================== +Manages consul service watches + +Steven Armstrong + + +DESCRIPTION +----------- +Generate and deploy watch definitions of type 'service' for a consul agent. +See http://www.consul.io/docs/agent/watches.html for parameter documentation. + + +REQUIRED PARAMETERS +------------------- +handler + the handler to invoke when the data view updates + +service + the service to watch for changes + + +OPTIONAL PARAMETERS +------------------- +datacenter + can be provided to override the agent's default datacenter + +state + if this watch is 'present' or 'absent'. Defaults to 'present'. + +token + can be provided to override the agent's default ACL token + +tag + filter by tag + + +BOOLEAN PARAMETERS +------------------ +passingonly + specifies if only hosts passing all checks are displayed + + +EXAMPLES +-------- + +.. code-block:: sh + + __consul_watch_service some-id \ + --service consul \ + --handler /usr/bin/my-handler.sh + + __consul_watch_service some-id \ + --service redis \ + --tag production \ + --handler /usr/bin/my-handler.sh + + __consul_watch_service some-id \ + --service redis \ + --tag production \ + --passingonly \ + --handler /usr/bin/my-handler.sh + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__consul_agent(7) `_ +- http://www.consul.io/docs/agent/watches.html + + +COPYING +------- +Copyright \(C) 2015 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/__consul_watch_service/manifest b/cdist/conf/type/__consul_watch_service/manifest new file mode 100755 index 00000000..6011e288 --- /dev/null +++ b/cdist/conf/type/__consul_watch_service/manifest @@ -0,0 +1,54 @@ +#!/bin/sh +# +# 2015 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 . +# + +cdist_type="${__type##*/}" +watch_type="${cdist_type##*_}" +conf_dir="/etc/consul/conf.d" +conf_file="watch_${watch_type}_${__object_id}.json" +state="$(cat "$__object/parameter/state")" + +# Generate json config file +( +echo "{" +printf ' "watches": [{\n' +printf ' "type": "%s"\n' "$watch_type" +for param in $(ls "$__object/parameter/"); do + case "$param" in + state) continue ;; + passingonly) + printf ' ,"passingonly": true\n' + ;; + *) + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +# end watches +echo " }]" +# end json file +echo "}" +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group consul --mode 640 \ + --state "$state" \ + --onchange 'service consul status >/dev/null && service consul reload || true' \ + --source - diff --git a/cdist/conf/type/__consul_watch_service/parameter/boolean b/cdist/conf/type/__consul_watch_service/parameter/boolean new file mode 100644 index 00000000..4c1e4b3f --- /dev/null +++ b/cdist/conf/type/__consul_watch_service/parameter/boolean @@ -0,0 +1 @@ +passingonly diff --git a/cdist/conf/type/__consul_watch_service/parameter/default/state b/cdist/conf/type/__consul_watch_service/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_watch_service/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_watch_service/parameter/optional b/cdist/conf/type/__consul_watch_service/parameter/optional new file mode 100644 index 00000000..a81860ac --- /dev/null +++ b/cdist/conf/type/__consul_watch_service/parameter/optional @@ -0,0 +1,4 @@ +datacenter +state +tag +token diff --git a/cdist/conf/type/__consul_watch_service/parameter/required b/cdist/conf/type/__consul_watch_service/parameter/required new file mode 100644 index 00000000..e1ffa4d6 --- /dev/null +++ b/cdist/conf/type/__consul_watch_service/parameter/required @@ -0,0 +1,2 @@ +handler +service diff --git a/cdist/conf/type/__consul_watch_services/man.rst b/cdist/conf/type/__consul_watch_services/man.rst new file mode 100644 index 00000000..bf766222 --- /dev/null +++ b/cdist/conf/type/__consul_watch_services/man.rst @@ -0,0 +1,51 @@ +cdist-type__consul_watch_services(7) +==================================== +Manages consul services watches + +Steven Armstrong + + +DESCRIPTION +----------- +Generate and deploy watch definitions of type 'services' for a consul agent. +See http://www.consul.io/docs/agent/watches.html for parameter documentation. + + +REQUIRED PARAMETERS +------------------- +handler + the handler to invoke when the data view updates + + +OPTIONAL PARAMETERS +------------------- +datacenter + can be provided to override the agent's default datacenter + +state + if this watch is 'present' or 'absent'. Defaults to 'present'. + +token + can be provided to override the agent's default ACL token + + +EXAMPLES +-------- + +.. code-block:: sh + + __consul_watch_services some-id \ + --handler /usr/bin/my-key-handler.sh + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__consul_agent(7) `_ +- http://www.consul.io/docs/agent/watches.html + + +COPYING +------- +Copyright \(C) 2015 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/__consul_watch_services/manifest b/cdist/conf/type/__consul_watch_services/manifest new file mode 100755 index 00000000..4e36a10d --- /dev/null +++ b/cdist/conf/type/__consul_watch_services/manifest @@ -0,0 +1,51 @@ +#!/bin/sh +# +# 2015 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 . +# + +cdist_type="${__type##*/}" +watch_type="${cdist_type##*_}" +conf_dir="/etc/consul/conf.d" +conf_file="watch_${watch_type}_${__object_id}.json" +state="$(cat "$__object/parameter/state")" + +# Generate json config file +( +echo "{" +printf ' "watches": [{\n' +printf ' "type": "%s"\n' "$watch_type" +for param in $(ls "$__object/parameter/"); do + case "$param" in + state) continue ;; + *) + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +# end watches +echo " }]" +# end json file +echo "}" +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group consul --mode 640 \ + --state "$state" \ + --onchange 'service consul status >/dev/null && service consul reload || true' \ + --source - diff --git a/cdist/conf/type/__consul_watch_services/parameter/default/state b/cdist/conf/type/__consul_watch_services/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_watch_services/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_watch_services/parameter/optional b/cdist/conf/type/__consul_watch_services/parameter/optional new file mode 100644 index 00000000..bfce8305 --- /dev/null +++ b/cdist/conf/type/__consul_watch_services/parameter/optional @@ -0,0 +1,3 @@ +datacenter +state +token diff --git a/cdist/conf/type/__consul_watch_services/parameter/required b/cdist/conf/type/__consul_watch_services/parameter/required new file mode 100644 index 00000000..64b916c1 --- /dev/null +++ b/cdist/conf/type/__consul_watch_services/parameter/required @@ -0,0 +1 @@ +handler diff --git a/cdist/conf/type/__cron/man.text b/cdist/conf/type/__cron/man.rst similarity index 58% rename from cdist/conf/type/__cron/man.text rename to cdist/conf/type/__cron/man.rst index f4e80a08..353f6bae 100644 --- a/cdist/conf/type/__cron/man.text +++ b/cdist/conf/type/__cron/man.rst @@ -1,13 +1,10 @@ cdist-type__cron(7) =================== +Installs and manages cron jobs + Steven Armstrong -NAME ----- -cdist-type__cron - installs and manages cron jobs - - DESCRIPTION ----------- This cdist type allows you to manage entries in a users crontab. @@ -15,34 +12,34 @@ This cdist type allows you to manage entries in a users crontab. REQUIRED PARAMETERS ------------------- -user:: +user The user who's crontab is edited -command:: +command The command to run. OPTIONAL PARAMETERS ------------------- -state:: +state Either present or absent. Defaults to present. -minute:: +minute See crontab(5). Defaults to * -hour:: +hour See crontab(5). Defaults to * -day_of_month:: +day_of_month See crontab(5). Defaults to * -month:: +month See crontab(5). Defaults to * -day_of_week:: +day_of_week See crontab(5). Defaults to * -raw:: +raw Take whatever the user has given instead of time and date fields. If given, all other time and date fields are ignored. Can for example be used to specify cron EXTENSIONS like reboot, yearly etc. See crontab(5) for the extensions if any that your cron implementation implements. -raw_command:: - Take whatever the user has given in the commmand and ignore everything else. +raw_command + Take whatever the user has given in the command and ignore everything else. If given, the command will be added to crontab. Can for example be used to define variables like SHELL or MAILTO. @@ -50,27 +47,27 @@ raw_command:: EXAMPLES -------- --------------------------------------------------------------------------------- -# run Monday to Saturday at 23:15 -__cron some-id --user root --command "/path/to/script" \ - --hour 23 --minute 15 --day_of_week 1-6 +.. code-block:: sh -# run on reboot -__cron some-id --user root --command "/path/to/script" \ - --raw @reboot + # run Monday to Saturday at 23:15 + __cron some-id --user root --command "/path/to/script" \ + --hour 23 --minute 15 --day_of_week 1-6 -# remove cronjob -__cron some-id --user root --command "/path/to/script" --state absent + # run on reboot + __cron some-id --user root --command "/path/to/script" \ + --raw @reboot -# define default shell -__cron some-id --user root --raw_command --command "SHELL=/bin/bash" \ - --state present --------------------------------------------------------------------------------- + # remove cronjob + __cron some-id --user root --command "/path/to/script" --state absent + + # define default shell + __cron some-id --user root --raw_command --command "SHELL=/bin/bash" \ + --state present SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ - crontab(5) diff --git a/cdist/conf/type/__debconf_set_selections/man.text b/cdist/conf/type/__debconf_set_selections/man.rst similarity index 52% rename from cdist/conf/type/__debconf_set_selections/man.text rename to cdist/conf/type/__debconf_set_selections/man.rst index e36ebaa3..37aa65b9 100644 --- a/cdist/conf/type/__debconf_set_selections/man.text +++ b/cdist/conf/type/__debconf_set_selections/man.rst @@ -1,13 +1,10 @@ cdist-type__debconf_set_selections(7) ===================================== +Setup debconf selections + Nico Schottelius -NAME ----- -cdist-type__debconf_set_selections - Setup debconf selections - - DESCRIPTION ----------- On Debian and alike systems debconf-set-selections(1) can be used @@ -16,7 +13,7 @@ to setup configuration parameters. REQUIRED PARAMETERS ------------------- -file:: +file Use the given filename as input for debconf-set-selections(1) If filename is "-", read from stdin. @@ -24,23 +21,23 @@ file:: EXAMPLES -------- --------------------------------------------------------------------------------- -# Setup configuration for nslcd -__debconf_set_selections nslcd --file /path/to/file +.. code-block:: sh -# Setup configuration for nslcd from another type -__debconf_set_selections nslcd --file "$__type/files/preseed/nslcd" + # Setup configuration for nslcd + __debconf_set_selections nslcd --file /path/to/file -__debconf_set_selections nslcd --file - << eof -gitolite gitolite/gituser string git -eof --------------------------------------------------------------------------------- + # Setup configuration for nslcd from another type + __debconf_set_selections nslcd --file "$__type/files/preseed/nslcd" + + __debconf_set_selections nslcd --file - << eof + gitolite gitolite/gituser string git + eof SEE ALSO -------- -- cdist-type(7) -- cdist-type__update_alternatives(7) +- `cdist-type(7) `_ +- `cdist-type__update_alternatives(7) `_ - debconf-set-selections(1) diff --git a/cdist/conf/type/__directory/explorer/stat b/cdist/conf/type/__directory/explorer/stat index d8cdbb9e..41bc8b04 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"|"netbsd"|"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/__directory/man.text b/cdist/conf/type/__directory/man.rst similarity index 53% rename from cdist/conf/type/__directory/man.text rename to cdist/conf/type/__directory/man.rst index a0bf8062..279763a1 100644 --- a/cdist/conf/type/__directory/man.text +++ b/cdist/conf/type/__directory/man.rst @@ -1,13 +1,10 @@ cdist-type__directory(7) ======================== +Manage a directory + Nico Schottelius -NAME ----- -cdist-type__directory - Manage a directory - - DESCRIPTION ----------- This cdist type allows you to create or remove directories on the target. @@ -20,80 +17,79 @@ None. OPTIONAL PARAMETERS ------------------- -state:: +state 'present' or 'absent', defaults to 'present' -group:: +group Group to chgrp to. -mode:: +mode Unix permissions, suitable for chmod. -owner:: +owner User to chown to. BOOLEAN PARAMETERS ------------------ -parents:: +parents Whether to create parents as well (mkdir -p behaviour). Warning: all intermediate directory permissions default to whatever mkdir -p does. Usually this means root:root, 0700. -recursive:: +recursive If supplied the chgrp and chown call will run recursively. This does *not* influence the behaviour of chmod. MESSAGES -------- -chgrp :: +chgrp Changed group membership -chown :: +chown Changed owner -chmod :: +chmod Changed mode -create:: +create Empty directory was created -remove:: +remove Directory exists, but state is absent, directory will be removed by generated code. -remove non directory:: - Someting other than a directory with the same name exists and was removed prior to create. +remove non directory + Something other than a directory with the same name exists and was removed prior to create. EXAMPLES -------- --------------------------------------------------------------------------------- -# A silly example -__directory /tmp/foobar +.. code-block:: sh -# Remove a directory -__directory /tmp/foobar --state absent + # A silly example + __directory /tmp/foobar -# Ensure /etc exists correctly -__directory /etc --owner root --group root --mode 0755 + # Remove a directory + __directory /tmp/foobar --state absent -# Create nfs service directory, including parents -__directory /home/services/nfs --parents + # Ensure /etc exists correctly + __directory /etc --owner root --group root --mode 0755 -# Change permissions recursively -__directory /home/services --recursive --owner root --group root + # Create nfs service directory, including parents + __directory /home/services/nfs --parents -# Setup a temp directory -__directory /local --mode 1777 + # Change permissions recursively + __directory /home/services --recursive --owner root --group root -# Take it all -__directory /home/services/kvm --recursive --parents \ - --owner root --group root --mode 0755 --state present + # Setup a temp directory + __directory /local --mode 1777 --------------------------------------------------------------------------------- + # Take it all + __directory /home/services/kvm --recursive --parents \ + --owner root --group root --mode 0755 --state present SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__dog_vdi/man.text b/cdist/conf/type/__dog_vdi/man.rst similarity index 50% rename from cdist/conf/type/__dog_vdi/man.text rename to cdist/conf/type/__dog_vdi/man.rst index e3453ba7..3e6155a6 100644 --- a/cdist/conf/type/__dog_vdi/man.text +++ b/cdist/conf/type/__dog_vdi/man.rst @@ -1,13 +1,10 @@ cdist-type__dog_vdi(7) ====================== +Manage Sheepdog VM images + Nico Schottelius -NAME ----- -cdist-type__dog_vdi - Manage Sheepdog VM images - - DESCRIPTION ----------- The dog program is used to create images for sheepdog @@ -16,9 +13,9 @@ to be used in qemu. OPTIONAL PARAMETERS ------------------- -state:: +state Either "present" or "absent", defaults to "present" -size:: +size Size of the image in "dog vdi" compatible units. Required if state is "present". @@ -28,24 +25,24 @@ size:: EXAMPLES -------- --------------------------------------------------------------------------------- -# Create a 50G size image -__dog_vdi nico-privat.sky.ungleich.ch --size 50G +.. code-block:: sh -# Create a 50G size image (more explicit) -__dog_vdi nico-privat.sky.ungleich.ch --size 50G --state present + # Create a 50G size image + __dog_vdi nico-privat.sky.ungleich.ch --size 50G -# Remove image -__dog_vdi nico-privat.sky.ungleich.ch --state absent + # Create a 50G size image (more explicit) + __dog_vdi nico-privat.sky.ungleich.ch --size 50G --state present -# Remove image - keeping --size is ok -__dog_vdi nico-privat.sky.ungleich.ch --size 50G --state absent --------------------------------------------------------------------------------- + # 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) +- `cdist-type(7) `_ - dog(8) - qemu(1) diff --git a/cdist/conf/type/__file/explorer/stat b/cdist/conf/type/__file/explorer/stat index 52570379..8a917556 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"|"openbsd") + "freebsd"|"netbsd"|"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/__file/gencode-local b/cdist/conf/type/__file/gencode-local index 601705c8..ed7482cb 100755 --- a/cdist/conf/type/__file/gencode-local +++ b/cdist/conf/type/__file/gencode-local @@ -67,7 +67,7 @@ DONE if [ "$upload_file" ]; then echo upload >> "$__messages_out" cat << DONE -$__remote_copy $source ${__target_host}:\$destination_upload +$__remote_copy "$source" "${__target_host}:\$destination_upload" DONE fi # move uploaded file into place diff --git a/cdist/conf/type/__file/man.rst b/cdist/conf/type/__file/man.rst new file mode 100644 index 00000000..73336581 --- /dev/null +++ b/cdist/conf/type/__file/man.rst @@ -0,0 +1,109 @@ +cdist-type__file(7) +=================== +Manage files. + +Nico Schottelius + + +DESCRIPTION +----------- +This cdist type allows you to create files, remove files and set file +attributes on the target. + +If the file already exists on the target, then if it is a: + +regular file, and state is: + present + replace it with the source file if they are not equal + exists + do nothing +symlink + replace it with the source file +directory + replace it with the source file + +In any case, make sure that the file attributes are as specified. + + +REQUIRED PARAMETERS +------------------- +None. + +OPTIONAL PARAMETERS +------------------- +state + 'present', 'absent' or 'exists', defaults to 'present' where: + + present + the file is exactly the one from source + absent + the file does not exist + exists + the file from source but only if it doesn't already exist + +group + Group to chgrp to. + +mode + Unix permissions, suitable for chmod. + +owner + User to chown to. + +source + If supplied, copy this file from the host running cdist to the target. + If not supplied, an empty file or directory will be created. + If source is '-' (dash), take what was written to stdin as the file content. + +MESSAGES +-------- +chgrp + Changed group membership +chown + Changed owner +chmod + Changed mode +create + Empty file was created (no --source specified) +remove + File exists, but state is absent, file will be removed by generated code. +upload + File was uploaded + + +EXAMPLES +-------- + +.. code-block:: sh + + # Create /etc/cdist-configured as an empty file + __file /etc/cdist-configured + # The same thing + __file /etc/cdist-configured --state present + # Use __file from another type + __file /etc/issue --source "$__type/files/archlinux" --state present + # Delete existing file + __file /etc/cdist-configured --state absent + # Supply some more settings + __file /etc/shadow --source "$__type/files/shadow" \ + --owner root --group shadow --mode 0640 \ + --state present + # Provide a default file, but let the user change it + __file /home/frodo/.bashrc --source "/etc/skel/.bashrc" \ + --state exists \ + --owner frodo --mode 0600 + # Take file content from stdin + __file /tmp/whatever --owner root --group root --mode 644 --source - << DONE + Here goes the content for /tmp/whatever + DONE + + +SEE ALSO +-------- +* `cdist-type(7) `_ + + +COPYING +------- +Copyright \(C) 2011-2013 Nico Schottelius. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__file/man.text b/cdist/conf/type/__file/man.text deleted file mode 100644 index a582b27b..00000000 --- a/cdist/conf/type/__file/man.text +++ /dev/null @@ -1,109 +0,0 @@ -cdist-type__file(7) -=================== -Nico Schottelius - - -NAME ----- -cdist-type__file - Manage files - - -DESCRIPTION ------------ -This cdist type allows you to create files, remove files and set file -attributes on the target. - -If the file already exists on the target, then if it is a: -- regular file, and state is: - present: replace it with the source file if they are not equal - exists: do nothing -- symlink: replace it with the source file -- directory: replace it with the source file - -In any case, make sure that the file attributes are as specified. - - -REQUIRED PARAMETERS -------------------- -None. - -OPTIONAL PARAMETERS -------------------- -state:: - 'present', 'absent' or 'exists', defaults to 'present' - where: - present: the file is exactly the one from source - absent: the file does not exist - exists: the file from source but only if it doesn't already exist - -group:: - Group to chgrp to. - -mode:: - Unix permissions, suitable for chmod. - -owner:: - User to chown to. - -source:: - If supplied, copy this file from the host running cdist to the target. - If not supplied, an empty file or directory will be created. - If source is '-' (dash), take what was written to stdin as the file content. - -MESSAGES --------- -chgrp :: - Changed group membership -chown :: - Changed owner -chmod :: - Changed mode -create:: - Empty file was created (no --source specified) -remove:: - File exists, but state is absent, file will be removed by generated code. -upload:: - File was uploaded - - -EXAMPLES --------- - --------------------------------------------------------------------------------- -# Create /etc/cdist-configured as an empty file -__file /etc/cdist-configured -# The same thing -__file /etc/cdist-configured --state present -# Delete existing file -__file /etc/cdist-configured --state absent - -# Use __file from another type -__file /etc/issue --source "$__type/files/archlinux" --state present - -# Supply some more settings -__file /etc/shadow --source "$__type/files/shadow" \ - --owner root --group shadow --mode 0640 \ - --state present - -# Provide a default file, but let the user change it -__file /home/frodo/.bashrc --source "/etc/skel/.bashrc" \ - --state exists \ - --owner frodo --mode 0600 - -# Take file content from stdin -__file /tmp/whatever --owner root --group root --mode 644 --source - << DONE -Here goes the content for /tmp/whatever -DONE - --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) - - -COPYING -------- -Copyright \(C) 2011-2013 Nico Schottelius. Free use of this software is -granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__firewalld_rule/explorer/rule b/cdist/conf/type/__firewalld_rule/explorer/rule new file mode 100644 index 00000000..5a0e0265 --- /dev/null +++ b/cdist/conf/type/__firewalld_rule/explorer/rule @@ -0,0 +1,32 @@ +#!/bin/sh +# +# 2015 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 . +# +# + +protocol="$(cat "$__object/parameter/protocol")" +table="$(cat "$__object/parameter/table")" +chain="$(cat "$__object/parameter/chain")" +priority="$(cat "$__object/parameter/priority")" +rule="$(cat "$__object/parameter/rule")" + +if firewall-cmd --permanent --direct --query-rule "$protocol" "$table" "$chain" "$priority" $rule >/dev/null; then + echo present +else + echo absent +fi diff --git a/cdist/conf/type/__firewalld_rule/gencode-remote b/cdist/conf/type/__firewalld_rule/gencode-remote new file mode 100644 index 00000000..8f1ba28a --- /dev/null +++ b/cdist/conf/type/__firewalld_rule/gencode-remote @@ -0,0 +1,48 @@ +#!/bin/sh +# +# 2015 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" +state_should="$(cat "$__object/parameter/state")" +state_is="$(cat "$__object/explorer/rule")" + +[ "$state_is" = "$state_should" ] && exit 0 + +protocol="$(cat "$__object/parameter/protocol")" +table="$(cat "$__object/parameter/table")" +chain="$(cat "$__object/parameter/chain")" +priority="$(cat "$__object/parameter/priority")" +rule="$(cat "$__object/parameter/rule")" + +case "$state_should" in + present) + echo firewall-cmd --quiet --permanent --direct --add-rule \"$protocol\" \"$table\" \"$chain\" \"$priority\" $rule + echo firewall-cmd --quiet --direct --add-rule \"$protocol\" \"$table\" \"$chain\" \"$priority\" $rule + ;; + + absent) + echo firewall-cmd --quiet --permanent --direct --remove-rule \"$protocol\" \"$table\" \"$chain\" \"$priority\" $rule + echo firewall-cmd --quiet --direct --remove-rule \"$protocol\" \"$table\" \"$chain\" \"$priority\" $rule + ;; + *) + echo "Unknown state $state_should" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__firewalld_rule/man.rst b/cdist/conf/type/__firewalld_rule/man.rst new file mode 100644 index 00000000..d953b3d2 --- /dev/null +++ b/cdist/conf/type/__firewalld_rule/man.rst @@ -0,0 +1,75 @@ +cdist-type__firewalld_rule(7) +============================= +Configure firewalld rules + +Nico Schottelius + + +DESCRIPTION +----------- +This cdist type allows you to manage rules in firewalld +using the *direct* way (i.e. no zone support). + + +REQUIRED PARAMETERS +------------------- +rule + The rule to apply. Essentially an firewalld command + line without firewalld in front of it. +protocol + Either ipv4, ipv4 or eb. See firewall-cmd(1) +table + The table to use (like filter or nat). See firewall-cmd(1). +chain + The chain to use (like INPUT_direct or FORWARD_direct). See firewall-cmd(1). +priority + The priority to use (0 is topmost). See firewall-cmd(1). + + +OPTIONAL PARAMETERS +------------------- +state + 'present' or 'absent', defaults to 'present' + + +EXAMPLES +-------- + +.. code-block:: sh + + # Allow acces from entrance.place4.ungleich.ch + __firewalld_rule entrance \ + --protocol ipv4 \ + --table filter \ + --chain INPUT_direct \ + --priority 0 \ + --rule '-s entrance.place4.ungleich.ch -j ACCEPT' + + # Allow forwarding of traffic from br0 + __firewalld_rule vm-forward --protocol ipv4 \ + --table filter \ + --chain FORWARD_direct \ + --priority 0 \ + --rule '-i br0 -j ACCEPT' + + # Ensure old rule is absent - warning, the rule part must stay the same! + __firewalld_rule vm-forward + --protocol ipv4 \ + --table filter \ + --chain FORWARD_direct \ + --priority 0 \ + --rule '-i br0 -j ACCEPT' \ + --state absent + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__iptables_rule(7) `_ +- firewalld(8) + + +COPYING +------- +Copyright \(C) 2015 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/__firewalld_rule/manifest b/cdist/conf/type/__firewalld_rule/manifest new file mode 100644 index 00000000..5baf6da3 --- /dev/null +++ b/cdist/conf/type/__firewalld_rule/manifest @@ -0,0 +1,23 @@ +#!/bin/sh +# +# 2015 David Hürlimann (david at ungleich.ch) +# +# 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 . +# +# +# This type allows to configure the desired localtime timezone. + +__package firewalld diff --git a/cdist/conf/type/__firewalld_rule/parameter/default/state b/cdist/conf/type/__firewalld_rule/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__firewalld_rule/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__firewalld_rule/parameter/optional b/cdist/conf/type/__firewalld_rule/parameter/optional new file mode 100644 index 00000000..ff72b5c7 --- /dev/null +++ b/cdist/conf/type/__firewalld_rule/parameter/optional @@ -0,0 +1 @@ +state diff --git a/cdist/conf/type/__firewalld_rule/parameter/required b/cdist/conf/type/__firewalld_rule/parameter/required new file mode 100644 index 00000000..58def7e4 --- /dev/null +++ b/cdist/conf/type/__firewalld_rule/parameter/required @@ -0,0 +1,5 @@ +chain +priority +protocol +rule +table diff --git a/cdist/conf/type/__git/man.text b/cdist/conf/type/__git/man.rst similarity index 60% rename from cdist/conf/type/__git/man.text rename to cdist/conf/type/__git/man.rst index 5f74108b..75f6e48b 100644 --- a/cdist/conf/type/__git/man.text +++ b/cdist/conf/type/__git/man.rst @@ -1,13 +1,10 @@ cdist-type__git(7) ================== +Get and or keep git repositories up-to-date + Nico Schottelius -NAME ----- -cdist-type__git - Get and or keep git repositories up-to-date - - DESCRIPTION ----------- This cdist type allows you to clone git repositories @@ -15,43 +12,43 @@ This cdist type allows you to clone git repositories REQUIRED PARAMETERS ------------------- -source:: +source Specifies the git remote to clone from OPTIONAL PARAMETERS ------------------- -state:: +state Either "present" or "absent", defaults to "present" -branch:: +branch Create this branch by checking out the remote branch of this name Default branch is "master" -group:: +group Group to chgrp to. -mode:: +mode Unix permissions, suitable for chmod. -owner:: +owner User to chown to. EXAMPLES -------- --------------------------------------------------------------------------------- -__git /home/services/dokuwiki --source git://github.com/splitbrain/dokuwiki.git +.. code-block:: sh -# Checkout cdist, stay on branch 2.1 -__git /home/nico/cdist --source git://github.com/telmich/cdist.git --branch 2.1 --------------------------------------------------------------------------------- + __git /home/services/dokuwiki --source git://github.com/splitbrain/dokuwiki.git + + # Checkout cdist, stay on branch 2.1 + __git /home/nico/cdist --source git://github.com/telmich/cdist.git --branch 2.1 SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__group/TODO b/cdist/conf/type/__group/TODO deleted file mode 100644 index c20a5d21..00000000 --- a/cdist/conf/type/__group/TODO +++ /dev/null @@ -1,2 +0,0 @@ -- delete groups - diff --git a/cdist/conf/type/__group/explorer/group b/cdist/conf/type/__group/explorer/group index 4c1e6ac0..07f73a91 100755 --- a/cdist/conf/type/__group/explorer/group +++ b/cdist/conf/type/__group/explorer/group @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011-2015 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # diff --git a/cdist/conf/type/__group/explorer/gshadow b/cdist/conf/type/__group/explorer/gshadow index 5ab4ed80..2e2ab29d 100755 --- a/cdist/conf/type/__group/explorer/gshadow +++ b/cdist/conf/type/__group/explorer/gshadow @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011-2015 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -22,21 +22,13 @@ # name=$__object_id -os_version="$($__explorer/os_version)" os="$($__explorer/os)" -if [ "$os" = "freebsd" ]; then - echo "FreeBSD does not have getent gshadow" - exit 0 -fi - -case "$os_version" in - "Red Hat Enterprise Linux Server release "[45]*|"CentOS release "[45]*) - # TODO: find a way to get this information - echo "$os_version does not have getent gshadow" - ;; - *) - getent gshadow "$name" || true - ;; +case "$os" in + "freebsd"|"netbsd") + echo "$os does not have getent gshadow" + exit 0 + ;; esac +getent gshadow "$name" || true diff --git a/cdist/conf/type/__group/gencode-remote b/cdist/conf/type/__group/gencode-remote index 1cffa8d4..2aaa83f3 100755 --- a/cdist/conf/type/__group/gencode-remote +++ b/cdist/conf/type/__group/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011-2015 Steven Armstrong (steven-cdist at armstrong.cc) # 2011 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. @@ -23,91 +23,86 @@ # name="$__object_id" -os_version="$(cat "$__global/explorer/os_version")" os="$(cat "$__global/explorer/os")" +state="$(cat "$__object/parameter/state")" -cd "$__object/parameter" -if grep -q "^${name}:" "$__object/explorer/group"; then - for property in $(ls .); do - new_value="$(cat "$property")" - # argument to pass the groupmod command for this property (exceptions - # are made in the case statement below) - proparg="--$property" - case "$property" in - password) - if [ "$os" = "freebsd" ]; then - echo "group/$name: FreeBSD doesn't support password modification" >&2 - exit 1 - fi - case "$os_version" in - "Red Hat Enterprise Linux Server release "[45]*|"CentOS release "[45]*) - # TODO: Use gpasswd? Need to fix gshadow explorer first. - echo "group/$name: '$os_version' groupmod does not support password modification" >&2 - exit 1 +# Use short option names for portability +shorten_property() { + case "$1" in + gid) echo "-g";; + password) echo "-p";; + system) echo "-r";; + esac +} + + +if [ "$state" = "present" ]; then + case "$os" in + freebsd) + supported_add_properties="gid" + supported_change_properties="gid" + ;; + *) + supported_add_properties="gid password system" + supported_change_properties="gid password" + ;; + esac + if grep -q "^${name}:" "$__object/explorer/group"; then + # change existing + for property in $supported_change_properties; do + if [ -f "$__object/parameter/$property" ]; then + new_value="$(cat "$__object/parameter/$property")" + unset current_value + case "$property" in + password) + current_value="$(awk -F: '{ print $2 }' "$__object/explorer/gshadow")" + ;; + gid) + current_value="$(awk -F: '{ print $3 }' "$__object/explorer/group")" ;; esac - current_value="$(awk -F: '{ print $2 }' < "$__object/explorer/gshadow")" - ;; - gid) - # set to -g to support older redhat/centos - proparg="-g" - current_value="$(awk -F: '{ print $3 }' < "$__object/explorer/group")" - ;; - esac - - if [ "$new_value" != "$current_value" ]; then - set -- "$@" "$proparg" \"$new_value\" - echo change $property $new_value $current_value >> "$__messages_out" - fi - done - - if [ $# -gt 0 ]; then - echo mod >> "$__messages_out" - case $os in - freebsd) - echo pw group mod "$@" "$name" - ;; - *) + if [ "$new_value" != "$current_value" ]; then + set -- "$@" "$(shorten_property $property)" \'$new_value\' + echo change $property $new_value $current_value >> "$__messages_out" + fi + fi + done + if [ $# -gt 0 ]; then + if [ "$os" = "freebsd" ]; then + echo pw groupmod "$@" "$name" + else echo groupmod "$@" "$name" - ;; - esac + fi + echo mod >> "$__messages_out" + fi + else + # create new + for property in $supported_change_properties; do + if [ -f "$__object/parameter/$property" ]; then + new_value="$(cat "$__object/parameter/$property")" + if [ -z "$new_value" ]; then + # Boolean parameters have no value + set -- "$@" "$(shorten_property $property)" + else + set -- "$@" "$(shorten_property $property)" \'$new_value\' + fi + fi + done + if [ "$os" = "freebsd" ]; then + echo pw groupadd "$@" "$name" + else + echo groupadd "$@" "$name" + fi fi else - echo add >> "$__messages_out" - for property in $(ls .); do - new_value="$(cat "$property")" + # delete existing + if grep -q "^${name}:" "$__object/explorer/group"; then if [ "$os" = "freebsd" ]; then - case $property in - gid) - proparg="-g" - ;; - password) - echo "group/$name: FreeBSD doesn't support password setting" >&2 - exit 1 - ;; - *) - # The type has been updated to support more properties than it knows how to handle for FreeBSD - # tell the user about this. - echo "Currently unknown property: $property" >&2 - exit 1 - ;; - esac + echo pw groupdel "$name" else - proparg="--$property" + echo groupdel "$name" fi - - set -- "$@" "$proparg" \"$new_value\" - echo set $property $new_value >> "$__messages_out" - done - - case $os in - freebsd) - echo pw group add "$@" "$name" - ;; - *) - echo groupadd "$@" "$name" - ;; - esac + echo remove >> "$__messages_out" + fi fi - diff --git a/cdist/conf/type/__group/man.rst b/cdist/conf/type/__group/man.rst new file mode 100644 index 00000000..912dd226 --- /dev/null +++ b/cdist/conf/type/__group/man.rst @@ -0,0 +1,77 @@ +cdist-type__group(7) +==================== +Manage groups + +Steven Armstrong + + +DESCRIPTION +----------- +This cdist type allows you to create or modify groups on the target. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +state + absent or present, defaults to present +gid + see groupmod(8) +password + see above + + +BOOLEAN PARAMETERS +------------------ +system + see groupadd(8), apply only on group creation + + +MESSAGES +-------- +mod + group is modified +add + New group added +remove + group is removed +change + Changed group property from current_value to new_value +set + set property to new value, property was not set before + + +EXAMPLES +-------- + +.. code-block:: sh + + # Create a group 'foobar' with operating system default settings + __group foobar + + # Remove the 'foobar' group + __group foobar --state absent + + # Create a system group 'myservice' with operating system default settings + __group myservice --system + + # Same but with a specific gid + __group foobar --gid 1234 + + # Same but with a gid and password + __group foobar --gid 1234 --password 'crypted-password-string' + + +SEE ALSO +-------- +- `cdist-type(7) `_ + + +COPYING +------- +Copyright \(C) 2011-2015 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/__group/man.text b/cdist/conf/type/__group/man.text deleted file mode 100644 index def0232f..00000000 --- a/cdist/conf/type/__group/man.text +++ /dev/null @@ -1,64 +0,0 @@ -cdist-type__group(7) -==================== -Steven Armstrong - - -NAME ----- -cdist-type__group - Manage groups - - -DESCRIPTION ------------ -This cdist type allows you to create or modify groups on the target. - - -REQUIRED PARAMETERS -------------------- -None. - - -OPTIONAL PARAMETERS -------------------- -gid:: - see groupmod(8) -password:: - see above - - -MESSAGES --------- -mod:: - group is modified -add:: - New group added -change :: - Changed group property from current_value to new_value -set :: - set property to new value, property was not set bevore - - -EXAMPLES --------- - --------------------------------------------------------------------------------- -# Create a group 'foobar' with operating system default settings -__group foobar - -# Same but with a specific gid -__group foobar --gid 1234 - -# Same but with a gid and password -__group foobar --gid 1234 --password 'crypted-password-string' --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) - - -COPYING -------- -Copyright \(C) 2011 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/__group/parameter/boolean b/cdist/conf/type/__group/parameter/boolean new file mode 100644 index 00000000..bec3a35e --- /dev/null +++ b/cdist/conf/type/__group/parameter/boolean @@ -0,0 +1 @@ +system diff --git a/cdist/conf/type/__group/parameter/default/state b/cdist/conf/type/__group/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__group/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__group/parameter/optional b/cdist/conf/type/__group/parameter/optional index 4c661c8f..dd51c173 100644 --- a/cdist/conf/type/__group/parameter/optional +++ b/cdist/conf/type/__group/parameter/optional @@ -1,2 +1,3 @@ gid password +state 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..9fac7bf4 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|devuan) + 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|devuan) + 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/man.text b/cdist/conf/type/__hostname/man.rst similarity index 63% rename from cdist/conf/type/__hostname/man.text rename to cdist/conf/type/__hostname/man.rst index ac44d426..32d452f7 100644 --- a/cdist/conf/type/__hostname/man.text +++ b/cdist/conf/type/__hostname/man.rst @@ -1,13 +1,10 @@ cdist-type__hostname(7) ======================= +Set the hostname + Steven Armstrong -NAME ----- -cdist-type__hostname - set the hostname - - DESCRIPTION ----------- Set's the hostname on various operating systems. @@ -19,31 +16,31 @@ None. OPTIONAL PARAMETERS ------------------- -name:: +name The hostname to set. Defaults to the first segment of __target_host (${__target_host%%.*}) MESSAGES -------- -changed:: +changed Changed the hostname EXAMPLES -------- --------------------------------------------------------------------------------- -# take hostname from __target_host -__hostname +.. code-block:: sh -# set hostname explicitly -__hostname --name some-static-hostname --------------------------------------------------------------------------------- + # take hostname from __target_host + __hostname + + # set hostname explicitly + __hostname --name some-static-hostname SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__hostname/manifest b/cdist/conf/type/__hostname/manifest index 0544a6f9..76f962e0 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|devuan) + # 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_apply/files/init-script b/cdist/conf/type/__iptables_apply/files/init-script index 2dc952e9..2247dcf5 100644 --- a/cdist/conf/type/__iptables_apply/files/init-script +++ b/cdist/conf/type/__iptables_apply/files/init-script @@ -45,4 +45,14 @@ case $1 in restart) "$0" stop && "$0" start ;; + reset) + for table in INPUT FORWARD OUTPUT; do + iptables -P "$table" ACCEPT + iptables -F "$table" + done + for table in PREROUTING POSTROUTING OUTPUT; do + iptables -t nat -P "$table" ACCEPT + iptables -t nat -F "$table" + done + ;; esac diff --git a/cdist/conf/type/__iptables_apply/gencode-remote b/cdist/conf/type/__iptables_apply/gencode-remote index 9cdf28cf..c15d4d7f 100644 --- a/cdist/conf/type/__iptables_apply/gencode-remote +++ b/cdist/conf/type/__iptables_apply/gencode-remote @@ -1,3 +1,5 @@ +#!/bin/sh + if grep -q "^__file/etc/iptables.d/" "$__messages_in"; then echo /etc/init.d/iptables restart fi diff --git a/cdist/conf/type/__iptables_apply/man.text b/cdist/conf/type/__iptables_apply/man.rst similarity index 83% rename from cdist/conf/type/__iptables_apply/man.text rename to cdist/conf/type/__iptables_apply/man.rst index 87f4b4ee..40605351 100644 --- a/cdist/conf/type/__iptables_apply/man.text +++ b/cdist/conf/type/__iptables_apply/man.rst @@ -1,13 +1,10 @@ cdist-type__iptables_apply(7) ============================= +Apply the rules + Nico Schottelius -NAME ----- -cdist-type__iptables_apply - Apply the rules - - DESCRIPTION ----------- This cdist type deploys an init script that triggers @@ -31,8 +28,8 @@ None (__iptables_apply is used by __iptables_rule) SEE ALSO -------- -- cdist-type(7) -- cdist-type__iptables_rule(7) +- `cdist-type(7) `_ +- `cdist-type__iptables_rule(7) `_ - iptables(8) diff --git a/cdist/conf/type/__iptables_apply/manifest b/cdist/conf/type/__iptables_apply/manifest index a22901ba..3bb2d976 100644 --- a/cdist/conf/type/__iptables_apply/manifest +++ b/cdist/conf/type/__iptables_apply/manifest @@ -1,3 +1,4 @@ +#!/bin/sh # # 2013 Nico Schottelius (nico-cdist at schottelius.org) # diff --git a/cdist/conf/type/__iptables_rule/man.rst b/cdist/conf/type/__iptables_rule/man.rst new file mode 100644 index 00000000..5ee02f9c --- /dev/null +++ b/cdist/conf/type/__iptables_rule/man.rst @@ -0,0 +1,60 @@ +cdist-type__iptables_rule(7) +============================ +Deploy iptable rulesets + +Nico Schottelius + + +DESCRIPTION +----------- +This cdist type allows you to manage iptable rules +in a distribution independent manner. + + +REQUIRED PARAMETERS +------------------- +rule + The rule to apply. Essentially an iptables command + line without iptables in front of it. + + +OPTIONAL PARAMETERS +------------------- +state + 'present' or 'absent', defaults to 'present' + + +EXAMPLES +-------- + +.. code-block:: sh + + # Deploy some policies + __iptables_rule policy-in --rule "-P INPUT DROP" + __iptables_rule policy-out --rule "-P OUTPUT ACCEPT" + __iptables_rule policy-fwd --rule "-P FORWARD DROP" + + # The usual established rule + __iptables_rule established --rule "-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT" + + # Some service rules + __iptables_rule http --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 + __iptables_rule munin --rule "-A INPUT -p tcp --dport 4949 -j ACCEPT" \ + --state absent + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__iptables_apply(7) `_ +- iptables(8) + + +COPYING +------- +Copyright \(C) 2013 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/__iptables_rule/man.text b/cdist/conf/type/__iptables_rule/man.text deleted file mode 100644 index 2f5b9785..00000000 --- a/cdist/conf/type/__iptables_rule/man.text +++ /dev/null @@ -1,64 +0,0 @@ -cdist-type__iptables_rule(7) -============================ -Nico Schottelius - - -NAME ----- -cdist-type__iptables_rule - Deploy iptable rulesets - - -DESCRIPTION ------------ -This cdist type allows you to manage iptable rules -in a distribution independent manner. - - -REQUIRED PARAMETERS -------------------- -rule:: - The rule to apply. Essentially an iptables command - line without iptables in front of it. - - -OPTIONAL PARAMETERS -------------------- -state:: - 'present' or 'absent', defaults to 'present' - - -EXAMPLES --------- - --------------------------------------------------------------------------------- -# Deploy some policies -__iptables_rule policy-in --rule "-P INPUT DROP" -__iptables_rule policy-out --rule "-P OUTPUT ACCEPT" -__iptables_rule policy-fwd --rule "-P FORWARD DROP" - -# The usual established rule -__iptables_rule established --rule "-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT" - -# Some service rules -__iptables_rule http --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 -__iptables_rule munin --rule "-A INPUT -p tcp --dport 4949 -j ACCEPT" \ - --state absent - --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) -- cdist-type__iptables_apply(7) -- iptables(8) - - -COPYING -------- -Copyright \(C) 2013 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/__iptables_rule/manifest b/cdist/conf/type/__iptables_rule/manifest index f02ab18b..13cec523 100644 --- a/cdist/conf/type/__iptables_rule/manifest +++ b/cdist/conf/type/__iptables_rule/manifest @@ -1,3 +1,4 @@ +#!/bin/sh # # 2013 Nico Schottelius (nico-cdist at schottelius.org) # diff --git a/cdist/conf/type/__issue/man.text b/cdist/conf/type/__issue/man.rst similarity index 62% rename from cdist/conf/type/__issue/man.text rename to cdist/conf/type/__issue/man.rst index 40ed920e..4a6c1f8d 100644 --- a/cdist/conf/type/__issue/man.text +++ b/cdist/conf/type/__issue/man.rst @@ -1,13 +1,10 @@ cdist-type__issue(7) ==================== +Manage issue + Nico Schottelius -NAME ----- -cdist-type__issue - Manage issue - - DESCRIPTION ----------- This cdist type allows you to easily setup /etc/issue. @@ -20,7 +17,7 @@ None. OPTIONAL PARAMETERS ------------------- -source:: +source If supplied, use this file as /etc/issue instead of default. @@ -28,17 +25,17 @@ source:: EXAMPLES -------- --------------------------------------------------------------------------------- -__issue +.. code-block:: sh -# When called from another type -__issue --source "$__type/files/myfancyissue" --------------------------------------------------------------------------------- + __issue + + # When called from another type + __issue --source "$__type/files/myfancyissue" SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__jail/explorer/status b/cdist/conf/type/__jail/explorer/status index 06f7d063..1ceba212 100755 --- a/cdist/conf/type/__jail/explorer/status +++ b/cdist/conf/type/__jail/explorer/status @@ -39,7 +39,7 @@ 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.rst similarity index 61% rename from cdist/conf/type/__jail/man.text rename to cdist/conf/type/__jail/man.rst index 9c968d84..38ec4f96 100644 --- a/cdist/conf/type/__jail/man.text +++ b/cdist/conf/type/__jail/man.rst @@ -1,13 +1,10 @@ cdist-type__jail(7) =================== +Manage FreeBSD jails + Jake Guffey -NAME ----- -cdist-type__jail - Manage FreeBSD jails - - DESCRIPTION ----------- This type is used on FreeBSD to manage jails. @@ -15,47 +12,47 @@ This type is used on FreeBSD to manage jails. REQUIRED PARAMETERS ------------------- -state:: +state Either "present" or "absent", defaults to "present". -jailbase:: +jailbase The location of the .tgz archive containing the base fs for your jails. OPTIONAL PARAMETERS ------------------- -name:: +name The name of the jail. Default is to use the object_id as the jail name. -ip:: +ip The ifconfig style IP/netmask combination to use for the jail guest. If the state parameter is "present," this parameter is required. -hostname:: +hostname The FQDN to use for the jail guest. Defaults to the name parameter. -interface:: +interface The name of the physical interface on the jail server to bind the jail to. Defaults to the first interface found in the output of ifconfig -l. -devfs-ruleset:: +devfs-ruleset The name of the devfs ruleset to associate with the jail. Defaults to "jailrules." This ruleset must be copied to the server via another type. To use this option, devfs-enable must be "true." -jaildir:: +jaildir The location on the remote server to use for hosting jail filesystems. Defaults to /usr/jail. BOOLEAN PARAMETERS ------------------ -stopped:: +stopped Do not start the jail -devfs-disable:: +devfs-disable Whether to disallow devfs mounting within the jail -onboot:: +onboot Whether to add the jail to rc.conf's jail_list variable. @@ -67,37 +64,50 @@ 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 -------- --------------------------------------------------------------------------------- -# Create a jail called www -__jail www --state present --ip "192.168.1.2" --jailbase /my/jail/base.tgz +.. code-block:: sh -# Remove the jail called www -__jail www --state absent --jailbase /my/jail/base.tgz + # Create a jail called www + __jail www --state present --ip "192.168.1.2" --jailbase /my/jail/base.tgz -# The jail www should not be started -__jail www --state present --stopped \ - --ip "192.168.1.2 netmask 255.255.255.0" \ - --jailbase /my/jail/base.tgz + # Remove the jail called www + __jail www --state absent --jailbase /my/jail/base.tgz -# Use the name variable explicitly -__jail thisjail --state present --name www \ - --ip "192.168.1.2" \ - --jailbase /my/jail/base.tgz + # The jail www should not be started + __jail www --state present --stopped \ + --ip "192.168.1.2 netmask 255.255.255.0" \ + --jailbase /my/jail/base.tgz -# Go nuts -__jail lotsofoptions --state present --name testjail \ - --ip "192.168.1.100 netmask 255.255.255.0" \ - --hostname "testjail.example.com" --interface "em0" \ - --onboot --jailbase /my/jail/base.tgz --jaildir /jails --------------------------------------------------------------------------------- + # Use the name variable explicitly + __jail thisjail --state present --name www \ + --ip "192.168.1.2" \ + --jailbase /my/jail/base.tgz + + # Go nuts + __jail lotsofoptions --state present --name testjail \ + --ip "192.168.1.100 netmask 255.255.255.0" \ + --hostname "testjail.example.com" --interface "em0" \ + --onboot --jailbase /my/jail/base.tgz --jaildir /jails SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING 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/__key_value/files/remote_script.sh b/cdist/conf/type/__key_value/files/remote_script.sh index 282ba531..52b3f2de 100644 --- a/cdist/conf/type/__key_value/files/remote_script.sh +++ b/cdist/conf/type/__key_value/files/remote_script.sh @@ -1,3 +1,5 @@ +#!/bin/sh + export key="$(cat "$__object/parameter/key" 2>/dev/null \ || echo "$__object_id")" export state="$(cat "$__object/parameter/state")" diff --git a/cdist/conf/type/__key_value/man.text b/cdist/conf/type/__key_value/man.rst similarity index 62% rename from cdist/conf/type/__key_value/man.text rename to cdist/conf/type/__key_value/man.rst index d4c8e2cc..4b259c75 100644 --- a/cdist/conf/type/__key_value/man.text +++ b/cdist/conf/type/__key_value/man.rst @@ -1,13 +1,10 @@ cdist-type__key_value(7) ======================== +Change property values in files + Steven Armstrong -NAME ----- -cdist-type__key_value - Change property values in files - - DESCRIPTION ----------- This cdist type allows you to change values in a key value based config @@ -16,22 +13,22 @@ file. REQUIRED PARAMETERS ------------------- -file:: +file The file to operate on. -delimiter:: - The delimiter which seperates the key from the value. +delimiter + The delimiter which separates the key from the value. OPTIONAL PARAMETERS ------------------- -state:: +state present or absent, defaults to present. If present, sets the key to value, if absent, removes the key from the file. -key:: +key The key to change. Defaults to object_id. -value:: +value The value for the key. Optional if state=absent, required otherwise. -comment:: +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 @@ -40,41 +37,41 @@ comment:: BOOLEAN PARAMETERS ------------------ -exact_delimiter:: +exact_delimiter If supplied, treat additional whitespaces between key, delimiter and value as wrong value. MESSAGES -------- -remove:: +remove Removed existing key and value -insert:: +insert Added key and value -change:: +change Changed value of existing key -create:: +create A new line was inserted in a new file EXAMPLES -------- --------------------------------------------------------------------------------- -# Set the maximum system user id -__key_value SYS_UID_MAX --file /etc/login.defs --value 666 --delimiter ' ' +.. code-block:: sh -# Same with fancy id -__key_value my-fancy-id --file /etc/login.defs --key SYS_UID_MAX --value 666 \ - --delimiter ' ' + # Set the maximum system user id + __key_value SYS_UID_MAX --file /etc/login.defs --value 666 --delimiter ' ' -# Enable packet forwarding -__key_value net.ipv4.ip_forward --file /etc/sysctl.conf --value 1 \ - --delimiter ' = ' --comment '# my linux kernel should act as a router' + # Same with fancy id + __key_value my-fancy-id --file /etc/login.defs --key SYS_UID_MAX --value 666 \ + --delimiter ' ' -# Remove existing key/value -__key_value LEGACY_KEY --file /etc/somefile --state absent --delimiter '=' --------------------------------------------------------------------------------- + # Enable packet forwarding + __key_value net.ipv4.ip_forward --file /etc/sysctl.conf --value 1 \ + --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 @@ -85,7 +82,7 @@ So you need to exactly specify the key and delimiter. Delimiter can be of any le SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__line/man.text b/cdist/conf/type/__line/man.rst similarity index 59% rename from cdist/conf/type/__line/man.text rename to cdist/conf/type/__line/man.rst index f39ee929..f6d71a5a 100644 --- a/cdist/conf/type/__line/man.text +++ b/cdist/conf/type/__line/man.rst @@ -1,13 +1,10 @@ cdist-type__line(7) =================== +Manage lines in files + Nico Schottelius -NAME ----- -cdist-type__line - Manage lines in files - - DESCRIPTION ----------- This cdist type allows you to add lines and remove lines from files. @@ -18,16 +15,16 @@ REQUIRED PARAMETERS OPTIONAL PARAMETERS ------------------- -state:: +state 'present' or 'absent', defaults to 'present' -line:: +line Specifies the line which should be absent or present Must be present, if state is present. Must not be combined with regex, if state is absent. -regex:: +regex If state is present, search for this pattern and add given line, if the given regular expression does not match. @@ -38,7 +35,7 @@ regex:: Must not be combined with line, if state is absent. -file:: +file If supplied, use this as the destination file. Otherwise the object_id is used. @@ -46,24 +43,24 @@ file:: EXAMPLES -------- --------------------------------------------------------------------------------- -# Manage the DAEMONS line in rc.conf -__line daemons --file /etc/rc.conf --line 'DAEMONS=(hwclock !network sshd crond postfix)' +.. code-block:: sh -# Ensure the home mount is present in /etc/fstab - explicitly make it present -__line home-fstab \ - --file /etc/fstab \ - --line 'filer.fs:/vol/home /home nfs defaults 0 0' \ - --state present + # Manage the DAEMONS line in rc.conf + __line daemons --file /etc/rc.conf --line 'DAEMONS=(hwclock !network sshd crond postfix)' -# Removes the line specifiend in "include_www" from the file "lighttpd.conf" -__line legacy_timezone --file /etc/rc.conf --regex 'TIMEZONE=.*' --state absent --------------------------------------------------------------------------------- + # Ensure the home mount is present in /etc/fstab - explicitly make it present + __line home-fstab \ + --file /etc/fstab \ + --line 'filer.fs:/vol/home /home nfs defaults 0 0' \ + --state present + + # Removes the line specifiend in "include_www" from the file "lighttpd.conf" + __line legacy_timezone --file /etc/rc.conf --regex 'TIMEZONE=.*' --state absent SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ - grep(1) diff --git a/cdist/conf/type/__link/man.text b/cdist/conf/type/__link/man.rst similarity index 51% rename from cdist/conf/type/__link/man.text rename to cdist/conf/type/__link/man.rst index 663087db..654b097b 100644 --- a/cdist/conf/type/__link/man.text +++ b/cdist/conf/type/__link/man.rst @@ -1,13 +1,10 @@ cdist-type__link(7) =================== +Manage links (hard and symbolic) + Nico Schottelius -NAME ----- -cdist-type__link - Manage links (hard and symbolic) - - DESCRIPTION ----------- This cdist type allows you to manage hard and symbolic links. @@ -16,42 +13,42 @@ The given object id is the destination for the link. REQUIRED PARAMETERS ------------------- -source:: +source Specifies the link source. -type:: +type Specifies the link type: Either hard or symoblic. OPTIONAL PARAMETERS ------------------- -state:: +state 'present' or 'absent', defaults to 'present' EXAMPLES -------- --------------------------------------------------------------------------------- -# Create hard link of /etc/shadow -__link /root/shadow --source /etc/shadow --type hard +.. code-block:: sh -# Relative symbolic link -__link /etc/apache2/sites-enabled/www.test.ch \ - --source ../sites-available/www.test.ch \ - --type symbolic + # Create hard link of /etc/shadow + __link /root/shadow --source /etc/shadow --type hard -# Absolute symbolic link -__link /opt/plone --source /home/services/plone --type symbolic + # Relative symbolic link + __link /etc/apache2/sites-enabled/www.test.ch \ + --source ../sites-available/www.test.ch \ + --type symbolic -# Remove link -__link /opt/plone --state absent --------------------------------------------------------------------------------- + # Absolute symbolic link + __link /opt/plone --source /home/services/plone --type symbolic + + # Remove link + __link /opt/plone --state absent SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__locale/man.text b/cdist/conf/type/__locale/man.rst similarity index 53% rename from cdist/conf/type/__locale/man.text rename to cdist/conf/type/__locale/man.rst index 5ccd3eab..df337739 100644 --- a/cdist/conf/type/__locale/man.text +++ b/cdist/conf/type/__locale/man.rst @@ -1,13 +1,10 @@ cdist-type__locale(7) ===================== +Configure locales + Nico Schottelius -NAME ----- -cdist-type__locale - Configure locales - - DESCRIPTION ----------- This cdist type allows you to setup locales. @@ -15,30 +12,30 @@ This cdist type allows you to setup locales. OPTIONAL PARAMETERS ------------------- -state:: +state 'present' or 'absent', defaults to present EXAMPLES -------- --------------------------------------------------------------------------------- -# Add locale de_CH.UTF-8 -__locale de_CH.UTF-8 +.. code-block:: sh -# Same as above, but more explicit -__locale de_CH.UTF-8 --state present + # Add locale de_CH.UTF-8 + __locale de_CH.UTF-8 -# Remove colourful British English -__locale en_GB.UTF-8 --state absent --------------------------------------------------------------------------------- + # Same as above, but more explicit + __locale de_CH.UTF-8 --state present + + # Remove colourful British English + __locale en_GB.UTF-8 --state absent SEE ALSO -------- - locale(1) - localedef(1) -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__locale/manifest b/cdist/conf/type/__locale/manifest index f3d75d59..c1837ae3 100644 --- a/cdist/conf/type/__locale/manifest +++ b/cdist/conf/type/__locale/manifest @@ -1,6 +1,7 @@ #!/bin/sh # -# 2013-2014 Nico Schottelius (nico-cdist at schottelius.org) +# 2013-2015 Nico Schottelius (nico-cdist at schottelius.org) +# 2015 David Hürlimann (david at ungleich.ch) # # This file is part of cdist. # @@ -25,10 +26,13 @@ os=$(cat "$__global/explorer/os") case "$os" in - debian) + debian|devuan) # Debian needs a seperate package __package locales --state present ;; + archlinux|suse|ubuntu|centos) + : + ;; *) echo "Sorry, do not know how to handle os: $os" >&2 echo "Please edit the type ${__type##*/} to fix this." >&2 diff --git a/cdist/conf/type/__motd/gencode-remote b/cdist/conf/type/__motd/gencode-remote index 2aa84902..41fe3482 100755 --- a/cdist/conf/type/__motd/gencode-remote +++ b/cdist/conf/type/__motd/gencode-remote @@ -1,3 +1,5 @@ +#!/bin/sh +# # 2013 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. @@ -20,8 +22,8 @@ os=$(cat "$__global/explorer/os") case "$os" in - debian|ubuntu) - + debian|ubuntu|devuan) + # Debian and Ubuntu need to be updated, # as seen in /etc/init.d/bootlogs echo "uname -snrvm > /var/run/motd" diff --git a/cdist/conf/type/__motd/man.text b/cdist/conf/type/__motd/man.rst similarity index 63% rename from cdist/conf/type/__motd/man.text rename to cdist/conf/type/__motd/man.rst index a4ca80b5..988e2d02 100644 --- a/cdist/conf/type/__motd/man.text +++ b/cdist/conf/type/__motd/man.rst @@ -1,13 +1,10 @@ cdist-type__motd(7) =================== +Manage message of the day + Nico Schottelius -NAME ----- -cdist-type__motd - Manage message of the day - - DESCRIPTION ----------- This cdist type allows you to easily setup /etc/motd. @@ -20,7 +17,7 @@ None. OPTIONAL PARAMETERS ------------------- -source:: +source If supplied, copy this file from the host running cdist to the target. If not supplied, a default message will be placed onto the target. @@ -28,18 +25,18 @@ source:: EXAMPLES -------- --------------------------------------------------------------------------------- -# Use cdist defaults -__motd +.. code-block:: sh -# Supply source file from a different type -__motd --source "$__type/files/my-motd" --------------------------------------------------------------------------------- + # Use cdist defaults + __motd + + # Supply source file from a different type + __motd --source "$__type/files/my-motd" SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__motd/manifest b/cdist/conf/type/__motd/manifest index 286d1ff3..4848a4c3 100755 --- a/cdist/conf/type/__motd/manifest +++ b/cdist/conf/type/__motd/manifest @@ -30,7 +30,7 @@ os=$(cat "$__global/explorer/os") case "$os" in - debian|ubuntu) + debian|ubuntu|devuan) destination=/etc/motd.tail ;; *) diff --git a/cdist/conf/type/__mount/man.text b/cdist/conf/type/__mount/man.rst similarity index 66% rename from cdist/conf/type/__mount/man.text rename to cdist/conf/type/__mount/man.rst index 7299bdf3..696dfbd4 100644 --- a/cdist/conf/type/__mount/man.text +++ b/cdist/conf/type/__mount/man.rst @@ -1,13 +1,10 @@ cdist-type__mount(7) ==================== +Manage filesystem mounts + Steven Armstrong -NAME ----- -cdist-type__mount - manage filesystem mounts - - DESCRIPTION ----------- Manage filesystem mounts either via /etc/fstab or manually. @@ -20,62 +17,62 @@ None. OPTIONAL PARAMETERS ------------------- -device:: +device device to mount at path, defaults to 'none'. see mount(8) -dump:: +dump value for the dump field in fstab. see fstab(5) defaults to 0. This parameter is ignored, if the nofstab parameter is given. -options:: +options comma separated string of options, see mount(8) -pass:: +pass value for the pass field in fstab. see fstab(5) defaults to 0. This parameter is ignored, if the nofstab parameter is given. -path:: +path mount point where to mount the device, see mount(8). Defaults to __object_id -state:: +state either present or absent. Defaults to present. -type:: +type vfstype, see mount(8) BOOLEAN PARAMETERS ------------------ -nofstab:: +nofstab do not manage an entry in /etc/fstab EXAMPLES -------- --------------------------------------------------------------------------------- -__mount /some/dir \ - --device /dev/sdc3 \ - --type xfs \ - --options "defaults,ro" - --dump 0 \ - --pass 1 +.. code-block:: sh -__mount /var/lib/one \ - --device mfsmount \ - --type fuse \ - --options "mfsmaster=mfsmaster.domain.tld,mfssubfolder=/one,nonempty,_netdev" --------------------------------------------------------------------------------- + __mount /some/dir \ + --device /dev/sdc3 \ + --type xfs \ + --options "defaults,ro" + --dump 0 \ + --pass 1 + + __mount /var/lib/one \ + --device mfsmount \ + --type fuse \ + --options "mfsmaster=mfsmaster.domain.tld,mfssubfolder=/one,nonempty,_netdev" SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__mount/manifest b/cdist/conf/type/__mount/manifest index 8a1fa234..472b6e2e 100755 --- a/cdist/conf/type/__mount/manifest +++ b/cdist/conf/type/__mount/manifest @@ -26,9 +26,9 @@ if [ ! -f "$__object/parameter/nofstab" ]; then ( printf "%s" "$(cat "$__object/parameter/device")" printf " %s" "$path" -type="$(cat "$__object/parameter/type" 2>/dev/null || echo "auto")" +type="$(cat "$__object/parameter/type")" printf " %s" "$type" -options="$(cat "$__object/parameter/options" 2>/dev/null || echo "defaults")" +options="$(cat "$__object/parameter/options")" printf " %s" "$options" printf " %s" "$(cat "$__object/parameter/dump")" printf " %s\n" "$(cat "$__object/parameter/pass")" diff --git a/cdist/conf/type/__mount/parameter/default/options b/cdist/conf/type/__mount/parameter/default/options new file mode 100644 index 00000000..e94f8140 --- /dev/null +++ b/cdist/conf/type/__mount/parameter/default/options @@ -0,0 +1 @@ +defaults diff --git a/cdist/conf/type/__mount/parameter/default/type b/cdist/conf/type/__mount/parameter/default/type new file mode 100644 index 00000000..865faf10 --- /dev/null +++ b/cdist/conf/type/__mount/parameter/default/type @@ -0,0 +1 @@ +auto diff --git a/cdist/conf/type/__mysql_database/gencode-remote b/cdist/conf/type/__mysql_database/gencode-remote index 7cd32242..b1c2e6a1 100755 --- a/cdist/conf/type/__mysql_database/gencode-remote +++ b/cdist/conf/type/__mysql_database/gencode-remote @@ -45,7 +45,6 @@ if [ -f "$__object/parameter/user" ]; then EOF EOFF else - password="" cat <<-EOFF mysql -u root <<-EOF GRANT ALL PRIVILEGES ON $database.* to '$user'@'localhost'; diff --git a/cdist/conf/type/__mysql_database/man.text b/cdist/conf/type/__mysql_database/man.rst similarity index 65% rename from cdist/conf/type/__mysql_database/man.text rename to cdist/conf/type/__mysql_database/man.rst index f184a30e..88f1eecd 100644 --- a/cdist/conf/type/__mysql_database/man.text +++ b/cdist/conf/type/__mysql_database/man.rst @@ -1,13 +1,10 @@ cdist-type__mysql_database(7) ============================= +Manage a MySQL database + Benedikt Koeppel -NAME ----- -cdist-type__mysql_database - Manage a MySQL database - - DESCRIPTION ----------- This cdist type allows you to install a MySQL database. @@ -19,28 +16,28 @@ None. OPTIONAL PARAMETERS ------------------- -name:: +name The name of the database to install defaults to the object id -user:: +user A user that should have access to the database -password:: +password The password for the user who manages the database EXAMPLES -------- --------------------------------------------------------------------------------- -__mysql_database "cdist" --name "cdist" --user "myuser" --password "mypwd" --------------------------------------------------------------------------------- +.. code-block:: sh + + __mysql_database "cdist" --name "cdist" --user "myuser" --password "mypwd" SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__package/explorer/pkgng_exists b/cdist/conf/type/__package/explorer/pkgng_exists new file mode 100755 index 00000000..355c5d65 --- /dev/null +++ b/cdist/conf/type/__package/explorer/pkgng_exists @@ -0,0 +1,27 @@ +#!/bin/sh +# +# 2014 Jake Guffey (jake.guffey at eprotex.com) +# +# 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 status of a package - parsed dpkg output +# + +if [ "$($__explorer/os)" = "freebsd" ]; then + command -v pkg +fi + diff --git a/cdist/conf/type/__package/man.text b/cdist/conf/type/__package/man.rst similarity index 54% rename from cdist/conf/type/__package/man.text rename to cdist/conf/type/__package/man.rst index b656c890..1ada06a7 100644 --- a/cdist/conf/type/__package/man.text +++ b/cdist/conf/type/__package/man.rst @@ -1,17 +1,14 @@ cdist-type__package(7) ====================== +Manage packages + Steven Armstrong -NAME ----- -cdist-type__package - Manage packages - - DESCRIPTION ----------- This cdist type allows you to install or uninstall packages on the target. -It dispatches the actual work to the package system dependant types. +It dispatches the actual work to the package system dependent types. REQUIRED PARAMETERS @@ -21,40 +18,41 @@ None OPTIONAL PARAMETERS ------------------- -name:: +name The name of the package to install. Default is to use the object_id as the package name. -version:: +version The version of the package to install. Default is to install the version - choosen by the local package manager. -type:: + chosen by the local package manager. +type The package type to use. Default is determined based on the $os explorer variable. - e.g. __package_apt for Debian - __package_emerge for Gentoo + e.g. + * __package_apt for Debian + * __package_emerge for Gentoo -state:: +state Either "present" or "absent", defaults to "present" EXAMPLES -------- --------------------------------------------------------------------------------- -# Install the package vim on the target -__package vim --state present +.. code-block:: sh -# Same but install specific version -__package vim --state present --version 7.3.50 + # Install the package vim on the target + __package vim --state present -# Force use of a specific package type -__package vim --state present --type __package_apt --------------------------------------------------------------------------------- + # Same but install specific version + __package vim --state present --version 7.3.50 + + # Force use of a specific package type + __package vim --state present --type __package_apt SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__package/manifest b/cdist/conf/type/__package/manifest index 0ebf0099..6b0daa98 100755 --- a/cdist/conf/type/__package/manifest +++ b/cdist/conf/type/__package/manifest @@ -19,7 +19,7 @@ # # # __package is an abstract type which dispatches to the lower level -# __package_$name types which do the actual interaction with the packaging +# __package_$type types which do the actual interaction with the packaging # system. # @@ -32,8 +32,14 @@ else case "$os" in amazon|centos|fedora|redhat) type="yum" ;; archlinux) type="pacman" ;; - debian|ubuntu) type="apt" ;; - freebsd) type="pkg_freebsd" ;; + debian|ubuntu|devuan) type="apt" ;; + freebsd) + if [ -n "$(cat "$__object/explorer/pkgng_exists")" ]; then + type="pkgng_freebsd" + else + type="pkg_freebsd" + fi + ;; gentoo) type="emerge" ;; suse) type="zypper" ;; openwrt) type="opkg" ;; diff --git a/cdist/conf/type/__package_apt/gencode-remote b/cdist/conf/type/__package_apt/gencode-remote index 57339db3..ef313070 100755 --- a/cdist/conf/type/__package_apt/gencode-remote +++ b/cdist/conf/type/__package_apt/gencode-remote @@ -27,12 +27,16 @@ else name="$__object_id" fi -if [ -f "$__object/parameter/state" ]; then - state_should="$(cat "$__object/parameter/state")" +state_should="$(cat "$__object/parameter/state")" + +if [ -f "$__object/parameter/target-release" ]; then + target_release="--target-release $(cat "$__object/parameter/target-release")" else - state_should="present" + target_release="" fi + + # FIXME: use grep directly, state is a list, not a line! state_is="$(cat "$__object/explorer/state")" case "$state_is" in @@ -44,13 +48,13 @@ esac # Hint if we need to avoid questions at some point: # DEBIAN_PRIORITY=critical can reduce the number of questions -aptget="DEBIAN_FRONTEND=noninteractive apt-get --quiet --yes --no-install-recommends -o DPkg::Options::=\"--force-confold\"" +aptget="DEBIAN_FRONTEND=noninteractive apt-get --quiet --yes --no-install-recommends -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\"" [ "$state_is" = "$state_should" ] && exit 0 case "$state_should" in present) - echo $aptget install \"$name\" + echo $aptget install $target_release \"$name\" ;; absent) echo $aptget remove \"$name\" diff --git a/cdist/conf/type/__package_apt/man.text b/cdist/conf/type/__package_apt/man.rst similarity index 53% rename from cdist/conf/type/__package_apt/man.text rename to cdist/conf/type/__package_apt/man.rst index 5d4656c1..ec28c0cc 100644 --- a/cdist/conf/type/__package_apt/man.text +++ b/cdist/conf/type/__package_apt/man.rst @@ -1,13 +1,10 @@ cdist-type__package_apt(7) ========================== +Manage packages with apt-get + Nico Schottelius -NAME ----- -cdist-type__package_apt - Manage packages with apt-get - - DESCRIPTION ----------- apt-get is usually used on Debian and variants (like Ubuntu) to @@ -21,32 +18,35 @@ None OPTIONAL PARAMETERS ------------------- -name:: +name If supplied, use the name and not the object id as the package name. -state:: +state Either "present" or "absent", defaults to "present" +target-release + Passed on to apt-get install, see apt-get(8). + Essentially allows you to retrieve packages from a different release EXAMPLES -------- --------------------------------------------------------------------------------- -# Ensure zsh in installed -__package_apt zsh --state present +.. code-block:: sh -# In case you only want *a* webserver, but don't care which one -__package_apt webserver --state present --name nginx + # Ensure zsh in installed + __package_apt zsh --state present -# Remove obsolete package -__package_apt puppet --state absent --------------------------------------------------------------------------------- + # In case you only want *a* webserver, but don't care which one + __package_apt webserver --state present --name nginx + + # Remove obsolete package + __package_apt puppet --state absent SEE ALSO -------- -- cdist-type(7) -- cdist-type__package(7) +- `cdist-type(7) `_ +- `cdist-type__package(7) `_ COPYING diff --git a/cdist/conf/type/__package_apt/parameter/default/state b/cdist/conf/type/__package_apt/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__package_apt/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__package_apt/parameter/optional b/cdist/conf/type/__package_apt/parameter/optional index 41b8e6cf..d6674f95 100644 --- a/cdist/conf/type/__package_apt/parameter/optional +++ b/cdist/conf/type/__package_apt/parameter/optional @@ -1,3 +1,4 @@ name version state +target-release diff --git a/cdist/conf/type/__package_emerge/gencode-remote b/cdist/conf/type/__package_emerge/gencode-remote index d4cee37e..1199fc72 100644 --- a/cdist/conf/type/__package_emerge/gencode-remote +++ b/cdist/conf/type/__package_emerge/gencode-remote @@ -27,37 +27,40 @@ else name="$__object_id" fi -if [ -f "$__object/parameter/state" ]; then - state_should="$(cat "$__object/parameter/state")" -else - state_should="present" +state_should="$(cat "$__object/parameter/state")" + +version="$(cat "$__object/parameter/version")" + +if [ -n "$version" ]; then + name="=$name-$version" fi pkg_version="$(cat "$__object/explorer/pkg_version")" if [ -z "$pkg_version" ]; then state_is="absent" -elif [ $(echo "$pkg_version" | wc -l) -gt 1 ]; then +elif [ -z "$version" -a $(echo "$pkg_version" | wc -l) -gt 1 ]; then + echo "Package name is not unique! The following packages are installed:" + echo "$pkg_version" + exit 1 +elif [ -n "$version" -a $(echo "$pkg_version" | cut -d " " -f 1 | sort | uniq | wc -l) -gt 1 ]; then echo "Package name is not unique! The following packages are installed:" echo "$pkg_version" exit 1 else state_is="present" - installed_version="$(echo "$pkg_version" | cut -d " " -f 2)" + if [ -n "$version" ] && echo "$pkg_version" | cut -d " " -f 2 | grep -q -x "$version"; then + installed_version="$(echo "$pkg_version" | cut -d " " -f 2 | grep -x "$version")" + else + installed_version="$(echo "$pkg_version" | cut -d " " -f 2 | tail -n 1)" + fi fi -if [ -f "$__object/parameter/version" ]; then - version="$(cat "$__object/parameter/version")" - if [ ! -z "$version" ]; then - name="=$name-$version" - fi -else - version="" -fi # Exit if nothing is needed to be done [ "$state_is" = "$state_should" ] && ( [ -z "$version" ] || [ "$installed_version" = "$version" ] ) && exit 0 [ "$state_should" = "absent" ] && [ ! -z "$version" ] && [ "$installed_version" != "$version" ] && exit 0 + case "$state_should" in present) echo "emerge \"$name\" &>/dev/null || exit 1" diff --git a/cdist/conf/type/__package_emerge/man.text b/cdist/conf/type/__package_emerge/man.rst similarity index 58% rename from cdist/conf/type/__package_emerge/man.text rename to cdist/conf/type/__package_emerge/man.rst index 983b49a8..fe06031e 100644 --- a/cdist/conf/type/__package_emerge/man.text +++ b/cdist/conf/type/__package_emerge/man.rst @@ -1,13 +1,10 @@ cdist-type__package_emerge(7) ============================= +Manage packages with portage + Thomas Oettli -NAME ----- -cdist-type__package_emerge - Manage packages with portage - - DESCRIPTION ----------- Portage is usually used on the gentoo distribution to manage packages. @@ -23,35 +20,35 @@ None OPTIONAL PARAMETERS ------------------- -name:: +name If supplied, use the name and not the object id as the package name. -state:: +state Either "present" or "absent", defaults to "present". -version:: +version If supplied, use to install or uninstall a specific version of the package named. EXAMPLES -------- --------------------------------------------------------------------------------- -# Ensure sys-devel/gcc is installed -__package_emerge sys-devel/gcc --state present +.. code-block:: sh -# If you want a specific version of a package -__package_emerge app-portage/gentoolkit --state present --version 0.3.0.8-r2 + # Ensure sys-devel/gcc is installed + __package_emerge sys-devel/gcc --state present -# Remove package -__package_emerge sys-devel/gcc --state absent --------------------------------------------------------------------------------- + # If you want a specific version of a package + __package_emerge app-portage/gentoolkit --state present --version 0.3.0.8-r2 + + # Remove package + __package_emerge sys-devel/gcc --state absent SEE ALSO -------- -- cdist-type(7) -- cdist-type__package(7) -- cdist-type__package_emerge_dependencies(7) +- `cdist-type(7) `_ +- `cdist-type__package(7) `_ +- `cdist-type__package_emerge_dependencies(7) `_ COPYING diff --git a/cdist/conf/type/__package_emerge/parameter/default/state b/cdist/conf/type/__package_emerge/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__package_emerge/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/test/cdist_object/fixtures/object/__second/.keep b/cdist/conf/type/__package_emerge/parameter/default/version similarity index 100% rename from cdist/test/cdist_object/fixtures/object/__second/.keep rename to cdist/conf/type/__package_emerge/parameter/default/version diff --git a/cdist/conf/type/__package_emerge_dependencies/man.text b/cdist/conf/type/__package_emerge_dependencies/man.rst similarity index 55% rename from cdist/conf/type/__package_emerge_dependencies/man.text rename to cdist/conf/type/__package_emerge_dependencies/man.rst index 0862256b..21af86e3 100644 --- a/cdist/conf/type/__package_emerge_dependencies/man.text +++ b/cdist/conf/type/__package_emerge_dependencies/man.rst @@ -1,19 +1,17 @@ cdist-type__package_emerge_dependencies(7) ========================================== +Install dependencies for __package_emerge + Thomas Oettli -NAME ----- -cdist-type__package_emerge_dependencies - Install dependencies for __package_emerge - - DESCRIPTION ----------- Portage is usually used on the gentoo distribution to manage packages. This type installs the following tools which are required by __package_emerge to work: -app-portage/flaggie -app-portage/gentoolkit + +* app-portage/flaggie +* app-portage/gentoolkit REQUIRED PARAMETERS @@ -29,17 +27,17 @@ None EXAMPLES -------- --------------------------------------------------------------------------------- -# Ensure app-portage/flaggie and app-portage/gentoolkit are installed -__package_emerge_dependencies --------------------------------------------------------------------------------- +.. code-block:: sh + + # Ensure app-portage/flaggie and app-portage/gentoolkit are installed + __package_emerge_dependencies SEE ALSO -------- -- cdist-type(7) -- cdist-type__package(7) -- cdist-type__package_emerge(7) +- `cdist-type(7) `_ +- `cdist-type__package(7) `_ +- `cdist-type__package_emerge(7) `_ COPYING diff --git a/cdist/conf/type/__package_luarocks/gencode-remote b/cdist/conf/type/__package_luarocks/gencode-remote index 7a5a5b04..1046a936 100755 --- a/cdist/conf/type/__package_luarocks/gencode-remote +++ b/cdist/conf/type/__package_luarocks/gencode-remote @@ -29,11 +29,7 @@ else name="$__object_id" fi -if [ -f "$__object/parameter/state" ]; then - state_should="$(cat "$__object/parameter/state")" -else - state_should="present" -fi +state_should="$(cat "$__object/parameter/state")" if grep -q "(installed)" "$__object/explorer/pkg_status"; then state_is="present" diff --git a/cdist/conf/type/__package_luarocks/man.text b/cdist/conf/type/__package_luarocks/man.rst similarity index 59% rename from cdist/conf/type/__package_luarocks/man.text rename to cdist/conf/type/__package_luarocks/man.rst index 657f68e5..ff7fea83 100644 --- a/cdist/conf/type/__package_luarocks/man.text +++ b/cdist/conf/type/__package_luarocks/man.rst @@ -1,13 +1,10 @@ cdist-type__package_luarocks(7) =============================== +Manage luarocks packages + Christian G. Warden -NAME ----- -cdist-type__package_luarocks - Manage luarocks packages - - DESCRIPTION ----------- LuaRocks is a deployment and management system for Lua modules. @@ -20,29 +17,29 @@ None OPTIONAL PARAMETERS ------------------- -name:: +name If supplied, use the name and not the object id as the package name. -state:: +state Either "present" or "absent", defaults to "present" EXAMPLES -------- --------------------------------------------------------------------------------- -# Ensure luasocket is installed -__package_luarocks luasocket --state present +.. code-block:: sh -# Remove package -__package_luarocks luasocket --state absent --------------------------------------------------------------------------------- + # Ensure luasocket is installed + __package_luarocks luasocket --state present + + # Remove package + __package_luarocks luasocket --state absent SEE ALSO -------- -- cdist-type(7) -- cdist-type__package(7) +- `cdist-type(7) `_ +- `cdist-type__package(7) `_ COPYING diff --git a/cdist/conf/type/__package_luarocks/parameter/default/state b/cdist/conf/type/__package_luarocks/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__package_luarocks/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__package_opkg/gencode-remote b/cdist/conf/type/__package_opkg/gencode-remote index 1fb78fbe..2df31202 100755 --- a/cdist/conf/type/__package_opkg/gencode-remote +++ b/cdist/conf/type/__package_opkg/gencode-remote @@ -28,11 +28,7 @@ else name="$__object_id" fi -if [ -f "$__object/parameter/state" ]; then - state_should="$(cat "$__object/parameter/state")" -else - state_should="present" -fi +state_should="$(cat "$__object/parameter/state")" state_is="$(cat "$__object/explorer/pkg_status")" case "$state_is" in diff --git a/cdist/conf/type/__package_opkg/man.text b/cdist/conf/type/__package_opkg/man.rst similarity index 57% rename from cdist/conf/type/__package_opkg/man.text rename to cdist/conf/type/__package_opkg/man.rst index aeb0a1c5..9af17988 100644 --- a/cdist/conf/type/__package_opkg/man.text +++ b/cdist/conf/type/__package_opkg/man.rst @@ -1,13 +1,10 @@ cdist-type__package_opkg(7) -========================== +=========================== +Manage packages with opkg + Giel van Schijndel -NAME ----- -cdist-type__package_opkg - Manage packages with opkg - - DESCRIPTION ----------- opkg is usually used on OpenWRT to manage packages. @@ -20,29 +17,29 @@ None OPTIONAL PARAMETERS ------------------- -name:: +name If supplied, use the name and not the object id as the package name. -state:: +state Either "present" or "absent", defaults to "present" EXAMPLES -------- --------------------------------------------------------------------------------- -# Ensure lsof is installed -__package_opkg lsof --state present +.. code-block:: sh -# Remove obsolete package -__package_opkg dnsmasq --state absent --------------------------------------------------------------------------------- + # Ensure lsof is installed + __package_opkg lsof --state present + + # Remove obsolete package + __package_opkg dnsmasq --state absent SEE ALSO -------- -- cdist-type(7) -- cdist-type__package(7) +- `cdist-type(7) `_ +- `cdist-type__package(7) `_ COPYING diff --git a/cdist/conf/type/__package_opkg/parameter/default/state b/cdist/conf/type/__package_opkg/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__package_opkg/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__package_pacman/gencode-remote b/cdist/conf/type/__package_pacman/gencode-remote index 02744fa8..da1ac7c2 100755 --- a/cdist/conf/type/__package_pacman/gencode-remote +++ b/cdist/conf/type/__package_pacman/gencode-remote @@ -31,11 +31,7 @@ else name="$__object_id" fi -if [ -f "$__object/parameter/state" ]; then - state_should="$(cat "$__object/parameter/state")" -else - state_should="present" -fi +state_should="$(cat "$__object/parameter/state")" pkg_version="$(cat "$__object/explorer/pkg_version")" if [ -z "$pkg_version" ]; then diff --git a/cdist/conf/type/__package_pacman/man.text b/cdist/conf/type/__package_pacman/man.rst similarity index 54% rename from cdist/conf/type/__package_pacman/man.text rename to cdist/conf/type/__package_pacman/man.rst index 2e24ecd9..3d8845a5 100644 --- a/cdist/conf/type/__package_pacman/man.text +++ b/cdist/conf/type/__package_pacman/man.rst @@ -1,13 +1,10 @@ cdist-type__package_pacman(7) ============================= +Manage packages with pacman + Nico Schottelius -NAME ----- -cdist-type__package_pacman - Manage packages with pacman - - DESCRIPTION ----------- Pacman is usually used on the Archlinux distribution to manage packages. @@ -20,32 +17,32 @@ None OPTIONAL PARAMETERS ------------------- -name:: +name If supplied, use the name and not the object id as the package name. -state:: +state Either "present" or "absent", defaults to "present" EXAMPLES -------- --------------------------------------------------------------------------------- -# Ensure zsh in installed -__package_pacman zsh --state present +.. code-block:: sh -# If you don't want to follow pythonX packages, but always use python -__package_pacman python --state present --name python2 + # Ensure zsh in installed + __package_pacman zsh --state present -# Remove obsolete package -__package_pacman puppet --state absent --------------------------------------------------------------------------------- + # If you don't want to follow pythonX packages, but always use python + __package_pacman python --state present --name python2 + + # Remove obsolete package + __package_pacman puppet --state absent SEE ALSO -------- -- cdist-type(7) -- cdist-type__package(7) +- `cdist-type(7) `_ +- `cdist-type__package(7) `_ COPYING diff --git a/cdist/conf/type/__package_pacman/parameter/default/state b/cdist/conf/type/__package_pacman/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__package_pacman/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__package_pip/gencode-remote b/cdist/conf/type/__package_pip/gencode-remote index ec1c89f8..ccfdb92b 100644 --- a/cdist/conf/type/__package_pip/gencode-remote +++ b/cdist/conf/type/__package_pip/gencode-remote @@ -1,6 +1,7 @@ #!/bin/sh # # 2012 Nico Schottelius (nico-cdist at schottelius.org) +# 2016 Darko Poljak (darko.poljak at gmail.com) # # This file is part of cdist. # @@ -22,11 +23,7 @@ # state_is=$(cat "$__object/explorer/state") -if [ -f "$__object/parameter/state" ]; then - state_should="$(cat "$__object/parameter/state")" -else - state_should="present" -fi +state_should="$(cat "$__object/parameter/state")" [ "$state_is" = "$state_should" ] && exit 0 @@ -44,12 +41,30 @@ else pip="pip" fi +runasparam="$__object/parameter/runas" +if [ -f "$runasparam" ] +then + runas=$(cat "$runasparam") +else + runas="" +fi + case "$state_should" in present) - echo $pip install -q "$name" + if [ "$runas" ] + then + echo "su -c \"$pip install -q $name\" $runas" + else + echo $pip install -q "$name" + fi ;; absent) - echo $pip uninstall -q -y "$name" + if [ "$runas" ] + then + echo "su -c \"$pip uninstall -q -y $name\" $runas" + else + echo $pip uninstall -q -y "$name" + fi ;; *) echo "Unknown state: $state_should" >&2 diff --git a/cdist/conf/type/__package_pip/man.text b/cdist/conf/type/__package_pip/man.rst similarity index 55% rename from cdist/conf/type/__package_pip/man.text rename to cdist/conf/type/__package_pip/man.rst index 5f619871..b312fff5 100644 --- a/cdist/conf/type/__package_pip/man.text +++ b/cdist/conf/type/__package_pip/man.rst @@ -1,13 +1,10 @@ cdist-type__package_pip(7) ========================== +Manage packages with pip + Nico Schottelius -NAME ----- -cdist-type__package_pip - Manage packages with pip - - DESCRIPTION ----------- Pip is used in Python environments to install packages. @@ -21,32 +18,38 @@ None OPTIONAL PARAMETERS ------------------- -name:: +name If supplied, use the name and not the object id as the package name. -pip:: +pip Instead of using pip from PATH, use the specific pip path. -state:: +state Either "present" or "absent", defaults to "present" +runas + Run pip as specified user. By default it runs as root. + EXAMPLES -------- --------------------------------------------------------------------------------- -# Install a package -__package_pip pyro --state present +.. code-block:: sh -# Use pip in a virtualenv located at /root/shinken_virtualenv -__package_pip pyro --state present --pip /root/shinken_virtualenv/bin/pip --------------------------------------------------------------------------------- + # Install a package + __package_pip pyro --state present + + # Use pip in a virtualenv located at /root/shinken_virtualenv + __package_pip pyro --state present --pip /root/shinken_virtualenv/bin/pip + + # Use pip in a virtualenv located at /foo/shinken_virtualenv as user foo + __package_pip pyro --state present --pip /foo/shinken_virtualenv/bin/pip --runas foo SEE ALSO -------- -- cdist-type(7) -- cdist-type__package(7) +- `cdist-type(7) `_ +- `cdist-type__package(7) `_ COPYING diff --git a/cdist/conf/type/__package_pip/parameter/default/state b/cdist/conf/type/__package_pip/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__package_pip/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__package_pip/parameter/optional b/cdist/conf/type/__package_pip/parameter/optional index f32876f7..d909e790 100644 --- a/cdist/conf/type/__package_pip/parameter/optional +++ b/cdist/conf/type/__package_pip/parameter/optional @@ -1,2 +1,4 @@ +name pip state +runas diff --git a/cdist/conf/type/__package_pkg_freebsd/gencode-remote b/cdist/conf/type/__package_pkg_freebsd/gencode-remote index 3f5ebde7..5866a0a8 100755 --- a/cdist/conf/type/__package_pkg_freebsd/gencode-remote +++ b/cdist/conf/type/__package_pkg_freebsd/gencode-remote @@ -51,23 +51,10 @@ else name="$__object_id" fi -if [ -f "$__object/parameter/flavor" ]; then - flavor="$(cat "$__object/parameter/flavor")" -fi - -if [ -f "$__object/parameter/version" ]; then - version="$(cat "$__object/parameter/version")" -fi - -if [ -f "$__object/parameter/pkgsite" ]; then - pkgsite="$(cat "$__object/parameter/pkgsite")" -fi - -if [ -f "$__object/parameter/state" ]; then - state="$(cat "$__object/parameter/state")" -else - state="present" -fi +flavor="$(cat "$__object/parameter/flavor")" +version="$(cat "$__object/parameter/version")" +pkgsite="$(cat "$__object/parameter/pkgsite")" +state="$(cat "$__object/parameter/state")" curr_version="$(cat "$__object/explorer/pkg_version")" add_cmd="pkg_add" rm_cmd="pkg_delete" diff --git a/cdist/conf/type/__package_pkg_freebsd/man.text b/cdist/conf/type/__package_pkg_freebsd/man.rst similarity index 53% rename from cdist/conf/type/__package_pkg_freebsd/man.text rename to cdist/conf/type/__package_pkg_freebsd/man.rst index 71387148..c728cc9a 100644 --- a/cdist/conf/type/__package_pkg_freebsd/man.text +++ b/cdist/conf/type/__package_pkg_freebsd/man.rst @@ -1,13 +1,10 @@ cdist-type__package_pkg_freebsd(7) ================================== +Manage FreeBSD packages + Jake Guffey -NAME ----- -cdist-type__package_pkg_freebsd - Manage FreeBSD packages - - DESCRIPTION ----------- This type is usually used on FreeBSD to manage packages. @@ -20,44 +17,44 @@ None OPTIONAL PARAMETERS ------------------- -name:: +name If supplied, use the name and not the object id as the package name. -flavor:: +flavor If supplied, use to avoid ambiguity. -version:: +version If supplied, use to install a specific version of the package named. -pkgsite:: +pkgsite If supplied, use to install from a specific package repository. -state:: +state Either "present" or "absent", defaults to "present" EXAMPLES -------- --------------------------------------------------------------------------------- -# Ensure zsh is installed -__package_pkg_freebsd zsh --state present +.. code-block:: sh -# Ensure vim is installed, use flavor no_x11 -__package_pkg_freebsd vim --state present --flavor no_x11 + # Ensure zsh is installed + __package_pkg_freebsd zsh --state present -# If you don't want to follow pythonX packages, but always use python -__package_pkg_freebsd python --state present --name python2 + # Ensure vim is installed, use flavor no_x11 + __package_pkg_freebsd vim --state present --flavor no_x11 -# Remove obsolete package -__package_pkg_freebsd puppet --state absent --------------------------------------------------------------------------------- + # If you don't want to follow pythonX packages, but always use python + __package_pkg_freebsd python --state present --name python2 + + # Remove obsolete package + __package_pkg_freebsd puppet --state absent SEE ALSO -------- -- cdist-type(7) -- cdist-type__package(7) +- `cdist-type(7) `_ +- `cdist-type__package(7) `_ COPYING diff --git a/cdist/test/cdist_object/fixtures/object/__second/on-the/.cdist/.keep b/cdist/conf/type/__package_pkg_freebsd/parameter/default/flavor similarity index 100% rename from cdist/test/cdist_object/fixtures/object/__second/on-the/.cdist/.keep rename to cdist/conf/type/__package_pkg_freebsd/parameter/default/flavor diff --git a/cdist/test/cdist_object/fixtures/object/__second/under-the/.cdist/.keep b/cdist/conf/type/__package_pkg_freebsd/parameter/default/pkgsite similarity index 100% rename from cdist/test/cdist_object/fixtures/object/__second/under-the/.cdist/.keep rename to cdist/conf/type/__package_pkg_freebsd/parameter/default/pkgsite diff --git a/cdist/conf/type/__package_pkg_freebsd/parameter/default/state b/cdist/conf/type/__package_pkg_freebsd/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__package_pkg_freebsd/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/test/cdist_object/fixtures/object/__third/.keep b/cdist/conf/type/__package_pkg_freebsd/parameter/default/version similarity index 100% rename from cdist/test/cdist_object/fixtures/object/__third/.keep rename to cdist/conf/type/__package_pkg_freebsd/parameter/default/version diff --git a/cdist/conf/type/__package_pkg_openbsd/gencode-remote b/cdist/conf/type/__package_pkg_openbsd/gencode-remote index 08e15e89..dea7f711 100755 --- a/cdist/conf/type/__package_pkg_openbsd/gencode-remote +++ b/cdist/conf/type/__package_pkg_openbsd/gencode-remote @@ -42,11 +42,7 @@ else name="$__object_id" fi -if [ -f "$__object/parameter/state" ]; then - state_should="$(cat "$__object/parameter/state")" -else - state_should="present" -fi +state_should="$(cat "$__object/parameter/state")" pkg_version="$(cat "$__object/explorer/pkg_version")" diff --git a/cdist/conf/type/__package_pkg_openbsd/man.rst b/cdist/conf/type/__package_pkg_openbsd/man.rst new file mode 100644 index 00000000..f9a746b9 --- /dev/null +++ b/cdist/conf/type/__package_pkg_openbsd/man.rst @@ -0,0 +1,63 @@ +cdist-type__package_pkg(7) +========================== +Manage OpenBSD packages + +Andi Brönnimann + + +DESCRIPTION +----------- +This type is usually used on OpenBSD to manage packages. + + +REQUIRED PARAMETERS +------------------- +None + + +OPTIONAL PARAMETERS +------------------- +name + If supplied, use the name and not the object id as the package name. + +flavor + If supplied, use to avoid ambiguity. + +state + Either "present" or "absent", defaults to "present" + +pkg_path + Manually specify a PKG_PATH to add packages from. + +EXAMPLES +-------- + +.. code-block:: sh + + # Ensure zsh is installed + __package_pkg_openbsd zsh --state present + + # Ensure vim is installed, use flavor no_x11 + __package_pkg_openbsd vim --state present --flavor no_x11 + + # If you don't want to follow pythonX packages, but always use python + __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 + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__package(7) `_ + + +COPYING +------- +Copyright \(C) 2011 Andi Brönnimann. 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/__package_pkg_openbsd/man.text b/cdist/conf/type/__package_pkg_openbsd/man.text deleted file mode 100644 index c7de2652..00000000 --- a/cdist/conf/type/__package_pkg_openbsd/man.text +++ /dev/null @@ -1,66 +0,0 @@ -cdist-type__package_pkg(7) -========================== -Andi Brönnimann - - -NAME ----- -cdist-type__package_pkg_openbsd - Manage OpenBSD packages - - -DESCRIPTION ------------ -This type is usually used on OpenBSD to manage packages. - - -REQUIRED PARAMETERS -------------------- -None - - -OPTIONAL PARAMETERS -------------------- -name:: - If supplied, use the name and not the object id as the package name. - -flavor:: - If supplied, use to avoid ambiguity. - -state:: - Either "present" or "absent", defaults to "present" - -pkg_path:: - Manually specify a PKG_PATH to add packages from. - -EXAMPLES --------- - --------------------------------------------------------------------------------- -# Ensure zsh is installed -__package_pkg_openbsd zsh --state present - -# Ensure vim is installed, use flavor no_x11 -__package_pkg_openbsd vim --state present --flavor no_x11 - -# If you don't want to follow pythonX packages, but always use python -__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 --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) -- cdist-type__package(7) - - -COPYING -------- -Copyright \(C) 2011 Andi Brönnimann. 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/__package_pkg_openbsd/parameter/default/state b/cdist/conf/type/__package_pkg_openbsd/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__package_pkg_openbsd/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__package_pkgng_freebsd/explorer/pkg_version b/cdist/conf/type/__package_pkgng_freebsd/explorer/pkg_version new file mode 100755 index 00000000..947857b9 --- /dev/null +++ b/cdist/conf/type/__package_pkgng_freebsd/explorer/pkg_version @@ -0,0 +1,37 @@ +#!/bin/sh +# +# 2014 Jake Guffey (jake.guffey at eprotex.com) +# +# 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 status of a package - parsed dpkg output +# + +if [ -f "$__object/parameter/name" ]; then + name="$(cat "$__object/parameter/name")" +else + name="$__object_id" +fi + +# Don't produce "no pkgs installed" output -- breaks things +PKG_OUTPUT=$(pkg info 2>&1) +echo -n "$(echo "$PKG_OUTPUT" \ + | awk '{print $1}' \ + | sed 's/^\(.*\)-\([^-]*\)$/name:\1 ver:\2/g' \ + | grep "name:$name ver:" \ + | sed 's/^.*ver:\(.*\)/\1/g')" + diff --git a/cdist/conf/type/__package_pkgng_freebsd/gencode-remote b/cdist/conf/type/__package_pkgng_freebsd/gencode-remote new file mode 100755 index 00000000..3c3e41e9 --- /dev/null +++ b/cdist/conf/type/__package_pkgng_freebsd/gencode-remote @@ -0,0 +1,127 @@ +#!/bin/sh +# +# 2014 Jake Guffey (jake.guffey at eprotex.com) +# +# 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 . +# +# +# Manage packages with pkg on FreeBSD +# + +# Debug +#exec >&2 +#set -x + +if [ -f "$__object/parameter/name" ]; then + name="$(cat "$__object/parameter/name")" +else + name="$__object_id" +fi + +flavor="$(cat "$__object/parameter/flavor")" +version="$(cat "$__object/parameter/version")" + +if [ -f "$__object/parameter/upgrade" ]; then + upgrade="true" +else + upgrade="false" +fi + +repo="$(cat "$__object/parameter/repo")" +state="$(cat "$__object/parameter/state")" +curr_version="$(cat "$__object/explorer/pkg_version")" +add_cmd="pkg install -y" +rm_cmd="pkg delete -y" +upg_cmd="pkg upgrade -y" +cmd="" + +# Print the command to be executed +# Parms: $1 -- mode, "rm", "add", or "upg" +# $2 -- the command to be echoed +execcmd(){ + local _cmd="" + + case "$1" in + add) + _cmd="${add_cmd} $2" + ;; + rm) + _cmd="${rm_cmd} $2" + ;; + upg) + _cmd="${upg_cmd} $2" + ;; + *) + printf "Error. Don't understand command: %s" "$1" >&2 + exit 1 + ;; + esac + + echo "$_cmd 2>&- >&-" # Silence the output of the command + echo "status=\$?" + echo "if [ \"\$status\" -ne \"0\" ]; then" + echo " echo \"Error: ${_cmd} exited nonzero with \$status\"'!' >&2" + echo " exit 1" + echo "fi" +} + +if [ -n "$curr_version" ]; then # PKG *is* installed + if [ -n "$repo" ]; then + cmd="-r ${repo} ${name}" + else + cmd="${name}" + fi + if [ -n "$flavor" ]; then + cmd="${cmd}-${flavor}" + fi + # PKG is supposed to be removed + if [ "$state" = "absent" ]; then + execcmd "rm" "${cmd}" + # PKG is supposed to be installed to a particular version + elif [ -n "$version" ] && [ "$version" != "$curr_version" ]; then + if [ "$upgrade" = "true" ]; then + execcmd "upg" "${cmd}" + else + printf "Version %s is already installed and pkg-ng can't upgrade directly to version %s.\nTo upgrade to the latest version, use the --upgrade flag.\n" "$curr_version" "$version" >&2 + exit 1 + fi + # PKG is supposed to be installed to the latest version + else + : # Do nothing. + fi +else # PKG *isn't* installed + if [ "$state" = "absent" ]; then # Shouldn't be installed + exit 0 + else # Should be installed + if [ -n "$repo" ]; then + cmd="-r ${repo} ${name}" + else + cmd="${name}" + fi + if [ -n "$flavor" ]; then + cmd="${cmd}-${flavor}" + fi + if [ -n "$version" ]; then + cmd="${cmd}-${version}" + fi + + execcmd "add" "$cmd" + exit 0 + fi +fi + +# Debug +#set +x diff --git a/cdist/conf/type/__package_pkgng_freebsd/man.rst b/cdist/conf/type/__package_pkgng_freebsd/man.rst new file mode 100644 index 00000000..36f1a7d8 --- /dev/null +++ b/cdist/conf/type/__package_pkgng_freebsd/man.rst @@ -0,0 +1,94 @@ +cdist-type__package_pkgng_freebsd(7) +==================================== +Manage FreeBSD packages with pkg-ng + +Jake Guffey + + +DESCRIPTION +----------- +This type is usually used on FreeBSD to manage packages. + + +REQUIRED PARAMETERS +------------------- +None + + +OPTIONAL PARAMETERS +------------------- +name + If supplied, use the name and not the object id as the package name. + +flavor + If supplied, use to avoid ambiguity. + +version + If supplied, use to install a specific version of the package named. + +repo + If supplied, use to install the package named from a particular repo. + +state + Either "present" or "absent", defaults to "present" + + +BOOLEAN PARAMETERS +------------------ +upgrade + If supplied, allow upgrading to the latest version of a package. + + +CAVEATS +------- +This type requires that repository definitions already exist in /etc/pkg/\*.conf. +Ensure that they exist prior to use of this type with __file. + +pkg-ng can't upgrade a package to a specific version. If this type needs to +upgrade a package, it can only ugprade to the latest available version. If the +"upgrade" parameter is not given and an upgrade needs to occur, an error will result. + + +MESSAGES +-------- +install + The package was installed +remove + The package was removed +upgrade + The package was upgraded +exist + The package was already present and thus not installed + + +EXAMPLES +-------- + +.. code-block:: sh + + # Ensure zsh is installed + __package_pkgng_freebsd zsh --state present + + # Ensure vim is installed, use flavor no_x11 + __package_pkgng_freebsd vim --state present --flavor no_x11 + + # If you don't want to follow pythonX packages, but always use python + __package_pkgng_freebsd python --state present --name python2 + + # Install a package from a particular repository when multiples exist + __package_pkgng_freebsd bash --state present --repo myrepo + + # Remove obsolete package + __package_pkgng_freebsd puppet --state absent + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__package(7) `_ + + +COPYING +------- +Copyright \(C) 2014 Jake Guffey. 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/__package_pkgng_freebsd/parameter/boolean b/cdist/conf/type/__package_pkgng_freebsd/parameter/boolean new file mode 100644 index 00000000..007ead00 --- /dev/null +++ b/cdist/conf/type/__package_pkgng_freebsd/parameter/boolean @@ -0,0 +1 @@ +upgrade \ No newline at end of file diff --git a/cdist/test/cdist_object/fixtures/object/__third/moon/.cdist/.keep b/cdist/conf/type/__package_pkgng_freebsd/parameter/default/flavor similarity index 100% rename from cdist/test/cdist_object/fixtures/object/__third/moon/.cdist/.keep rename to cdist/conf/type/__package_pkgng_freebsd/parameter/default/flavor diff --git a/cdist/conf/type/__package_pkgng_freebsd/parameter/default/repo b/cdist/conf/type/__package_pkgng_freebsd/parameter/default/repo new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__package_pkgng_freebsd/parameter/default/state b/cdist/conf/type/__package_pkgng_freebsd/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__package_pkgng_freebsd/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__package_pkgng_freebsd/parameter/default/version b/cdist/conf/type/__package_pkgng_freebsd/parameter/default/version new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__package_pkgng_freebsd/parameter/optional b/cdist/conf/type/__package_pkgng_freebsd/parameter/optional new file mode 100644 index 00000000..6e67f838 --- /dev/null +++ b/cdist/conf/type/__package_pkgng_freebsd/parameter/optional @@ -0,0 +1,5 @@ +name +flavor +version +repo +state diff --git a/cdist/conf/type/__package_rubygem/gencode-remote b/cdist/conf/type/__package_rubygem/gencode-remote index 6256e308..dc755ad3 100755 --- a/cdist/conf/type/__package_rubygem/gencode-remote +++ b/cdist/conf/type/__package_rubygem/gencode-remote @@ -27,11 +27,7 @@ else name="$__object_id" fi -if [ -f "$__object/parameter/state" ]; then - state_should="$(cat "$__object/parameter/state")" -else - state_should="present" -fi +state_should="$(cat "$__object/parameter/state")" if grep -q true "$__object/explorer/pkg_status"; then state_is="present" diff --git a/cdist/conf/type/__package_rubygem/man.text b/cdist/conf/type/__package_rubygem/man.rst similarity index 60% rename from cdist/conf/type/__package_rubygem/man.text rename to cdist/conf/type/__package_rubygem/man.rst index a808c2aa..4cb9af04 100644 --- a/cdist/conf/type/__package_rubygem/man.text +++ b/cdist/conf/type/__package_rubygem/man.rst @@ -1,13 +1,10 @@ cdist-type__package_rubygem(7) ============================== +Manage rubygem packages + Chase Allen James -NAME ----- -cdist-type__package_rubygem - Manage rubygem packages - - DESCRIPTION ----------- Rubygems is the default package management system for the Ruby programming language. @@ -20,29 +17,29 @@ None OPTIONAL PARAMETERS ------------------- -name:: +name If supplied, use the name and not the object id as the package name. -state:: +state Either "present" or "absent", defaults to "present" EXAMPLES -------- --------------------------------------------------------------------------------- -# Ensure sinatra is installed -__package_rubygem sinatra --state present +.. code-block:: sh -# Remove package -__package_rubygem rails --state absent --------------------------------------------------------------------------------- + # Ensure sinatra is installed + __package_rubygem sinatra --state present + + # Remove package + __package_rubygem rails --state absent SEE ALSO -------- -- cdist-type(7) -- cdist-type__package(7) +- `cdist-type(7) `_ +- `cdist-type__package(7) `_ COPYING diff --git a/cdist/conf/type/__package_rubygem/parameter/default/state b/cdist/conf/type/__package_rubygem/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__package_rubygem/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__package_update_index/gencode-remote b/cdist/conf/type/__package_update_index/gencode-remote new file mode 100755 index 00000000..589e7202 --- /dev/null +++ b/cdist/conf/type/__package_update_index/gencode-remote @@ -0,0 +1,50 @@ +#!/bin/sh +# +# 2014 Ricardo Catalinas Jiménez (jimenezrick at gmail.com) +# +# 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 . +# +# +# Update the package index with the appropriate package manager +# + +type="$__object/parameter/type" + +if [ -f "$type" ]; then + type="$(cat "$type")" +else + # By default determine package manager based on operating system + os="$(cat "$__global/explorer/os")" + case "$os" in + amazon|centos|fedora|redhat) type="yum" ;; + debian|ubuntu|devuan) type="apt" ;; + archlinux) type="pacman" ;; + *) + echo "Don't know how to manage packages on: $os" >&2 + exit 1 + ;; + esac +fi + +case "$type" in + yum) ;; + apt) echo "apt-get --quiet update" ;; + pacman) echo "pacman --noprogressbar --sync --refresh" ;; + *) + echo "Don't know how to manage packages on: $os" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__package_update_index/man.rst b/cdist/conf/type/__package_update_index/man.rst new file mode 100644 index 00000000..a16d29ce --- /dev/null +++ b/cdist/conf/type/__package_update_index/man.rst @@ -0,0 +1,50 @@ +cdist-type__package_update_index(7) +=================================== +Update the package index + +Ricardo Catalinas Jiménez + + +DESCRIPTION +----------- +This cdist type allows you to update the package index on the target. +It will automatically use the appropriate package manager. + + +REQUIRED PARAMETERS +------------------- +None + + +OPTIONAL PARAMETERS +------------------- +type + The package manager to use. Default is determined based on the $os + explorer variable. + e.g. + * apt for Debian + * yum for Red Hat + * pacman for Arch Linux + + +EXAMPLES +-------- + +.. code-block:: sh + + # Update the package index on the target + __package_update_index + + # Force use of a specific package manager + __package_update_index --type apt + + +SEE ALSO +-------- +- `cdist-type(7) `_ + + +COPYING +------- +Copyright \(C) 2014 Ricardo Catalinas Jiménez. 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/__package_update_index/parameter/optional b/cdist/conf/type/__package_update_index/parameter/optional new file mode 100644 index 00000000..aa80e646 --- /dev/null +++ b/cdist/conf/type/__package_update_index/parameter/optional @@ -0,0 +1 @@ +type diff --git a/cdist/conf/type/__package_update_index/singleton b/cdist/conf/type/__package_update_index/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__package_upgrade_all/gencode-remote b/cdist/conf/type/__package_upgrade_all/gencode-remote new file mode 100755 index 00000000..4d034816 --- /dev/null +++ b/cdist/conf/type/__package_upgrade_all/gencode-remote @@ -0,0 +1,62 @@ +#!/bin/sh +# +# 2014 Ricardo Catalinas Jiménez (jimenezrick at gmail.com) +# +# 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 . +# +# +# Upgrade all the already installed packages with the appropriate package +# manager +# + +type="$__object/parameter/type" + +if [ -f "$type" ]; then + type="$(cat "$type")" +else + # By default determine package manager based on operating system + os="$(cat "$__global/explorer/os")" + case "$os" in + amazon|centos|fedora|redhat) type="yum" ;; + debian|ubuntu|devuan) type="apt" ;; + archlinux) type="pacman" ;; + *) + echo "Don't know how to manage packages on: $os" >&2 + exit 1 + ;; + esac +fi + +aptget="DEBIAN_FRONTEND=noninteractive apt-get --quiet --yes --no-install-recommends -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\"" + +case "$type" in + yum) + echo "yum --quiet --assumeyes update" + echo "yum --quiet clean all" + ;; + apt) + echo $aptget dist-upgrade + echo "apt-get --quiet autoclean" + ;; + pacman) + echo "pacman --noprogressbar --noconfirm --sync --sysupgrade" + echo "pacman --noprogressbar --noconfirm --sync --clean" + ;; + *) + echo "Don't know how to manage packages on: $os" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__package_upgrade_all/man.rst b/cdist/conf/type/__package_upgrade_all/man.rst new file mode 100644 index 00000000..146a8259 --- /dev/null +++ b/cdist/conf/type/__package_upgrade_all/man.rst @@ -0,0 +1,50 @@ +cdist-type__package_upgrade_all(7) +================================== +Upgrade all the installed packages + +Ricardo Catalinas Jiménez + + +DESCRIPTION +----------- +This cdist type allows you to upgrade all the installed packages on the +target. It will automatically use the appropriate package manager. + + +REQUIRED PARAMETERS +------------------- +None + + +OPTIONAL PARAMETERS +------------------- +type + The package manager to use. Default is determined based on the $os + explorer variable. + e.g. + * apt for Debian + * yum for Red Hat + * pacman for Arch Linux + + +EXAMPLES +-------- + +.. code-block:: sh + + # Upgrade all the installed packages on the target + __package_upgrade_all + + # Force use of a specific package manager + __package_upgrade_all --type apt + + +SEE ALSO +-------- +- `cdist-type(7) `_ + + +COPYING +------- +Copyright \(C) 2014 Ricardo Catalinas Jiménez. 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/__package_upgrade_all/parameter/optional b/cdist/conf/type/__package_upgrade_all/parameter/optional new file mode 100644 index 00000000..aa80e646 --- /dev/null +++ b/cdist/conf/type/__package_upgrade_all/parameter/optional @@ -0,0 +1 @@ +type diff --git a/cdist/conf/type/__package_upgrade_all/singleton b/cdist/conf/type/__package_upgrade_all/singleton new file mode 100644 index 00000000..e69de29b 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.rst similarity index 56% rename from cdist/conf/type/__package_yum/man.text rename to cdist/conf/type/__package_yum/man.rst index d958dd1e..65e56c7a 100644 --- a/cdist/conf/type/__package_yum/man.text +++ b/cdist/conf/type/__package_yum/man.rst @@ -1,13 +1,10 @@ cdist-type__package_yum(7) ========================== +Manage packages with yum + Nico Schottelius -NAME ----- -cdist-type__package_yum - Manage packages with yum - - DESCRIPTION ----------- Yum is usually used on the Fedora distribution to manage packages. @@ -22,32 +19,37 @@ None OPTIONAL PARAMETERS ------------------- -name:: +name If supplied, use the name and not the object id as the package name. -state:: +state Either "present" or "absent", defaults to "present" +url + URL to use for the package EXAMPLES -------- --------------------------------------------------------------------------------- -# Ensure zsh in installed -__package_yum zsh --state present +.. code-block:: sh -# If you don't want to follow pythonX packages, but always use python -__package_yum python --state present --name python2 + # Ensure zsh in installed + __package_yum zsh --state present -# Remove obsolete package -__package_yum puppet --state absent --------------------------------------------------------------------------------- + # If you don't want to follow pythonX packages, but always use python + __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 SEE ALSO -------- -- cdist-type(7) -- cdist-type__package(7) +- `cdist-type(7) `_ +- `cdist-type__package(7) `_ COPYING 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/__package_zypper/explorer/pkg_version b/cdist/conf/type/__package_zypper/explorer/pkg_version index 7f203067..83bf6dab 100644 --- a/cdist/conf/type/__package_zypper/explorer/pkg_version +++ b/cdist/conf/type/__package_zypper/explorer/pkg_version @@ -42,7 +42,7 @@ case "$ptype" in zypper search --match-exact --installed-only --type "$ptype" "$name" | grep -E '^i' | cut -d " " -f 3 || true ;; *) - echo "unknown ptype in __package_zypper explorer" &>2 + echo "unknown ptype in __package_zypper explorer" >&2 exit 1 ;; esac diff --git a/cdist/conf/type/__package_zypper/man.text b/cdist/conf/type/__package_zypper/man.rst similarity index 51% rename from cdist/conf/type/__package_zypper/man.text rename to cdist/conf/type/__package_zypper/man.rst index 104d3a7a..2df22e72 100644 --- a/cdist/conf/type/__package_zypper/man.text +++ b/cdist/conf/type/__package_zypper/man.rst @@ -1,13 +1,10 @@ cdist-type__package_zypper(7) ============================= +Manage packages with zypper + Daniel Heule -NAME ----- -cdist-type__package_zypper - Manage packages with zypper - - DESCRIPTION ----------- Zypper is usually used on the SuSE distribution to manage packages. @@ -20,46 +17,46 @@ None OPTIONAL PARAMETERS ------------------- -name:: +name If supplied, use the name and not the object id as the package name. -state:: +state Either "present" or "absent", defaults to "present" -version:: +version The version of the package to install. Default is to install the version - choosen by the local package manager. For a list of available versions, + chosen by the local package manager. For a list of available versions, have a look at the output of "zypper se -s packagename" -ptype:: +ptype Either "package", "patch", "pattern", "product" or "srcpackage", defaults to "package". For a description see man zypper. EXAMPLES -------- --------------------------------------------------------------------------------- -# Ensure zsh is installed -__package_zypper zsh --state present +.. code-block:: sh -# If you don't want to follow pythonX packages, but always use python -__package_zypper python --state present --name python2 + # Ensure zsh is installed + __package_zypper zsh --state present -# Ensure binutils is installed and the version is forced to be 2.23.1-0.19.2 -__package_zypper binutils --state present --version 2.23.1-0.19.2 + # If you don't want to follow pythonX packages, but always use python + __package_zypper python --state present --name python2 -# Remove package -__package_zypper cfengine --state absent + # Ensure binutils is installed and the version is forced to be 2.23.1-0.19.2 + __package_zypper binutils --state present --version 2.23.1-0.19.2 -# install all packages which belongs to pattern x11 -__package_zypper x11 --ptype pattern --state present --------------------------------------------------------------------------------- + # Remove package + __package_zypper cfengine --state absent + + # install all packages which belongs to pattern x11 + __package_zypper x11 --ptype pattern --state present SEE ALSO -------- -- cdist-type(7) -- cdist-type__package(7) +- `cdist-type(7) `_ +- `cdist-type__package(7) `_ COPYING diff --git a/cdist/conf/type/__pacman_conf/man.rst b/cdist/conf/type/__pacman_conf/man.rst new file mode 100644 index 00000000..930035fa --- /dev/null +++ b/cdist/conf/type/__pacman_conf/man.rst @@ -0,0 +1,68 @@ +cdist-type__pacman_conf(7) +========================== +Manage pacman configuration + +Dominique Roux + + +DESCRIPTION +----------- +The type allows you to configure options section, add or delete repositories and manage mirrorlists + + +REQUIRED PARAMETERS +------------------- +section + 'options' for configure options section + + Otherwise it specifies a repository or a plain file + +key + Specifies the key which will be set + + If section = 'options' or file is not set the key will + be checked against available keys from pacman.conf + +value + Specifies the value which will be set against the key + + +OPTIONAL PARAMETERS +------------------- +state + 'present' or 'absent', defaults to 'present' + +file + Specifies the filename. + + The managed file will be named like 'plain_file_filename' + + If supplied the key will not be checked. + + +EXAMPLES +-------- + +.. code-block:: sh + + # Manage options section in pacman.conf + __pacman_conf options_Architecture --section options --key Architecture --value auto + + # Add new repository + __pacman_conf localrepo_Server --section localrepo --key Server --value "file:///var/cache/pacman/pkg" + + # Add mirror to a mirrorlist + __pacman_conf customlist_Server --file customlist --section customlist --key Server\ + --value "file:///var/cache/pacman/pkg" + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- grep(1) + + +COPYING +------- +Copyright \(C) 2015 Dominique Roux. 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/__pacman_conf/manifest b/cdist/conf/type/__pacman_conf/manifest new file mode 100644 index 00000000..b9679577 --- /dev/null +++ b/cdist/conf/type/__pacman_conf/manifest @@ -0,0 +1,133 @@ +#!/bin/sh +# +# 2015 Dominique Roux (dominique.roux4 at gmail.com) +# +# 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 . +# + +#get params +section=$(cat "$__object/parameter/section") +key=$(cat "$__object/parameter/key") +value=$(cat "$__object/parameter/value") +file=$(cat "$__object/parameter/file" 2>/dev/null) +state=$(cat "$__object/parameter/state" 2>/dev/null) + +#path variable default /etc/pacman.d +sec_path="/etc/pacman.d" + +#allowed keys (from man pacman.conf) +allowed_option_keys="RootDir DBPath CacheDir GPGDir LogFile HoldPkg IgnorePkg IgnoreGroup Include Architecture XferCommand NoUpgrade NoExtract CleanMethod SigLevel LocalFileSigLevel RemoteFileSigLevel" +boolean_option_keys="UseSyslog Color UseDelta TotalDownload CheckSpace VerbosePkgLists" +allowed_repo_keys="Include Server SigLevel Usage" + +#set global variables +MATCH=0 + +#function for check if array contain string +contains_element() { + + MATCH=0 + + target=$1 + shift + + for key in "$@"; do + if [ "${key}" = "${target}" ]; then + MATCH=1 + return 0 + fi + done + MATCH=0 +} + +if [ "${file}" ]; then + __file "${sec_path}/plain_file_${file}"\ + --state exists --mode 666 + + if [ "${state}" = "present" ]; then + + require="__file/${sec_path}/plain_file_${file}" __key_value ${file}_${key}\ + --file ${sec_path}/plain_file_${file} --key ${key} --value ${value} --delimiter ' = ' + + exit 0 + + elif [ "${state}" = "absent" ]; then + require="__file/${sec_path}/plain_file_${file}" __key_value ${file}_${key}\ + --state absent + exit 0 + + else + echo "ERROR: Unknown state: ${state}" >&2 + exit 0 + fi +fi + +if [ "${section}" = "options" ]; then + + __file "${sec_path}/${section}"\ + --state exists --mode 666 --source - << eof +[${section}] +eof + #check if key is valid + #check for boolean value + contains_element "${key}" "${boolean_option_keys}" + + if [ "${MATCH}" -eq 1 ]; then + if [ "${value}" = "on" ]; then + require="__file/${sec_path}/${section}" __line ${key}_${value}\ + --file ${sec_path}/${section} --line ${key} + elif [ "${value}" = "off" ]; then + require="__file/${sec_path}/${section}" __line ${key}_${value}\ + --file ${sec_path}/${section} --line ${key} --state absent + fi + + else + contains_element "${key}" "${allowed_option_keys}" + + if [ "${MATCH}" -eq 1 ]; then + require="__file/${sec_path}/${section}" __key_value ${section}_${key}\ + --file ${sec_path}/${section} --key ${key} --value ${value} --delimiter ' = ' + else + echo "Key: ${key} is not valid. Have a look at man pacman.conf" >&2 + fi + fi + +else + __file "${sec_path}/repo_${section}"\ + --state exists --mode 666 --source - << eof +[${section}] +eof + if [ "${state}" = "present" ]; then + + #check if key is valid + contains_element "${key}" "${allowed_repo_keys}" + if [ ${MATCH} -eq 0 ]; then + exit + fi + + require="__file/${sec_path}/repo_${section}" __key_value ${section}_${key}\ + --file ${sec_path}/repo_${section} --key ${key} --value ${value} --delimiter ' = ' + + elif [ "${state}" = "absent" ]; then + + require="__file/${sec_path}/repo_${section}" __key_value ${section}_${key}\ + --state absent + + else + echo "ERROR: Unknown state: ${state}" >&2 + fi + +fi diff --git a/cdist/conf/type/__pacman_conf/parameter/default/file b/cdist/conf/type/__pacman_conf/parameter/default/file new file mode 100644 index 00000000..139597f9 --- /dev/null +++ b/cdist/conf/type/__pacman_conf/parameter/default/file @@ -0,0 +1,2 @@ + + diff --git a/cdist/conf/type/__pacman_conf/parameter/default/state b/cdist/conf/type/__pacman_conf/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__pacman_conf/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__pacman_conf/parameter/optional b/cdist/conf/type/__pacman_conf/parameter/optional new file mode 100644 index 00000000..5d52aa2e --- /dev/null +++ b/cdist/conf/type/__pacman_conf/parameter/optional @@ -0,0 +1,2 @@ +file +state diff --git a/cdist/conf/type/__pacman_conf/parameter/required b/cdist/conf/type/__pacman_conf/parameter/required new file mode 100644 index 00000000..2f9d59e0 --- /dev/null +++ b/cdist/conf/type/__pacman_conf/parameter/required @@ -0,0 +1,3 @@ +section +key +value diff --git a/cdist/conf/type/__pacman_conf_integrate/files/mirrorlist b/cdist/conf/type/__pacman_conf_integrate/files/mirrorlist new file mode 100644 index 00000000..a378fb50 --- /dev/null +++ b/cdist/conf/type/__pacman_conf_integrate/files/mirrorlist @@ -0,0 +1,344 @@ +## +## Arch Linux repository mirrorlist +## Generated on 2015-03-15 +## + +## Worldwide +#Server = http://mirror.rackspace.com/archlinux/$repo/os/$arch + +## Australia +#Server = http://mirror.aarnet.edu.au/pub/archlinux/$repo/os/$arch +#Server = http://archlinux.mirror.digitalpacific.com.au/$repo/os/$arch +#Server = http://ftp.iinet.net.au/pub/archlinux/$repo/os/$arch +#Server = http://mirror.internode.on.net/pub/archlinux/$repo/os/$arch +#Server = http://mirror.rackcentral.com.au/archlinux/$repo/os/$arch +#Server = http://ftp.swin.edu.au/archlinux/$repo/os/$arch +#Server = http://archlinux.mirror.uber.com.au/$repo/os/$arch + +## Austria +#Server = http://mirror.easyname.at/archlinux/$repo/os/$arch +#Server = http://mirror1.htu.tugraz.at/archlinux/$repo/os/$arch + +## Bangladesh +#Server = http://mirrors.ispros.com.bd/archlinux/$repo/os/$arch + +## Belarus +#Server = http://ftp.byfly.by/pub/archlinux/$repo/os/$arch +#Server = http://mirror.datacenter.by/pub/archlinux/$repo/os/$arch + +## Belgium +#Server = http://archlinux.cu.be/$repo/os/$arch +#Server = http://archlinux.mirror.kangaroot.net/$repo/os/$arch + +## Brazil +#Server = http://archlinux.c3sl.ufpr.br/$repo/os/$arch +#Server = http://www.las.ic.unicamp.br/pub/archlinux/$repo/os/$arch +#Server = http://pet.inf.ufsc.br/mirrors/archlinux/$repo/os/$arch + +## Bulgaria +#Server = http://mirror.telepoint.bg/archlinux/$repo/os/$arch + +## Canada +#Server = http://archlinux.dropswitch.net/archlinux/$repo/os/$arch +#Server = http://mirror.clibre.uqam.ca/archlinux/$repo/os/$arch +#Server = http://mirror.csclub.uwaterloo.ca/archlinux/$repo/os/$arch +#Server = http://mirror.its.dal.ca/archlinux/$repo/os/$arch +#Server = http://archlinux.mirror.rafal.ca/$repo/os/$arch +#Server = http://archlinux.mirror.vexxhost.com/$repo/os/$arch + +## Chile +#Server = http://mirror.archlinux.cl/$repo/os/$arch + +## China +#Server = http://mirrors.163.com/archlinux/$repo/os/$arch +#Server = http://mirror.bjtu.edu.cn/archlinux/$repo/os/$arch +#Server = http://mirrors.cqu.edu.cn/archlinux/$repo/os/$arch +#Server = http://mirrors.hust.edu.cn/archlinux/$repo/os/$arch +#Server = http://mirrors.hustunique.com/archlinux/$repo/os/$arch +#Server = http://mirrors.neusoft.edu.cn/archlinux/$repo/os/$arch +#Server = http://run.hit.edu.cn/archlinux/$repo/os/$arch +#Server = http://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch +#Server = http://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch +#Server = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch +#Server = http://mirrors.zju.edu.cn/archlinux/$repo/os/$arch + +## Colombia +#Server = http://mirror.edatel.net.co/archlinux/$repo/os/$arch +#Server = http://www.laqee.unal.edu.co/archlinux/$repo/os/$arch + +## Croatia +#Server = http://archlinux.iskon.hr/$repo/os/$arch + +## Czech Republic +#Server = http://archlinux.mirror.dkm.cz/pub/archlinux/$repo/os/$arch +#Server = http://gluttony.sin.cvut.cz/arch/$repo/os/$arch +#Server = http://mirror.oss.maxcdn.com/archlinux/$repo/os/$arch +#Server = http://mirrors.nic.cz/archlinux/$repo/os/$arch +#Server = http://mirror.vpsfree.cz/archlinux/$repo/os/$arch + +## Denmark +#Server = http://mirrors.dotsrc.org/archlinux/$repo/os/$arch +#Server = http://mirror.one.com/archlinux/$repo/os/$arch + +## Ecuador +#Server = http://mirror.cedia.org.ec/archlinux/$repo/os/$arch +#Server = http://mirror.espoch.edu.ec/archlinux/$repo/os/$arch +#Server = http://mirror.uta.edu.ec/archlinux/$repo/os/$arch + +## Estonia +#Server = http://ftp.eenet.ee/pub/archlinux/$repo/os/$arch + +## France +#Server = http://archlinux.aubrac-medical.fr/$repo/os/$arch +#Server = http://mirror.archlinux.ikoula.com/archlinux/$repo/os/$arch +#Server = http://archlinux.vi-di.fr/$repo/os/$arch +#Server = http://mir.art-software.fr/arch/$repo/os/$arch +#Server = http://fooo.biz/archlinux/$repo/os/$arch +#Server = https://fooo.biz/archlinux/$repo/os/$arch +#Server = http://mirror.lastmikoi.net/archlinux/$repo/os/$arch +#Server = http://mirror.lightcone.eu/archlinux/$repo/os/$arch +#Server = http://archlinux.mailtunnel.eu/$repo/os/$arch +#Server = https://www.mailtunnel.eu/archlinux/$repo/os/$arch +#Server = http://mir.archlinux.fr/$repo/os/$arch +#Server = http://arch.nimukaito.net/$repo/os/$arch +#Server = http://archlinux.mirrors.ovh.net/archlinux/$repo/os/$arch +#Server = http://archlinux.mirror.pkern.at/$repo/os/$arch +#Server = https://archlinux.mirror.pkern.at/$repo/os/$arch +#Server = http://archlinux.polymorf.fr/$repo/os/$arch +#Server = http://arch.static.lu/$repo/os/$arch +#Server = https://arch.static.lu/$repo/os/$arch +#Server = http://arch.tamcore.eu/$repo/os/$arch +#Server = http://mirror.tyborek.pl/arch/$repo/os/$arch +#Server = http://ftp.u-strasbg.fr/linux/distributions/archlinux/$repo/os/$arch +#Server = http://arch.yourlabs.org/$repo/os/$arch + +## Germany +#Server = http://mirror.23media.de/archlinux/$repo/os/$arch +#Server = http://archlinux.limun.org/$repo/os/$arch +#Server = https://archlinux.limun.org/$repo/os/$arch +#Server = http://artfiles.org/archlinux.org/$repo/os/$arch +#Server = http://ftp.fau.de/archlinux/$repo/os/$arch +#Server = https://ftp.fau.de/archlinux/$repo/os/$arch +#Server = http://mirror.flipez.de/archlinux/$repo/os/$arch +#Server = http://mirror.fluxent.de/archlinux/$repo/os/$arch +#Server = http://mirror.gnomus.de/$repo/os/$arch +#Server = http://arch.packages.gnp-tec.net/$repo/os/$arch +#Server = http://ftp5.gwdg.de/pub/linux/archlinux/$repo/os/$arch +#Server = http://mirror.hactar.bz/$repo/os/$arch +#Server = http://ftp.hawo.stw.uni-erlangen.de/archlinux/$repo/os/$arch +#Server = http://ftp.hosteurope.de/mirror/ftp.archlinux.org/$repo/os/$arch +#Server = http://ftp-stud.hs-esslingen.de/pub/Mirrors/archlinux/$repo/os/$arch +#Server = http://mirror.js-webcoding.de/pub/archlinux/$repo/os/$arch +#Server = http://mirror.k42.ch/archlinux/$repo/os/$arch +#Server = http://mirror.de.leaseweb.net/archlinux/$repo/os/$arch +#Server = http://mirror.metalgamer.eu/archlinux/$repo/os/$arch +#Server = http://mirror.michael-eckert.net/archlinux/$repo/os/$arch +#Server = http://archlinux.my-universe.com/$repo/os/$arch +#Server = https://archlinux.my-universe.com/$repo/os/$arch +#Server = http://mirrors.n-ix.net/archlinux/$repo/os/$arch +#Server = http://mirror.netcologne.de/archlinux/$repo/os/$arch +#Server = http://mirrors.niyawe.de/archlinux/$repo/os/$arch +#Server = http://ftp.halifax.rwth-aachen.de/archlinux/$repo/os/$arch +#Server = http://linux.rz.rub.de/archlinux/$repo/os/$arch +#Server = http://mirror.selfnet.de/archlinux/$repo/os/$arch +#Server = http://ftp.spline.inf.fu-berlin.de/mirrors/archlinux/$repo/os/$arch +#Server = http://ftp.tu-chemnitz.de/pub/linux/archlinux/$repo/os/$arch +#Server = http://ftp.tuxdroid.org/archlinux/$repo/os/$arch +#Server = http://ftp.uni-bayreuth.de/linux/archlinux/$repo/os/$arch +#Server = http://ftp.uni-hannover.de/archlinux/$repo/os/$arch +#Server = http://ftp.uni-kl.de/pub/linux/archlinux/$repo/os/$arch +#Server = http://mirror.united-gameserver.de/archlinux/$repo/os/$arch + +## Greece +#Server = http://ftp.cc.uoc.gr/mirrors/linux/archlinux/$repo/os/$arch +#Server = http://foss.aueb.gr/mirrors/linux/archlinux/$repo/os/$arch +#Server = https://foss.aueb.gr/mirrors/linux/archlinux/$repo/os/$arch +#Server = http://mirrors.myaegean.gr/linux/archlinux/$repo/os/$arch +#Server = http://ftp.ntua.gr/pub/linux/archlinux/$repo/os/$arch +#Server = http://ftp.otenet.gr/linux/archlinux/$repo/os/$arch + +## Hungary +#Server = http://ftp.mfa.kfki.hu/pub/mirrors/ftp.archlinux.org/$repo/os/$arch + +## Iceland +#Server = http://mirror.system.is/arch/$repo/os/$arch +#Server = https://mirror.system.is/arch/$repo/os/$arch + +## India +#Server = http://mirror.cse.iitk.ac.in/archlinux/$repo/os/$arch +#Server = http://ftp.iitm.ac.in/archlinux/$repo/os/$arch + +## Indonesia +#Server = http://mirror.kavalinux.com/archlinux/$repo/os/$arch +#Server = http://mirror.poliwangi.ac.id/archlinux/$repo/os/$arch +#Server = http://suro.ubaya.ac.id/archlinux/$repo/os/$arch + +## Iran +#Server = http://mirror.yazd.ac.ir/arch/$repo/os/$arch + +## Ireland +#Server = http://ftp.heanet.ie/mirrors/ftp.archlinux.org/$repo/os/$arch + +## Israel +#Server = http://mirror.isoc.org.il/pub/archlinux/$repo/os/$arch + +## Italy +#Server = http://archlinux.openlabto.org/archlinux/$repo/os/$arch +#Server = http://archlinux.beccacervello.it/archlinux/$repo/os/$arch +#Server = http://mirrors.prometeus.net/archlinux/$repo/os/$arch + +## Japan +#Server = http://ftp.tsukuba.wide.ad.jp/Linux/archlinux/$repo/os/$arch +#Server = http://ftp.jaist.ac.jp/pub/Linux/ArchLinux/$repo/os/$arch + +## Kazakhstan +#Server = http://mirror.neolabs.kz/archlinux/$repo/os/$arch + +## Latvia +#Server = http://archlinux.koyanet.lv/archlinux/$repo/os/$arch + +## Lithuania +#Server = http://archlinux.akmc.lt/$repo/os/$arch +#Server = http://atviras.lt/veidrodziai/archlinux/$repo/os/$arch + +## Luxembourg +#Server = http://archlinux.mirror.root.lu/$repo/os/$arch + +## Macedonia +#Server = http://arch.softver.org.mk/archlinux/$repo/os/$arch +#Server = http://mirror.t-home.mk/archlinux/$repo/os/$arch + +## Netherlands +#Server = http://arch.apt-get.eu/$repo/os/$arch +#Server = http://mirror.i3d.net/pub/archlinux/$repo/os/$arch +#Server = https://mirror.i3d.net/pub/archlinux/$repo/os/$arch +#Server = http://mirror.nl.leaseweb.net/archlinux/$repo/os/$arch +#Server = http://ftp.nluug.nl/os/Linux/distr/archlinux/$repo/os/$arch +#Server = http://ftp.snt.utwente.nl/pub/os/linux/archlinux/$repo/os/$arch + +## New Caledonia +#Server = http://mirror.lagoon.nc/pub/archlinux/$repo/os/$arch +#Server = http://archlinux.nautile.nc/archlinux/$repo/os/$arch + +## New Zealand +#Server = http://mirror.xnet.co.nz/pub/archlinux/$repo/os/$arch + +## Norway +#Server = http://mirror.archlinux.no/$repo/os/$arch +#Server = http://archlinux.uib.no/$repo/os/$arch +#Server = http://archlinux.neuf.no/$repo/os/$arch + +## Philippines +#Server = http://mirror.pregi.net/pub/Linux/archlinux/$repo/os/$arch + +## Poland +#Server = http://mirror.chmuri.net/archmirror/$repo/os/$arch +#Server = http://arch.midov.pl/arch/$repo/os/$arch +#Server = http://piotrkosoft.net/pub/mirrors/ftp.archlinux.org/$repo/os/$arch +#Server = http://ftp.vectranet.pl/archlinux/$repo/os/$arch + +## Portugal +#Server = http://archlinux.dcc.fc.up.pt/$repo/os/$arch +#Server = http://ftp.rnl.tecnico.ulisboa.pt/pub/archlinux/$repo/os/$arch + +## Romania +#Server = http://mirror.archlinux.ro/archlinux/$repo/os/$arch +#Server = http://archlinux.mirrors.linux.ro/$repo/os/$arch + +## Russia +#Server = http://mirror.rol.ru/archlinux/$repo/os/$arch +#Server = http://mirror.yandex.ru/archlinux/$repo/os/$arch + +## Serbia +#Server = http://mirror.pmf.kg.ac.rs/archlinux/$repo/os/$arch + +## Singapore +#Server = http://download.nus.edu.sg/mirror/arch/$repo/os/$arch +#Server = http://mirror.nus.edu.sg/archlinux/$repo/os/$arch + +## Slovakia +#Server = http://mirror.lnx.sk/pub/linux/archlinux/$repo/os/$arch +#Server = http://tux.rainside.sk/archlinux/$repo/os/$arch + +## South Africa +#Server = http://ftp.wa.co.za/pub/archlinux/$repo/os/$arch + +## South Korea +#Server = http://ftp.kaist.ac.kr/ArchLinux/$repo/os/$arch +#Server = http://mirror.premi.st/archlinux/$repo/os/$arch + +## Spain +#Server = http://osl.ugr.es/archlinux/$repo/os/$arch +#Server = http://sunsite.rediris.es/mirror/archlinux/$repo/os/$arch + +## Sweden +#Server = http://ftp.df.lth.se/pub/archlinux/$repo/os/$arch +#Server = http://ftp.lysator.liu.se/pub/archlinux/$repo/os/$arch +#Server = https://ftp.lysator.liu.se/pub/archlinux/$repo/os/$arch +#Server = http://ftp.myrveln.se/pub/linux/archlinux/$repo/os/$arch +#Server = http://ftp.portlane.com/pub/os/linux/archlinux/$repo/os/$arch + +## Switzerland +#Server = http://archlinux.puzzle.ch/$repo/os/$arch + +## Taiwan +#Server = http://archlinux.cs.nctu.edu.tw/$repo/os/$arch +#Server = http://shadow.ind.ntou.edu.tw/archlinux/$repo/os/$arch +#Server = http://ftp.tku.edu.tw/Linux/ArchLinux/$repo/os/$arch +#Server = http://ftp.yzu.edu.tw/Linux/archlinux/$repo/os/$arch + +## Turkey +#Server = http://ftp.linux.org.tr/archlinux/$repo/os/$arch + +## Ukraine +#Server = http://mirrors.nix.org.ua/linux/archlinux/$repo/os/$arch + +## United Kingdom +#Server = http://mirror.bytemark.co.uk/archlinux/$repo/os/$arch +#Server = http://mirror.cinosure.com/archlinux/$repo/os/$arch +#Server = http://mirrors.manchester.m247.com/arch-linux/$repo/os/$arch +#Server = http://www.mirrorservice.org/sites/ftp.archlinux.org/$repo/os/$arch +#Server = http://arch.serverspace.co.uk/arch/$repo/os/$arch +#Server = http://archlinux.mirrors.uk2.net/$repo/os/$arch + +## United States +#Server = http://mirrors.abscission.net/archlinux/$repo/os/$arch +#Server = http://mirrors.acm.wpi.edu/archlinux/$repo/os/$arch +#Server = http://mirrors.advancedhosters.com/archlinux/$repo/os/$arch +#Server = http://mirrors.aggregate.org/archlinux/$repo/os/$arch +#Server = http://archlinux.surlyjake.com/archlinux/$repo/os/$arch +#Server = http://mirrors.cat.pdx.edu/archlinux/$repo/os/$arch +#Server = http://mirror.cc.columbia.edu/pub/linux/archlinux/$repo/os/$arch +#Server = http://mirrors.cdndepo.com/archlinux/$repo/os/$arch +#Server = https://mirrors.cdndepo.com/archlinux/$repo/os/$arch +#Server = http://mirrors.cecsresearch.org/archlinux/$repo/os/$arch +#Server = http://cosmos.cites.illinois.edu/pub/archlinux/$repo/os/$arch +#Server = http://mirror.cs.pitt.edu/archlinux/$repo/os/$arch +#Server = http://mirror.es.its.nyu.edu/archlinux/$repo/os/$arch +#Server = http://mirrors.gigenet.com/archlinux/$repo/os/$arch +#Server = http://mirror.grig.io/archlinux/$repo/os/$arch +#Server = http://www.gtlib.gatech.edu/pub/archlinux/$repo/os/$arch +#Server = http://mirror.ancl.hawaii.edu/linux/archlinux/$repo/os/$arch +#Server = http://mirror.jmu.edu/pub/archlinux/$repo/os/$arch +#Server = http://mirrors.kernel.org/archlinux/$repo/os/$arch +#Server = https://mirrors.kernel.org/archlinux/$repo/os/$arch +#Server = http://mirror.us.leaseweb.net/archlinux/$repo/os/$arch +#Server = http://mirrors.liquidweb.com/archlinux/$repo/os/$arch +#Server = http://arch.localmsp.org/arch/$repo/os/$arch +#Server = https://arch.localmsp.org/arch/$repo/os/$arch +#Server = http://lug.mtu.edu/archlinux/$repo/os/$arch +#Server = http://mirror.metrocast.net/archlinux/$repo/os/$arch +#Server = http://mirror.nexcess.net/archlinux/$repo/os/$arch +#Server = http://ftp.osuosl.org/pub/archlinux/$repo/os/$arch +#Server = http://archlinux.pallissard.net/archlinux/$repo/os/$arch +#Server = http://mirror.rit.edu/archlinux/$repo/os/$arch +#Server = http://mirrors.rutgers.edu/archlinux/$repo/os/$arch +#Server = http://mirror.umd.edu/archlinux/$repo/os/$arch +#Server = http://mirror.vtti.vt.edu/archlinux/$repo/os/$arch +#Server = http://mirrors.xmission.com/archlinux/$repo/os/$arch +#Server = http://mirror.yellowfiber.net/archlinux/$repo/os/$arch + +## Vietnam +#Server = http://f.archlinuxvn.org/archlinux/$repo/os/$arch +#Server = http://mirror-fpt-telecom.fpt.net/archlinux/$repo/os/$arch + diff --git a/cdist/conf/type/__pacman_conf_integrate/files/options b/cdist/conf/type/__pacman_conf_integrate/files/options new file mode 100644 index 00000000..68273e49 --- /dev/null +++ b/cdist/conf/type/__pacman_conf_integrate/files/options @@ -0,0 +1,6 @@ +[options] +HoldPkg = pacman glibc +Architecture = auto +CheckSpace +SigLevel = Required DatabaseOptional +LocalFileSigLevel = Optional diff --git a/cdist/conf/type/__pacman_conf_integrate/files/pacman.conf.cdist b/cdist/conf/type/__pacman_conf_integrate/files/pacman.conf.cdist new file mode 100644 index 00000000..88e6e623 --- /dev/null +++ b/cdist/conf/type/__pacman_conf_integrate/files/pacman.conf.cdist @@ -0,0 +1,6 @@ +# +# cdist managed - do not change +# +Include = /etc/pacman.d/options +Include = /etc/pacman.d/repo_* +Include = /etc/pacman.d/plain_file_* diff --git a/cdist/conf/type/__pacman_conf_integrate/files/pacman.conf.pacman b/cdist/conf/type/__pacman_conf_integrate/files/pacman.conf.pacman new file mode 100644 index 00000000..f43fe397 --- /dev/null +++ b/cdist/conf/type/__pacman_conf_integrate/files/pacman.conf.pacman @@ -0,0 +1,99 @@ +# +# /etc/pacman.conf +# +# See the pacman.conf(5) manpage for option and repository directives + +# +# GENERAL OPTIONS +# +[options] +# The following paths are commented out with their default values listed. +# If you wish to use different paths, uncomment and update the paths. +#RootDir = / +#DBPath = /var/lib/pacman/ +#CacheDir = /var/cache/pacman/pkg/ +#LogFile = /var/log/pacman.log +#GPGDir = /etc/pacman.d/gnupg/ +HoldPkg = pacman glibc +#XferCommand = /usr/bin/curl -C - -f %u > %o +#XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u +#CleanMethod = KeepInstalled +#UseDelta = 0.7 +Architecture = auto + +# Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup +#IgnorePkg = +#IgnoreGroup = + +#NoUpgrade = +#NoExtract = + +# Misc options +#UseSyslog +#Color +#TotalDownload +CheckSpace +#VerbosePkgLists + +# By default, pacman accepts packages signed by keys that its local keyring +# trusts (see pacman-key and its man page), as well as unsigned packages. +SigLevel = Required DatabaseOptional +LocalFileSigLevel = Optional +#RemoteFileSigLevel = Required + +# NOTE: You must run `pacman-key --init` before first using pacman; the local +# keyring can then be populated with the keys of all official Arch Linux +# packagers with `pacman-key --populate archlinux`. + +# +# REPOSITORIES +# - can be defined here or included from another file +# - pacman will search repositories in the order defined here +# - local/custom mirrors can be added here or in separate files +# - repositories listed first will take precedence when packages +# have identical names, regardless of version number +# - URLs will have $repo replaced by the name of the current repo +# - URLs will have $arch replaced by the name of the architecture +# +# Repository entries are of the format: +# [repo-name] +# Server = ServerName +# Include = IncludePath +# +# The header [repo-name] is crucial - it must be present and +# uncommented to enable the repo. +# + +# The testing repositories are disabled by default. To enable, uncomment the +# repo name header and Include lines. You can add preferred servers immediately +# after the header, and they will be used before the default mirrors. + +#[testing] +#Include = /etc/pacman.d/mirrorlist + +[core] +Include = /etc/pacman.d/mirrorlist + +[extra] +Include = /etc/pacman.d/mirrorlist + +#[community-testing] +#Include = /etc/pacman.d/mirrorlist + +[community] +Include = /etc/pacman.d/mirrorlist + +# If you want to run 32 bit applications on your x86_64 system, +# enable the multilib repositories as required here. + +#[multilib-testing] +#Include = /etc/pacman.d/mirrorlist + +#[multilib] +#Include = /etc/pacman.d/mirrorlist + +# An example of a custom package repository. See the pacman manpage for +# tips on creating your own repositories. +#[custom] +#SigLevel = Optional TrustAll +#Server = file:///home/custompkgs diff --git a/cdist/conf/type/__pacman_conf_integrate/man.rst b/cdist/conf/type/__pacman_conf_integrate/man.rst new file mode 100644 index 00000000..6a856efe --- /dev/null +++ b/cdist/conf/type/__pacman_conf_integrate/man.rst @@ -0,0 +1,44 @@ +cdist-type__pacman_conf_integrate(7) +==================================== +Integrate default pacman.conf to cdist conform and vice versa + +Dominique Roux + + +DESCRIPTION +----------- +The type allows you to convert the default pacman.conf to a cdist conform one and vice versa + + +REQUIRED PARAMETERS +------------------- +None. + +OPTIONAL PARAMETERS +------------------- +state + 'present' or 'absent', defaults to 'present' + + +EXAMPLES +-------- + +.. code-block:: sh + + # Convert normal to cdist conform + __pacman_conf_integrate convert + + # Convert cdist conform to normal + __pacman_conf_integrate convert --state absent + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- grep(1) + + +COPYING +------- +Copyright \(C) 2015 Dominique Roux. 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/__pacman_conf_integrate/manifest b/cdist/conf/type/__pacman_conf_integrate/manifest new file mode 100644 index 00000000..1d02f3b3 --- /dev/null +++ b/cdist/conf/type/__pacman_conf_integrate/manifest @@ -0,0 +1,59 @@ +#!/bin/sh +# +# 2015 Dominique Roux (dominique.roux4 at gmail.com +# +# 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=$(cat $__object/parameter/state 2>/dev/null) + +path="/etc/" + +if [ "${state}" = "present" ]; then + __file /etc/pacman.conf\ + --owner root --group root --mode 644 --source $__type/files/pacman.conf.cdist + + __file /etc/pacman.d/options\ + --owner root --group root --mode 644 --source $__type/files/options + + __file /etc/pacman.d/repo_empty_placeholder\ + --owner root --group root --mode 644 + + __file /etc/pacman.d/plain_file_empty_placeholder\ + --owner root --group root --mode 644 + +elif [ "${state}" = "absent" ]; then + + __file /etc/pacman.conf\ + --owner root --group root --mode 644 --source $__type/files/pacman.conf.pacman + + __file /etc/pacman.d/mirrorlist\ + --owner root --group root --mode 644 --source $__type/files/mirrorlist + + __file /etc/pacman.d/options\ + --state absent + + __file /etc/pacman.d/repo_empty_placeholder\ + --state absent + + __file /etc/pacman.d/plain_file_empty_placeholder\ + --state absent + +else + + echo "ERROR: Unknown state: ${state}" >&2 + +fi diff --git a/cdist/conf/type/__pacman_conf_integrate/parameter/default/state b/cdist/conf/type/__pacman_conf_integrate/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__pacman_conf_integrate/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__pacman_conf_integrate/parameter/optional b/cdist/conf/type/__pacman_conf_integrate/parameter/optional new file mode 100644 index 00000000..ff72b5c7 --- /dev/null +++ b/cdist/conf/type/__pacman_conf_integrate/parameter/optional @@ -0,0 +1 @@ +state diff --git a/cdist/conf/type/__pf_apply/man.rst b/cdist/conf/type/__pf_apply/man.rst new file mode 100644 index 00000000..0b440e2d --- /dev/null +++ b/cdist/conf/type/__pf_apply/man.rst @@ -0,0 +1,53 @@ +cdist-type__pf_apply(7) +======================= +Apply pf(4) ruleset on \*BSD + +Jake Guffey + + +NAME +---- + + +DESCRIPTION +----------- +This type is used on \*BSD systems to manage the pf firewall's active ruleset. + + +REQUIRED PARAMETERS +------------------- +NONE + + +OPTIONAL PARAMETERS +------------------- +NONE + + +EXAMPLES +-------- + +.. code-block:: sh + + # Modify the ruleset on $__target_host: + __pf_ruleset --state present --source /my/pf/ruleset.conf + require="__pf_ruleset" \ + __pf_apply + + # Remove the ruleset on $__target_host (implies disabling pf(4): + __pf_ruleset --state absent + require="__pf_ruleset" \ + __pf_apply + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__pf_ruleset(7) `_ +- pf(4) + + +COPYING +------- +Copyright \(C) 2012 Jake Guffey. 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/__pf_apply/man.text b/cdist/conf/type/__pf_apply/man.text deleted file mode 100644 index 2e0d7802..00000000 --- a/cdist/conf/type/__pf_apply/man.text +++ /dev/null @@ -1,52 +0,0 @@ -cdist-type__pf_apply(7) -======================= -Jake Guffey - - -NAME ----- -cdist-type__pf_apply - Apply pf(4) ruleset on *BSD - - -DESCRIPTION ------------ -This type is used on *BSD systems to manage the pf firewall's active ruleset. - - -REQUIRED PARAMETERS -------------------- -NONE - - -OPTIONAL PARAMETERS -------------------- -NONE - - -EXAMPLES --------- - --------------------------------------------------------------------------------- -# Modify the ruleset on $__target_host: -__pf_ruleset --state present --source /my/pf/ruleset.conf -require="__pf_ruleset" \ - __pf_apply - -# Remove the ruleset on $__target_host (implies disabling pf(4): -__pf_ruleset --state absent -require="__pf_ruleset" \ - __pf_apply --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) -- cdist-type__pf_ruleset(7) -- pf(4) - - -COPYING -------- -Copyright \(C) 2012 Jake Guffey. 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/__pf_ruleset/man.text b/cdist/conf/type/__pf_ruleset/man.rst similarity index 57% rename from cdist/conf/type/__pf_ruleset/man.text rename to cdist/conf/type/__pf_ruleset/man.rst index 29efe065..b3e9b073 100644 --- a/cdist/conf/type/__pf_ruleset/man.text +++ b/cdist/conf/type/__pf_ruleset/man.rst @@ -1,27 +1,24 @@ cdist-type__pf_ruleset(7) ========================= +Copy a pf(4) ruleset to $__target_host + Jake Guffey -NAME ----- -cdist-type__pf_ruleset - Copy a pf(4) ruleset to $__target_host - - DESCRIPTION ----------- -This type is used on *BSD systems to manage the pf firewall's ruleset. +This type is used on \*BSD systems to manage the pf firewall's ruleset. REQUIRED PARAMETERS ------------------- -state:: +state Either "absent" (no ruleset at all) or "present", defaults to "present". OPTIONAL PARAMETERS ------------------- -source:: +source If supplied, use to define the ruleset to load onto the $__target_host for pf(4). Note that this type is almost useless without a ruleset defined, but it's technically not needed, e.g. for the case of disabling the firewall temporarily. @@ -30,19 +27,18 @@ source:: EXAMPLES -------- --------------------------------------------------------------------------------- -# Remove the current ruleset in place -__pf_ruleset --state absent +.. code-block:: sh -# Enable the firewall with the ruleset defined in $__manifest/files/pf.conf -__pf_ruleset --state present --source $__manifest/files/pf.conf + # Remove the current ruleset in place + __pf_ruleset --state absent --------------------------------------------------------------------------------- + # Enable the firewall with the ruleset defined in $__manifest/files/pf.conf + __pf_ruleset --state present --source $__manifest/files/pf.conf SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ - pf(4) diff --git a/cdist/conf/type/__postfix/man.text b/cdist/conf/type/__postfix/man.rst similarity index 66% rename from cdist/conf/type/__postfix/man.text rename to cdist/conf/type/__postfix/man.rst index 1a91723a..d10a9960 100644 --- a/cdist/conf/type/__postfix/man.text +++ b/cdist/conf/type/__postfix/man.rst @@ -1,13 +1,10 @@ cdist-type__postfix(7) ====================== +Install postfix + Steven Armstrong -NAME ----- -cdist-type__postfix - install postfix - - DESCRIPTION ----------- This space intentionally left blank. @@ -26,14 +23,14 @@ None. EXAMPLES -------- --------------------------------------------------------------------------------- -__postfix --------------------------------------------------------------------------------- +.. code-block:: sh + + __postfix SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__postfix/manifest b/cdist/conf/type/__postfix/manifest index 52a13919..43443e1e 100755 --- a/cdist/conf/type/__postfix/manifest +++ b/cdist/conf/type/__postfix/manifest @@ -1,6 +1,6 @@ #!/bin/sh # -# 2012 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012-2014 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -22,7 +22,7 @@ os=$(cat "$__global/explorer/os") case "$os" in - ubuntu|debian|archlinux|suse) + ubuntu|debian|archlinux|suse|centos|devuan) __package postfix --state present ;; *) diff --git a/cdist/conf/type/__postfix_master/man.text b/cdist/conf/type/__postfix_master/man.rst similarity index 51% rename from cdist/conf/type/__postfix_master/man.text rename to cdist/conf/type/__postfix_master/man.rst index 0ec78752..4853e687 100644 --- a/cdist/conf/type/__postfix_master/man.text +++ b/cdist/conf/type/__postfix_master/man.rst @@ -1,13 +1,10 @@ cdist-type__postfix_master(7) ============================= +Configure postfix master.cf + Steven Armstrong -NAME ----- -cdist-type__postfix_master - configure postfix master.cf - - DESCRIPTION ----------- See master(5) for more information. @@ -15,54 +12,62 @@ See master(5) for more information. REQUIRED PARAMETERS ------------------- -type:: +type See master(5) -command:: +command See master(5) BOOLEAN PARAMETERS ------------------ -noreload:: +noreload don't reload postfix after changes OPTIONAL PARAMETERS ------------------- -state:: +state present or absent, defaults to present -service:: -private:: -unpriv:: -chroot:: -wakeup:: -maxproc:: -option:: + +service + +private + +unpriv + +chroot + +wakeup + +maxproc + +option Pass an option to a service. Same as using -o in master.cf. Can be specified multiple times. -comment:: + +comment a textual comment to add with the master.cf entry EXAMPLES -------- --------------------------------------------------------------------------------- -__postfix_master smtp --type inet --command smtpd +.. code-block:: sh -__postfix_master smtp --type inet --chroot y --command smtpd \ - --option smtpd_enforce_tls=yes \ - --option smtpd_sasl_auth_enable=yes \ - --option smtpd_client_restrictions=permit_sasl_authenticated,reject + __postfix_master smtp --type inet --command smtpd -__postfix_master submission --type inet --command smtpd \ - --comment "Run alternative smtp on submission port" --------------------------------------------------------------------------------- + __postfix_master smtp --type inet --chroot y --command smtpd \ + --option smtpd_enforce_tls=yes \ + --option smtpd_sasl_auth_enable=yes \ + --option smtpd_client_restrictions=permit_sasl_authenticated,reject + + __postfix_master submission --type inet --command smtpd \ + --comment "Run alternative smtp on submission port" SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ - master(5) diff --git a/cdist/conf/type/__postfix_master/manifest b/cdist/conf/type/__postfix_master/manifest index 87e2329b..3d82c526 100755 --- a/cdist/conf/type/__postfix_master/manifest +++ b/cdist/conf/type/__postfix_master/manifest @@ -1,6 +1,6 @@ #!/bin/sh # -# 2012 - 2013 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012-2014 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -22,7 +22,7 @@ os=$(cat "$__global/explorer/os") case "$os" in - ubuntu|debian|archlinux) + ubuntu|debian|archlinux|centos|devuan) : ;; *) diff --git a/cdist/conf/type/__postfix_postconf/explorer/value b/cdist/conf/type/__postfix_postconf/explorer/value index e08c6da6..d451bce6 100755 --- a/cdist/conf/type/__postfix_postconf/explorer/value +++ b/cdist/conf/type/__postfix_postconf/explorer/value @@ -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. # @@ -22,7 +22,7 @@ os=$("$__explorer/os") case "$os" in - ubuntu|debian|archlinux|suse) + ubuntu|debian|archlinux|suse|centos|devuan) : ;; *) diff --git a/cdist/conf/type/__postfix_postconf/gencode-remote b/cdist/conf/type/__postfix_postconf/gencode-remote index 43c0482e..b3557640 100755 --- a/cdist/conf/type/__postfix_postconf/gencode-remote +++ b/cdist/conf/type/__postfix_postconf/gencode-remote @@ -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. # @@ -21,7 +21,7 @@ os=$(cat "$__global/explorer/os") case "$os" in - ubuntu|debian|archlinux|suse) + ubuntu|debian|archlinux|suse|centos|devuan) : ;; *) diff --git a/cdist/conf/type/__postfix_postconf/man.text b/cdist/conf/type/__postfix_postconf/man.rst similarity index 64% rename from cdist/conf/type/__postfix_postconf/man.text rename to cdist/conf/type/__postfix_postconf/man.rst index 727637b1..e07e136f 100644 --- a/cdist/conf/type/__postfix_postconf/man.text +++ b/cdist/conf/type/__postfix_postconf/man.rst @@ -1,13 +1,10 @@ cdist-type__postfix_postconf(7) =============================== +Configure postfix main.cf + Steven Armstrong -NAME ----- -cdist-type__postfix_postconf - configure postfix main.cf - - DESCRIPTION ----------- See postconf(5) for possible keys and values. @@ -18,30 +15,29 @@ It does not make changes to /etc/postfix/main.cf itself. REQUIRED PARAMETERS ------------------- -value:: +value the value for the postfix parameter OPTIONAL PARAMETERS ------------------- -key:: +key the name of the parameter. Defaults to __object_id EXAMPLES -------- --------------------------------------------------------------------------------- -__postfix_postconf mydomain --value somedomain.com +.. code-block:: sh -__postfix_postconf bind-to-special-ip --key smtp_bind_address --value 127.0.0.5 + __postfix_postconf mydomain --value somedomain.com --------------------------------------------------------------------------------- + __postfix_postconf bind-to-special-ip --key smtp_bind_address --value 127.0.0.5 SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ - postconf(5) diff --git a/cdist/conf/type/__postfix_postconf/manifest b/cdist/conf/type/__postfix_postconf/manifest index 0dde64e9..dbce5364 100755 --- a/cdist/conf/type/__postfix_postconf/manifest +++ b/cdist/conf/type/__postfix_postconf/manifest @@ -1,6 +1,6 @@ #!/bin/sh # -# 2012 - 2013 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012-2014 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # diff --git a/cdist/conf/type/__postfix_postmap/man.text b/cdist/conf/type/__postfix_postmap/man.rst similarity index 62% rename from cdist/conf/type/__postfix_postmap/man.text rename to cdist/conf/type/__postfix_postmap/man.rst index 37060d04..ecee6722 100644 --- a/cdist/conf/type/__postfix_postmap/man.text +++ b/cdist/conf/type/__postfix_postmap/man.rst @@ -1,13 +1,10 @@ cdist-type__postfix_postmap(7) ============================== +Run postmap on the given file + Steven Armstrong -NAME ----- -cdist-type__postfix_postmap - run postmap on the given file - - DESCRIPTION ----------- This space intentionally left blank. @@ -26,14 +23,14 @@ None. EXAMPLES -------- --------------------------------------------------------------------------------- -__postfix_postmap /etc/postfix/generic --------------------------------------------------------------------------------- +.. code-block:: sh + + __postfix_postmap /etc/postfix/generic SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__postfix_postmap/manifest b/cdist/conf/type/__postfix_postmap/manifest index 0dde64e9..dbce5364 100755 --- a/cdist/conf/type/__postfix_postmap/manifest +++ b/cdist/conf/type/__postfix_postmap/manifest @@ -1,6 +1,6 @@ #!/bin/sh # -# 2012 - 2013 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012-2014 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # diff --git a/cdist/conf/type/__postfix_reload/gencode-remote b/cdist/conf/type/__postfix_reload/gencode-remote index 5822f1e3..7323606c 100755 --- a/cdist/conf/type/__postfix_reload/gencode-remote +++ b/cdist/conf/type/__postfix_reload/gencode-remote @@ -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. # @@ -22,7 +22,7 @@ os=$(cat "$__global/explorer/os") case "$os" in - ubuntu|debian|archlinux) + ubuntu|debian|archlinux|centos|devuan) echo "postfix reload" ;; *) diff --git a/cdist/conf/type/__postfix_reload/man.text b/cdist/conf/type/__postfix_reload/man.rst similarity index 63% rename from cdist/conf/type/__postfix_reload/man.text rename to cdist/conf/type/__postfix_reload/man.rst index c63356b5..c5101953 100644 --- a/cdist/conf/type/__postfix_reload/man.text +++ b/cdist/conf/type/__postfix_reload/man.rst @@ -1,13 +1,10 @@ cdist-type__postfix_reload(7) ============================= +Tell postfix to reload its configuration + Steven Armstrong -NAME ----- -cdist-type__postfix_reload - tell postfix to reload its configuration - - DESCRIPTION ----------- This space intentionally left blank. @@ -26,14 +23,14 @@ None. EXAMPLES -------- --------------------------------------------------------------------------------- -__postfix_reload --------------------------------------------------------------------------------- +.. code-block:: sh + + __postfix_reload SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__postfix_reload/manifest b/cdist/conf/type/__postfix_reload/manifest index 0dde64e9..dbce5364 100755 --- a/cdist/conf/type/__postfix_reload/manifest +++ b/cdist/conf/type/__postfix_reload/manifest @@ -1,6 +1,6 @@ #!/bin/sh # -# 2012 - 2013 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012-2014 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # diff --git a/cdist/conf/type/__postgres_database/man.text b/cdist/conf/type/__postgres_database/man.rst similarity index 60% rename from cdist/conf/type/__postgres_database/man.text rename to cdist/conf/type/__postgres_database/man.rst index c7c0d3cd..152ee910 100644 --- a/cdist/conf/type/__postgres_database/man.text +++ b/cdist/conf/type/__postgres_database/man.rst @@ -1,13 +1,10 @@ cdist-type__postgres_database(7) ================================ +Create/drop postgres databases + Steven Armstrong -NAME ----- -cdist-type__postgres_database - create/drop postgres databases - - DESCRIPTION ----------- This cdist type allows you to create or drop postgres databases. @@ -15,25 +12,25 @@ This cdist type allows you to create or drop postgres databases. OPTIONAL PARAMETERS ------------------- -state:: +state either 'present' or 'absent', defaults to 'present'. -owner:: +owner the role owning this database EXAMPLES -------- --------------------------------------------------------------------------------- -__postgres_database mydbname --owner mydbusername --------------------------------------------------------------------------------- +.. code-block:: sh + + __postgres_database mydbname --owner mydbusername SEE ALSO -------- -- cdist-type(7) -- cdist-type__postgres_role(7) +- `cdist-type(7) `_ +- `cdist-type__postgres_role(7) `_ COPYING diff --git a/cdist/conf/type/__postgres_role/man.text b/cdist/conf/type/__postgres_role/man.rst similarity index 59% rename from cdist/conf/type/__postgres_role/man.text rename to cdist/conf/type/__postgres_role/man.rst index ac87754b..6384568f 100644 --- a/cdist/conf/type/__postgres_role/man.text +++ b/cdist/conf/type/__postgres_role/man.rst @@ -1,13 +1,10 @@ cdist-type__postgres_role(7) ============================ +Manage postgres roles + Steven Armstrong -NAME ----- -cdist-type__postgres_role - manage postgres roles - - DESCRIPTION ----------- This cdist type allows you to create or drop postgres roles. @@ -15,43 +12,43 @@ This cdist type allows you to create or drop postgres roles. OPTIONAL PARAMETERS ------------------- -state:: +state Either "present" or "absent", defaults to "present" All other parameters map directly to the corresponding postgres createrole parameters. -password:: +password BOOLEAN PARAMETERS ------------------ All parameter map directly to the corresponding postgres createrole parameters. -login:: -createdb:: -createrole:: -superuser:: -inherit:: +login +createdb +createrole +superuser +inherit EXAMPLES -------- --------------------------------------------------------------------------------- -__postgres_role myrole +.. code-block:: sh -__postgres_role myrole --password 'secret' + __postgres_role myrole -__postgres_role admin --password 'very-secret' --superuser + __postgres_role myrole --password 'secret' -__postgres_role dbcustomer --password 'bla' --createdb --------------------------------------------------------------------------------- + __postgres_role admin --password 'very-secret' --superuser + + __postgres_role dbcustomer --password 'bla' --createdb SEE ALSO -------- -- cdist-type(7) -- cdist-type__postgres_database(7) +- `cdist-type(7) `_ +- `cdist-type__postgres_database(7) `_ - http://www.postgresql.org/docs/current/static/sql-createrole.html diff --git a/cdist/conf/type/__process/man.rst b/cdist/conf/type/__process/man.rst new file mode 100644 index 00000000..09032a1a --- /dev/null +++ b/cdist/conf/type/__process/man.rst @@ -0,0 +1,67 @@ +cdist-type__process(7) +====================== +Start or stop process + +Nico Schottelius + + +DESCRIPTION +----------- +This cdist type allows you to define the state of a process. + + +OPTIONAL PARAMETERS +------------------- +state + Either "present" or "absent", defaults to "present" + +name + Process name to match on when using pgrep -f -x. + + This is useful, if the name starts with a "/", + because the leading slash is stripped away from + the object id by cdist. + +stop + Executable to use for stopping the process. + +start + Executable to use for starting the process. + + +EXAMPLES +-------- + +.. code-block:: sh + + # Start if not running + __process /usr/sbin/syslog-ng --state present + + # Start if not running with a different binary + __process /usr/sbin/nginx --state present --start "/etc/rc.d/nginx start" + + # Stop the process using kill (the type default) - DO NOT USE THIS + __process /usr/sbin/sshd --state absent + + # Stop the process using /etc/rc.d/sshd stop - THIS ONE NOT AS WELL + __process /usr/sbin/sshd --state absent --stop "/etc/rc.d/sshd stop" + + # Ensure cups is running, which runs with -C ...: + __process cups --start "/etc/rc.d/cups start" --state present \ + --name "/usr/sbin/cupsd -C /etc/cups/cupsd.conf" + + # Ensure rpc.statd is running (which usually runs with -L) using a regexp + __process rpcstatd --state present --start "/etc/init.d/statd start" \ + --name "rpc.statd.*" + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__start_on_boot(7) `_ + + +COPYING +------- +Copyright \(C) 2011-2012 Nico Schottelius. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__process/man.text b/cdist/conf/type/__process/man.text deleted file mode 100644 index 2fdd27aa..00000000 --- a/cdist/conf/type/__process/man.text +++ /dev/null @@ -1,70 +0,0 @@ -cdist-type__process(7) -====================== -Nico Schottelius - - -NAME ----- -cdist-type__process - Start or stop process - - -DESCRIPTION ------------ -This cdist type allows you to define the state of a process. - - -OPTIONAL PARAMETERS -------------------- -state:: - Either "present" or "absent", defaults to "present" - -name:: - Process name to match on when using pgrep -f -x. - - This is useful, if the name starts with a "/", - because the leading slash is stripped away from - the object id by cdist. - -stop:: - Executable to use for stopping the process. - -start:: - Executable to use for starting the process. - - -EXAMPLES --------- - --------------------------------------------------------------------------------- -# Start if not running -__process /usr/sbin/syslog-ng --state present - -# Start if not running with a different binary -__process /usr/sbin/nginx --state present --start "/etc/rc.d/nginx start" - -# Stop the process using kill (the type default) - DO NOT USE THIS -__process /usr/sbin/sshd --state absent - -# Stop the process using /etc/rc.d/sshd stop - THIS ONE NOT AS WELL -__process /usr/sbin/sshd --state absent --stop "/etc/rc.d/sshd stop" - -# Ensure cups is running, which runs with -C ...: -__process cups --start "/etc/rc.d/cups start" --state present \ - --name "/usr/sbin/cupsd -C /etc/cups/cupsd.conf" - -# Ensure rpc.statd is running (which usually runs with -L) using a regexp -__process rpcstatd --state present --start "/etc/init.d/statd start" \ - --name "rpc.statd.*" --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) -- cdist-type__start_on_boot(7) - - -COPYING -------- -Copyright \(C) 2011-2012 Nico Schottelius. Free use of this software is -granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__pyvenv/explorer/group b/cdist/conf/type/__pyvenv/explorer/group new file mode 100755 index 00000000..ff072c5e --- /dev/null +++ b/cdist/conf/type/__pyvenv/explorer/group @@ -0,0 +1,5 @@ +#!/bin/sh + +destination="/$__object_id" + +stat --print "%G" ${destination} 2>/dev/null || exit 0 diff --git a/cdist/conf/type/__pyvenv/explorer/owner b/cdist/conf/type/__pyvenv/explorer/owner new file mode 100755 index 00000000..b77e3c6e --- /dev/null +++ b/cdist/conf/type/__pyvenv/explorer/owner @@ -0,0 +1,5 @@ +#!/bin/sh + +destination="/$__object_id" + +stat --print "%U" ${destination} 2>/dev/null || exit 0 diff --git a/cdist/conf/type/__pyvenv/explorer/state b/cdist/conf/type/__pyvenv/explorer/state new file mode 100755 index 00000000..ffe3cbbd --- /dev/null +++ b/cdist/conf/type/__pyvenv/explorer/state @@ -0,0 +1,9 @@ +#!/bin/sh + +destination="/$__object_id" + +if [ -d "$destination" ]; then + echo present +else + echo absent +fi diff --git a/cdist/conf/type/__pyvenv/gencode-remote b/cdist/conf/type/__pyvenv/gencode-remote new file mode 100755 index 00000000..907e0ff6 --- /dev/null +++ b/cdist/conf/type/__pyvenv/gencode-remote @@ -0,0 +1,67 @@ +#!/bin/sh +# +# 2016 Darko Poljak (darko.poljak at gmail.com) +# +# 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_is="$(cat "$__object/explorer/state")" +owner_is="$(cat "$__object/explorer/owner")" +group_is="$(cat "$__object/explorer/group")" + +state_should="$(cat "$__object/parameter/state")" + +owner="$(cat "$__object/parameter/owner")" +group="$(cat "$__object/parameter/group")" +mode="$(cat "$__object/parameter/mode")" + +[ "$state_should" = "$state_is" -a \ + "$owner" = "$owner_is" -a \ + "$group" = "$group_is" -a \ + -n "$mode" ] && exit 0 + +destination="/$__object_id" +venvparams="$(cat "$__object/parameter/venvparams")" +pyvenvparam="$__object/parameter/pyvenv" +if [ -f "$pyvenvparam" ] +then + pyvenv=$(cat "$pyvenvparam") +else + pyvenv="pyvenv" +fi + +case $state_should in + present) + if [ "$state_should" != "$state_is" ]; then + echo $pyvenv $venvparams "$destination" + fi + if [ \( -n "$owner" -a "$owner_is" != "$owner" \) -o \ + \( -n "$group" -a "$group_is" != "$group" \) ]; then + echo chown -R "${owner}:${group}" "$destination" + fi + if [ -n "$mode" ]; then + echo chmod -R "$mode" "$destination" + fi + ;; + absent) + ;; + + *) + echo "Unknown state: $state_should" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__pyvenv/man.rst b/cdist/conf/type/__pyvenv/man.rst new file mode 100755 index 00000000..bdc1166c --- /dev/null +++ b/cdist/conf/type/__pyvenv/man.rst @@ -0,0 +1,78 @@ +cdist-type__pyvenv(7) +===================== +Create or remove python virtual environment + +Darko Poljak + + +DESCRIPTION +----------- +This cdist type allows you to create or remove python virtual +environment using pyvenv. +It assumes pyvenv is already installed. Concrete package depends +on concrete OS and/or OS version/distribution. +Ensure this for e.g. in your init manifest as in the following example: + +.. code-block sh + + case "$__target_host" in + localhost) + __package python3-venv --state present + require="__package/python3-venv" __pyvenv /home/darko/testenv --pyvenv "pyvenv-3.4" --owner darko --group darko --mode 740 --state present + require="__pyvenv/home/darko/testenv" __package_pip docopt --pip /home/darko/testenv/bin/pip --runas darko --state present + ;; + esac + + +REQUIRED PARAMETERS +------------------- +None + +OPTIONAL PARAMETERS +------------------- +state + Either "present" or "absent", defaults to "present" + +group + Group to chgrp to + +mode + Unix permissions, suitable for chmod + +owner + User to chown to + +pyvenv + Use this specific pyvenv + +venvparams + Specific parameters to pass to pyvenv invocation + + +EXAMPLES +-------- + +.. code-block:: sh + + __pyvenv /home/services/djangoenv + + # Use specific pyvenv + __pyvenv /home/foo/fooenv --pyvenv /usr/local/bin/pyvenv-3.4 + + # Create python virtualenv for user foo. + __pyvenv /home/foo/fooenv --group foo --user foo + + # Create python virtualenv with specific parameters. + __pyvenv /home/services/djangoenv --venvparams "--copies --system-site-packages" + + +SEE ALSO +-------- +- `cdist-type(7) `_ + + +COPYING +------- +Copyright \(C) 2016 Darko Poljak. 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/__pyvenv/manifest b/cdist/conf/type/__pyvenv/manifest new file mode 100755 index 00000000..3e41ad04 --- /dev/null +++ b/cdist/conf/type/__pyvenv/manifest @@ -0,0 +1,46 @@ +#!/bin/sh +# +# 2016 Darko Poljak (darko.poljak at gmail.com) +# +# 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 . +# + +# It assumes pyvenv is already installed. Concrete packages +# or installation procedures depend on concrete OS and/or OS +# version/distribution. + +state_should="$(cat "$__object/parameter/state")" +owner="$(cat "$__object/parameter/owner")" +group="$(cat "$__object/parameter/group")" +mode="$(cat "$__object/parameter/mode")" + +case "$state_should" in + present) + : + ;; + + absent) + __directory "$__object_id" --state absent \ + --owner "$owner" \ + --group "$group" \ + --mode "$mode" + ;; + + *) + echo "Unknown state: $state_should" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__pyvenv/parameter/default/group b/cdist/conf/type/__pyvenv/parameter/default/group new file mode 100755 index 00000000..8b137891 --- /dev/null +++ b/cdist/conf/type/__pyvenv/parameter/default/group @@ -0,0 +1 @@ + diff --git a/cdist/conf/type/__pyvenv/parameter/default/mode b/cdist/conf/type/__pyvenv/parameter/default/mode new file mode 100755 index 00000000..8b137891 --- /dev/null +++ b/cdist/conf/type/__pyvenv/parameter/default/mode @@ -0,0 +1 @@ + diff --git a/cdist/conf/type/__pyvenv/parameter/default/owner b/cdist/conf/type/__pyvenv/parameter/default/owner new file mode 100755 index 00000000..8b137891 --- /dev/null +++ b/cdist/conf/type/__pyvenv/parameter/default/owner @@ -0,0 +1 @@ + diff --git a/cdist/conf/type/__pyvenv/parameter/default/state b/cdist/conf/type/__pyvenv/parameter/default/state new file mode 100755 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__pyvenv/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__pyvenv/parameter/default/venvparams b/cdist/conf/type/__pyvenv/parameter/default/venvparams new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/cdist/conf/type/__pyvenv/parameter/default/venvparams @@ -0,0 +1 @@ + diff --git a/cdist/conf/type/__pyvenv/parameter/optional b/cdist/conf/type/__pyvenv/parameter/optional new file mode 100755 index 00000000..ed2218b1 --- /dev/null +++ b/cdist/conf/type/__pyvenv/parameter/optional @@ -0,0 +1,6 @@ +state +group +owner +mode +venvparams +pyvenv diff --git a/cdist/conf/type/__qemu_img/gencode-remote b/cdist/conf/type/__qemu_img/gencode-remote index 6e4bb4d0..bffedd26 100644 --- a/cdist/conf/type/__qemu_img/gencode-remote +++ b/cdist/conf/type/__qemu_img/gencode-remote @@ -1,3 +1,5 @@ +#!/bin/sh +# ################################################################################ # State: absent is handled by manifest - we need only to do stuff if image is # not existing and state != absent diff --git a/cdist/conf/type/__qemu_img/man.text b/cdist/conf/type/__qemu_img/man.rst similarity index 56% rename from cdist/conf/type/__qemu_img/man.text rename to cdist/conf/type/__qemu_img/man.rst index 0fe2bbec..598e06ab 100644 --- a/cdist/conf/type/__qemu_img/man.text +++ b/cdist/conf/type/__qemu_img/man.rst @@ -1,13 +1,10 @@ cdist-type__qemu_img(7) -======================== +======================= +Manage VM disk images + Nico Schottelius -NAME ----- -cdist-type__qemu_img - Manage VM disk images - - DESCRIPTION ----------- The qemu-img program is used to create qemu images for @@ -17,9 +14,9 @@ qemu and (qemu-)kvm. OPTIONAL PARAMETERS ------------------- -state:: +state Either "present" or "absent", defaults to "present" -size:: +size Size of the image in qemu-img compatible units. Required if state is "present". @@ -28,18 +25,18 @@ size:: EXAMPLES -------- --------------------------------------------------------------------------------- -# Create a 50G size image -__qemu_img /home/services/kvm/vm/myvmname/system-disk --size 50G +.. code-block:: sh -# Remove image -__qemu_img /home/services/kvm/vm/myoldvm/system-disk --state absent --------------------------------------------------------------------------------- + # Create a 50G size image + __qemu_img /home/services/kvm/vm/myvmname/system-disk --size 50G + + # Remove image + __qemu_img /home/services/kvm/vm/myoldvm/system-disk --state absent SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ - qemu-img(1) diff --git a/cdist/conf/type/__qemu_img/manifest b/cdist/conf/type/__qemu_img/manifest index bb2c9366..e0ff6e03 100644 --- a/cdist/conf/type/__qemu_img/manifest +++ b/cdist/conf/type/__qemu_img/manifest @@ -1,3 +1,5 @@ +#!/bin/sh +# ################################################################################ # Default settings # diff --git a/cdist/conf/type/__rbenv/man.text b/cdist/conf/type/__rbenv/man.rst similarity index 54% rename from cdist/conf/type/__rbenv/man.text rename to cdist/conf/type/__rbenv/man.rst index c6ed5de2..314507fe 100644 --- a/cdist/conf/type/__rbenv/man.text +++ b/cdist/conf/type/__rbenv/man.rst @@ -1,13 +1,10 @@ cdist-type__rbenv(7) ==================== +Manage rbenv installation + Nico Schottelius -NAME ----- -cdist-type__rbenv - Manage rbenv installation - - DESCRIPTION ----------- This cdist type allows you to manage rbenv installations. @@ -16,31 +13,31 @@ It also installs ruby-build. OPTIONAL PARAMETERS ------------------- -state:: +state Either "present" or "absent", defaults to "present" -owner:: +owner Which user should own the rbenv installation, defaults to root EXAMPLES -------- --------------------------------------------------------------------------------- -# Install rbenv including ruby-build for nico -__rbenv /home/nico +.. code-block:: sh -# Install rbenv including ruby-build for nico -__rbenv /home/nico --owner nico + # Install rbenv including ruby-build for nico + __rbenv /home/nico -# Bastian does not need rbenv anymore, he began to code C99 -__rbenv /home/bastian --state absent --------------------------------------------------------------------------------- + # 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) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__rsync/gencode-local b/cdist/conf/type/__rsync/gencode-local new file mode 100644 index 00000000..8d268d7e --- /dev/null +++ b/cdist/conf/type/__rsync/gencode-local @@ -0,0 +1,39 @@ +#!/bin/sh +# +# 2015 Dominique Roux (dominique.roux4 at gmail.com) +# +# 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 . +# + +source=$(cat "$__object/parameter/source") +remote_user=$(cat "$__object/parameter/remote-user") + +if [ -f "$__object/parameter/destination" ]; then + destination=$(cat "$__object/parameter/destination") +else + destination="/$__object_id" +fi + +set -- +if [ -f "$__object/parameter/rsync-opts" ]; then + while read opts; do + set -- "$@" "--$opts" + done < $__object/parameter/rsync-opts +fi + +echo rsync -a \ + --no-owner --no-group \ + -q "$@" "${source}/" "${remote_user}@${__target_host}:${destination}" diff --git a/cdist/conf/type/__rsync/gencode-remote b/cdist/conf/type/__rsync/gencode-remote new file mode 100644 index 00000000..a1135ea6 --- /dev/null +++ b/cdist/conf/type/__rsync/gencode-remote @@ -0,0 +1,37 @@ +#!/bin/sh +# +# 2015 Dominique Roux (dominique.roux4 at gmail.com) +# +# 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 . +# + +if [ -f "$__object/parameter/destination" ]; then + destination=$(cat "$__object/parameter/destination") +else + destination="/$__object_id" +fi + +ownergroup="" +if [ -f "$__object/parameter/owner" ]; then + ownergroup=$(cat "$__object/parameter/owner") +fi +if [ -f "$__object/parameter/group" ]; then + ownergroup="${ownergroup}:$(cat "$__object/parameter/group")" +fi + +if [ "$ownergroup" ]; then + echo chown -R "$ownergroup" "$destination" +fi diff --git a/cdist/conf/type/__rsync/man.rst b/cdist/conf/type/__rsync/man.rst new file mode 100644 index 00000000..bc7b1bca --- /dev/null +++ b/cdist/conf/type/__rsync/man.rst @@ -0,0 +1,107 @@ +cdist-type__rsync(7) +==================== +Mirror directories using rsync + +Nico Schottelius + + +DESCRIPTION +----------- +WARNING: This type is of BETA quality: + +- it has not been tested widely +- interfaces *may* change +- if there is a better approach to solve the problem -> the type may even vanish + +If you are fine with these constraints, please read on. + + +This cdist type allows you to mirror local directories to the +target host using rsync. Rsync will be installed in the manifest of the type. +If group or owner are giveng, a recursive chown will be executed on the +target host. + +A slash will be appended to the source directory so that only the contents +of the directory are taken and not the directory name itself. + + +REQUIRED PARAMETERS +------------------- +source + Where to take files from + + +OPTIONAL PARAMETERS +------------------- +group + Group to chgrp to. + +owner + User to chown to. + +destination + Use this as the base destination instead of the object id + +remote-user + Use this user instead of the default "root" for rsync operations. + + +OPTIONAL MULTIPLE PARAMETERS +---------------------------- +rsync-opts + Use this option to give rsync options with. + See rsync(1) for available options. + Only "--" options are supported. + Write the options without the beginning "--" + Can be specified multiple times. + + +MESSAGES +-------- +NONE + + +EXAMPLES +-------- + +.. code-block:: sh + + # You can use any source directory + __rsync /tmp/testdir \ + --source /etc + + # Use source from type + __rsync /etc \ + --source "$__type/files/package" + + # Allow multiple __rsync objects to write to the same dir + __rsync mystuff \ + --destination /usr/local/bin \ + --source "$__type/files/package" + + __rsync otherstuff \ + --destination /usr/local/bin \ + --source "$__type/files/package2" + + # Use rsync option --exclude + __rsync /tmp/testdir \ + --source /etc \ + --rsync-opts exclude=sshd_conf + + # Use rsync with multiple options --exclude --dry-run + __rsync /tmp/testing \ + --source /home/tester \ + --rsync-opts exclude=id_rsa \ + --rsync-opts dry-run + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- rsync(1) + + +COPYING +------- +Copyright \(C) 2015 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/__rsync/manifest b/cdist/conf/type/__rsync/manifest new file mode 100644 index 00000000..0e4cc1f4 --- /dev/null +++ b/cdist/conf/type/__rsync/manifest @@ -0,0 +1,21 @@ +#!/bin/sh +# +# 2015 Dominique Roux (dominique.roux4 at gmail.com) +# +# 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 . +# + +__package rsync diff --git a/cdist/conf/type/__rsync/parameter/default/remote-user b/cdist/conf/type/__rsync/parameter/default/remote-user new file mode 100644 index 00000000..d8649da3 --- /dev/null +++ b/cdist/conf/type/__rsync/parameter/default/remote-user @@ -0,0 +1 @@ +root diff --git a/cdist/conf/type/__rsync/parameter/optional b/cdist/conf/type/__rsync/parameter/optional new file mode 100644 index 00000000..ac2b2390 --- /dev/null +++ b/cdist/conf/type/__rsync/parameter/optional @@ -0,0 +1,4 @@ +destination +owner +group +remote-user diff --git a/cdist/conf/type/__rsync/parameter/optional_multiple b/cdist/conf/type/__rsync/parameter/optional_multiple new file mode 100644 index 00000000..fdb7cd88 --- /dev/null +++ b/cdist/conf/type/__rsync/parameter/optional_multiple @@ -0,0 +1 @@ +rsync-opts diff --git a/cdist/conf/type/__rsync/parameter/required b/cdist/conf/type/__rsync/parameter/required new file mode 100644 index 00000000..5a18cd2f --- /dev/null +++ b/cdist/conf/type/__rsync/parameter/required @@ -0,0 +1 @@ +source diff --git a/cdist/conf/type/__rvm/man.text b/cdist/conf/type/__rvm/man.rst similarity index 52% rename from cdist/conf/type/__rvm/man.text rename to cdist/conf/type/__rvm/man.rst index 0408d125..8a3f72f5 100644 --- a/cdist/conf/type/__rvm/man.text +++ b/cdist/conf/type/__rvm/man.rst @@ -1,13 +1,10 @@ cdist-type__rvm(7) ================== +Install rvm for a given user + Evax Software -NAME ----- -cdist-type__rvm - Install rvm for a given user - - DESCRIPTION ----------- RVM is the Ruby enVironment Manager for the Ruby programming language. @@ -15,28 +12,28 @@ RVM is the Ruby enVironment Manager for the Ruby programming language. REQUIRED PARAMETERS ------------------- -state:: +state Either "present" or "absent", defaults to "present". EXAMPLES -------- --------------------------------------------------------------------------------- -# Install rvm for user billie -__rvm billie --state present +.. code-block:: sh -# Remove rvm -__rvm billie --state absent --------------------------------------------------------------------------------- + # Install rvm for user billie + __rvm billie --state present + + # Remove rvm + __rvm billie --state absent SEE ALSO -------- -- cdist-type(7) -- cdist-type__rvm_ruby(7) -- cdist-type__rvm_gemset(7) -- cdist-type__rvm_gem(7) +- `cdist-type(7) `_ +- `cdist-type__rvm_ruby(7) `_ +- `cdist-type__rvm_gemset(7) `_ +- `cdist-type__rvm_gem(7) `_ COPYING diff --git a/cdist/conf/type/__rvm_gem/man.rst b/cdist/conf/type/__rvm_gem/man.rst new file mode 100644 index 00000000..39d93065 --- /dev/null +++ b/cdist/conf/type/__rvm_gem/man.rst @@ -0,0 +1,54 @@ +cdist-type__rvm_gemset(7) +========================== +Manage Ruby gems through rvm + +Evax Software + + +DESCRIPTION +----------- +RVM is the Ruby enVironment Manager for the Ruby programming language. + + +REQUIRED PARAMETERS +------------------- +user + The remote user account to use +gemset + The gemset to use +state + Either "present" or "absent", defaults to "present". + +OPTIONAL PARAMETERS +------------------- +default + Make the selected gemset the default + +EXAMPLES +-------- + +.. code-block:: sh + + # Install the rails gem in gemset ruby-1.9.3-p0@myset for user bill + __rvm_gemset rails --gemset ruby-1.9.3-p0@myset --user bill --state present + + # Do the same and also make ruby-1.9.3-p0@myset the default gemset + __rvm_gemset rails --gemset ruby-1.9.3-p0@myset --user bill \ + --state present --default + + # Remove it + __rvm_ruby rails --gemset ruby-1.9.3-p0@myset --user bill --state absent + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__rvm(7) `_ +- `cdist-type__rvm_ruby(7) `_ +- `cdist-type__rvm_gemset(7) `_ + + +COPYING +------- +Copyright \(C) 2012 Evax Software. 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/__rvm_gem/man.text b/cdist/conf/type/__rvm_gem/man.text deleted file mode 100644 index d7eff3be..00000000 --- a/cdist/conf/type/__rvm_gem/man.text +++ /dev/null @@ -1,57 +0,0 @@ -cdist-type__rvm_gemset(7) -========================== -Evax Software - - -NAME ----- -cdist-type__rvm_gem - Manage Ruby gems through rvm - - -DESCRIPTION ------------ -RVM is the Ruby enVironment Manager for the Ruby programming language. - - -REQUIRED PARAMETERS -------------------- -user:: - The remote user account to use -gemset:: - The gemset to use -state:: - Either "present" or "absent", defaults to "present". - -OPTIONAL PARAMETERS -------------------- -default:: - Make the selected gemset the default - -EXAMPLES --------- - --------------------------------------------------------------------------------- -# Install the rails gem in gemset ruby-1.9.3-p0@myset for user bill -__rvm_gemset rails --gemset ruby-1.9.3-p0@myset --user bill --state present - -# Do the same and also make ruby-1.9.3-p0@myset the default gemset -__rvm_gemset rails --gemset ruby-1.9.3-p0@myset --user bill \ - --state present --default - -# Remove it -__rvm_ruby rails --gemset ruby-1.9.3-p0@myset --user bill --state absent --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) -- cdist-type__rvm(7) -- cdist-type__rvm_ruby(7) -- cdist-type__rvm_gemset(7) - - -COPYING -------- -Copyright \(C) 2012 Evax Software. 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/__rvm_gemset/man.rst b/cdist/conf/type/__rvm_gemset/man.rst new file mode 100644 index 00000000..422130cb --- /dev/null +++ b/cdist/conf/type/__rvm_gemset/man.rst @@ -0,0 +1,52 @@ +cdist-type__rvm_gemset(7) +========================== +Manage gemsets through rvm + +Evax Software + + +DESCRIPTION +----------- +RVM is the Ruby enVironment Manager for the Ruby programming language. + + +REQUIRED PARAMETERS +------------------- +user + The remote user account to use +state + Either "present" or "absent", defaults to "present". + +BOOLEAN PARAMETERS +------------------- +default + If present, set the given gemset as default. + + +EXAMPLES +-------- + +.. code-block:: sh + + # Install the gemset @myset for user charles on based on ruby-1.9.3-0 + __rvm_gemset ruby-1.9.3-p0@myset --user charles --state present + + # Do the same and make ruby-1.9.3-p0@myset the default gemset + __rvm_gemset ruby-1.9.3-p0@myset --user charles --state present --default + + # Remove the gemset @myset for user john + __rvm_ruby ruby-1.9.3-p0@myset --user john --state absent + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__rvm(7) `_ +- `cdist-type__rvm_ruby(7) `_ +- `cdist-type__rvm_gem(7) `_ + + +COPYING +------- +Copyright \(C) 2012 Evax Software. 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/__rvm_gemset/man.text b/cdist/conf/type/__rvm_gemset/man.text deleted file mode 100644 index e85425f3..00000000 --- a/cdist/conf/type/__rvm_gemset/man.text +++ /dev/null @@ -1,55 +0,0 @@ -cdist-type__rvm_gemset(7) -========================== -Evax Software - - -NAME ----- -cdist-type__rvm_gemset - Manage gemsets through rvm - - -DESCRIPTION ------------ -RVM is the Ruby enVironment Manager for the Ruby programming language. - - -REQUIRED PARAMETERS -------------------- -user:: - The remote user account to use -state:: - Either "present" or "absent", defaults to "present". - -BOOLEAN PARAMETERS -------------------- -default:: - If present, set the given gemset as default. - - -EXAMPLES --------- - --------------------------------------------------------------------------------- -# Install the gemset @myset for user charles on based on ruby-1.9.3-0 -__rvm_gemset ruby-1.9.3-p0@myset --user charles --state present - -# Do the same and make ruby-1.9.3-p0@myset the default gemset -__rvm_gemset ruby-1.9.3-p0@myset --user charles --state present --default - -# Remove the gemset @myset for user john -__rvm_ruby ruby-1.9.3-p0@myset --user john --state absent --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) -- cdist-type__rvm(7) -- cdist-type__rvm_ruby(7) -- cdist-type__rvm_gem(7) - - -COPYING -------- -Copyright \(C) 2012 Evax Software. 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/__rvm_ruby/man.rst b/cdist/conf/type/__rvm_ruby/man.rst new file mode 100644 index 00000000..dbb1c9a2 --- /dev/null +++ b/cdist/conf/type/__rvm_ruby/man.rst @@ -0,0 +1,53 @@ +cdist-type__rvm_ruby(7) +======================= +Manage ruby installations through rvm + +Evax Software + + +DESCRIPTION +----------- +RVM is the Ruby enVironment Manager for the Ruby programming language. + + +REQUIRED PARAMETERS +------------------- +user + The remote user account to use +state + Either "present" or "absent", defaults to "present". + + +BOOLEAN PARAMETERS +------------------ +default + Set the given version as default + + +EXAMPLES +-------- + +.. code-block:: sh + + # Install ruby 1.9.3 through rvm for user thelonious + __rvm_ruby ruby-1.9.3-p0 --user thelonious --state present + + # Install ruby 1.9.3 through rvm for user ornette and make it the default + __rvm_ruby ruby-1.9.3-p0 --user ornette --state present --default + + # Remove ruby 1.9.3 for user john + __rvm_ruby ruby-1.9.3-p0 --user john --state absent + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__rvm(7) `_ +- `cdist-type__rvm_gemset(7) `_ +- `cdist-type__rvm_gem(7) `_ + + +COPYING +------- +Copyright \(C) 2012 Evax Software. 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/__rvm_ruby/man.text b/cdist/conf/type/__rvm_ruby/man.text deleted file mode 100644 index 6419a4d4..00000000 --- a/cdist/conf/type/__rvm_ruby/man.text +++ /dev/null @@ -1,54 +0,0 @@ -cdist-type__rvm_ruby(7) -======================= -Evax Software - - -NAME ----- -cdist-type__rvm_ruby - Manage ruby installations through rvm - - -DESCRIPTION ------------ -RVM is the Ruby enVironment Manager for the Ruby programming language. - - -REQUIRED PARAMETERS -------------------- -user:: - The remote user account to use -state:: - Either "present" or "absent", defaults to "present". - -BOOLEAN PARAMETERS ------------------- -default: - Set the given version as default - -EXAMPLES --------- - --------------------------------------------------------------------------------- -# Install ruby 1.9.3 through rvm for user thelonious -__rvm_ruby ruby-1.9.3-p0 --user thelonious --state present - -# Install ruby 1.9.3 through rvm for user ornette and make it the default -__rvm_ruby ruby-1.9.3-p0 --user ornette --state present --default - -# Remove ruby 1.9.3 for user john -__rvm_ruby ruby-1.9.3-p0 --user john --state absent --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) -- cdist-type__rvm(7) -- cdist-type__rvm_gemset(7) -- cdist-type__rvm_gem(7) - - -COPYING -------- -Copyright \(C) 2012 Evax Software. 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_key/explorer/entry b/cdist/conf/type/__ssh_authorized_key/explorer/entry new file mode 100755 index 00000000..78031ab5 --- /dev/null +++ b/cdist/conf/type/__ssh_authorized_key/explorer/entry @@ -0,0 +1,26 @@ +#!/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 . +# + +# extract the keytype and base64 encoded key ignoring any options and comment +type_and_key="$(cat "$__object/parameter/key" | tr ' ' '\n' | awk '/^(ssh|ecdsa)-[^ ]+/ { printf $1" "; getline; printf $1 }')" +file="$(cat $__object/parameter/file)" + +# get any entries that match the type and key +grep ".*$type_and_key[ \n]" "$file" || true diff --git a/cdist/conf/type/__ssh_authorized_key/gencode-remote b/cdist/conf/type/__ssh_authorized_key/gencode-remote new file mode 100755 index 00000000..6bbfa269 --- /dev/null +++ b/cdist/conf/type/__ssh_authorized_key/gencode-remote @@ -0,0 +1,109 @@ +#!/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 . +# + +set -u + +remove_line() { + file="$1" + line="$2" + cat << DONE +tmpfile=\$(mktemp ${file}.cdist.XXXXXXXXXX) +# preserve ownership and permissions of existing file +if [ -f "$file" ]; then + cp -p "$file" "\$tmpfile" +fi +grep -v -F -x '$line' '$file' > \$tmpfile || true +mv -f "\$tmpfile" "$file" +DONE +} + +add_line() { + file="$1" + line="$2" + # escape single quotes + line_sanitised=$(echo "$line" | sed -e "s/'/'\"'\"'/g") + printf '%s' "printf '%s\n' '$line_sanitised' >> $file" +} + + +file="$(cat "$__object/parameter/file")" +mkdir "$__object/files" + +# Generate the entry as it should be +( + if [ -f "$__object/parameter/option" ]; then + # comma seperated list of options + options="$(cat "$__object/parameter/option" | tr '\n' ',')" + printf '%s ' "${options%*,}" + fi + if [ -f "$__object/parameter/comment" ]; then + # extract the keytype and base64 encoded key ignoring any options and comment + printf '%s ' "$(cat "$__object/parameter/key" | tr ' ' '\n' | awk '/^(ssh|ecdsa)-[^ ]+/ { printf $1" "; getline; printf $1 }')" + # override the comment with the one explicitly given + printf '%s' "$(cat "$__object/parameter/comment")" + else + printf '%s' "$(cat "$__object/parameter/key")" + fi + printf '\n' +) > "$__object/files/should" + +# Remove conflicting entries if any +if [ -s "$__object/explorer/entry" ]; then + # Note that the files have to be sorted for comparison with `comm`. + sort "$__object/explorer/entry" > "$__object/files/is" + comm -13 "$__object/files/should" "$__object/files/is" | { + while read entry; do + remove_line "$file" "$entry" + done + } +fi + +# Determine the current state +entry="$(cat "$__object/files/should")" +state_should="$(cat "$__object/parameter/state")" +num_existing_entries=$(grep -c -F -x "$entry" "$__object/explorer/entry" || true) +if [ $num_existing_entries -eq 1 ]; then + state_is="present" +else + # Posix grep does not define the -m option, so we can not remove a single + # occurence of a string from a file in the `remove_line` function. Instead + # _all_ occurences are removed. + # By using `comm` to detect conflicting entries this could lead to the + # situation that the key we want to add is actually removed. + # To workaround this we must treat 0 or more then 1 existing entries to + # mean current state is 'absent'. By doing this, the key is readded + # again after cleaning up conflicting entries. + state_is="absent" +fi + +# Manage the actual entry as it should be +if [ "$state_should" = "$state_is" ]; then + # Nothing to do + exit 0 +fi + +case "$state_should" in + present) + add_line "$file" "$entry" + ;; + absent) + remove_line "$file" "$entry" + ;; +esac diff --git a/cdist/conf/type/__ssh_authorized_key/man.rst b/cdist/conf/type/__ssh_authorized_key/man.rst new file mode 100644 index 00000000..984ea51b --- /dev/null +++ b/cdist/conf/type/__ssh_authorized_key/man.rst @@ -0,0 +1,64 @@ +cdist-type__ssh_authorized_key(7) +================================= +Manage a single ssh authorized key entry + +Steven Armstrong + + +DESCRIPTION +----------- +Manage a single authorized key entry in an authorized_key file. +This type was created to be used by the __ssh_authorized_keys type. + + +REQUIRED PARAMETERS +------------------- +file + the authorized_keys file to which the given key should be added + +key + a string containing the ssh keytype, base 64 encoded key and optional + trailing comment which shall be added to the given authorized_keys file. + + +OPTIONAL PARAMETERS +------------------- +comment + explicit comment instead of the one which may be trailing the given key + +option + an option to set for this authorized_key entry. + Can be specified multiple times. + See sshd(8) for available options. + +state + if the given keys should be 'present' or 'absent', defaults to 'present'. + + +EXAMPLES +-------- + +.. code-block:: sh + + __ssh_authorized_key some-id \ + --file "/home/user/.ssh/autorized_keys" \ + --key "$(cat ~/.ssh/id_rsa.pub)" + + __ssh_authorized_key some-id \ + --file "/home/user/.ssh/autorized_keys" \ + --key "$(cat ~/.ssh/id_rsa.pub)" \ + --option 'command="/path/to/script"' \ + --option 'environment="FOO=bar"' \ + --comment 'one to rule them all' + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist__ssh_authorized_keys(7) `_ +- sshd(8) + +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/__ssh_authorized_key/parameter/default/state b/cdist/conf/type/__ssh_authorized_key/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__ssh_authorized_key/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__ssh_authorized_key/parameter/optional b/cdist/conf/type/__ssh_authorized_key/parameter/optional new file mode 100644 index 00000000..89e8d966 --- /dev/null +++ b/cdist/conf/type/__ssh_authorized_key/parameter/optional @@ -0,0 +1,2 @@ +comment +state diff --git a/cdist/conf/type/__ssh_authorized_key/parameter/optional_multiple b/cdist/conf/type/__ssh_authorized_key/parameter/optional_multiple new file mode 100644 index 00000000..01925a15 --- /dev/null +++ b/cdist/conf/type/__ssh_authorized_key/parameter/optional_multiple @@ -0,0 +1 @@ +option diff --git a/cdist/conf/type/__ssh_authorized_key/parameter/required b/cdist/conf/type/__ssh_authorized_key/parameter/required new file mode 100644 index 00000000..d51426c3 --- /dev/null +++ b/cdist/conf/type/__ssh_authorized_key/parameter/required @@ -0,0 +1,2 @@ +file +key diff --git a/cdist/conf/type/__ssh_authorized_keys/explorer/file b/cdist/conf/type/__ssh_authorized_keys/explorer/file new file mode 100755 index 00000000..5a02721a --- /dev/null +++ b/cdist/conf/type/__ssh_authorized_keys/explorer/file @@ -0,0 +1,27 @@ +#!/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 . +# + +if [ -f "$__object/parameter/file" ]; then + cat "$__object/parameter/file" +else + owner="$(cat "$__object/parameter/owner" 2>/dev/null || echo "$__object_id")" + home=$(getent passwd "$owner" | cut -d':' -f 6) + echo "$home/.ssh/authorized_keys" +fi diff --git a/cdist/conf/type/__ssh_authorized_keys/explorer/group b/cdist/conf/type/__ssh_authorized_keys/explorer/group index cdea6fe7..72a4e314 100755 --- a/cdist/conf/type/__ssh_authorized_keys/explorer/group +++ b/cdist/conf/type/__ssh_authorized_keys/explorer/group @@ -18,5 +18,6 @@ # along with cdist. If not, see . # -gid="$("$__type_explorer/passwd" | cut -d':' -f 4)" +owner="$(cat "$__object/parameter/owner" 2>/dev/null || echo "$__object_id")" +gid="$(getent passwd "$owner" | cut -d':' -f 4)" getent group "$gid" || true diff --git a/cdist/conf/type/__ssh_authorized_keys/man.rst b/cdist/conf/type/__ssh_authorized_keys/man.rst new file mode 100644 index 00000000..0907c2b3 --- /dev/null +++ b/cdist/conf/type/__ssh_authorized_keys/man.rst @@ -0,0 +1,114 @@ +cdist-type__ssh_authorized_keys(7) +================================== +Manage ssh authorized_keys files + +Steven Armstrong + + +DESCRIPTION +----------- +Adds or removes ssh keys from a authorized_keys file. + +This type uses the __ssh_dot_ssh type to manage the directory containing +the authorized_keys file. You can disable this feature with the --noparent +boolean parameter. + +The existence, ownership and permissions of the authorized_keys file itself are +also managed. This can be disabled with the --nofile boolean parameter. It is +then left to the user to ensure that the file exists and that ownership and +permissions work with ssh. + + +REQUIRED PARAMETERS +------------------- +key + the ssh key which shall be added to this authorized_keys file. + Must be a string and can be specified multiple times. + + +OPTIONAL PARAMETERS +------------------- +comment + explicit comment instead of the one which may be trailing the given key + +file + an alternative destination file, defaults to ~$owner/.ssh/authorized_keys + +option + an option to set for all created authorized_key entries. + Can be specified multiple times. + See sshd(8) for available options. + +owner + the user owning the authorized_keys file, defaults to object_id. + +state + if the given keys should be 'present' or 'absent', defaults to 'present'. + + +BOOLEAN PARAMETERS +------------------ +noparent + don't create or change ownership and permissions of the directory containing + the authorized_keys file + +nofile + don't manage existence, ownership and permissions of the the authorized_keys + file + + +EXAMPLES +-------- + +.. code-block:: sh + + # add your ssh key to remote root's authorized_keys file + __ssh_authorized_keys root \ + --key "$(cat ~/.ssh/id_rsa.pub)" + + # allow key to login as user-name + __ssh_authorized_keys user-name \ + --key "ssh-rsa AXYZAAB3NzaC1yc2..." + + # allow key to login as user-name with options and expicit comment + __ssh_authorized_keys user-name \ + --key "ssh-rsa AXYZAAB3NzaC1yc2..." \ + --option no-agent-forwarding \ + --option 'from="*.example.com"' \ + --comment 'backup server' + + # same as above, but with explicit owner and two keys + # note that the options are set for all given keys + __ssh_authorized_keys some-fancy-id \ + --owner user-name \ + --key "ssh-rsa AXYZAAB3NzaC1yc2..." \ + --key "ssh-rsa AZXYAAB3NzaC1yc2..." \ + --option no-agent-forwarding \ + --option 'from="*.example.com"' \ + --comment 'backup server' + + # authorized_keys file in non standard location + __ssh_authorized_keys some-fancy-id \ + --file /etc/ssh/keys/user-name/authorized_keys \ + --owner user-name \ + --key "ssh-rsa AXYZAAB3NzaC1yc2..." + + # same as above, but directory and authorized_keys file is created elswhere + __ssh_authorized_keys some-fancy-id \ + --file /etc/ssh/keys/user-name/authorized_keys \ + --owner user-name \ + --noparent \ + --nofile \ + --key "ssh-rsa AXYZAAB3NzaC1yc2..." + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- sshd(8) + + +COPYING +------- +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/man.text b/cdist/conf/type/__ssh_authorized_keys/man.text deleted file mode 100644 index 9fd683fd..00000000 --- a/cdist/conf/type/__ssh_authorized_keys/man.text +++ /dev/null @@ -1,97 +0,0 @@ -cdist-type__ssh_authorized_keys(7) -================================== -Steven Armstrong - - -NAME ----- -cdist-type__ssh_authorized_keys - manage ssh authorized_keys files - - -DESCRIPTION ------------ -Adds or removes ssh keys from a authorized_keys file. - -This type also manages the directory containing the authorized_keys -file and sets strict ownership and permissions. You can disable this feature -with the --noparent boolean parameter. - -The existence, ownership and permissions of the authorized_keys file itself are -also managed. This can be disabled with the --nofile boolean parameter. It is -then left to the user to ensure that the file exists and that ownership and -permissions work with ssh. - - -REQUIRED PARAMETERS -------------------- -key:: - the ssh key which shall be added to this authorized_keys file. - Must be a string and can be specified multiple times. - - -OPTIONAL PARAMETERS -------------------- -owner:: - the user owning the authorized_keys file, defaults to object_id. - -state:: - if the given keys should be 'present' or 'absent', defaults to 'present'. - -file:: - an alternative destination file, defaults to ~$owner/.ssh/authorized_keys - - -BOOLEAN PARAMETERS ------------------- -noparent:: - don't create or change ownership and permissions of the directory containing - the authorized_keys file - -nofile:: - don't manage existence, ownership and permissions of the the authorized_keys - file - - -EXAMPLES --------- - --------------------------------------------------------------------------------- -# add your ssh key to remote root's authorized_keys file -__ssh_authorized_keys root \ - --key "$(cat ~/.ssh/id_rsa.pub)" - -# allow key to login as user-name -__ssh_authorized_keys user-name \ - --key "ssh-rsa AXYZAAB3NzaC1yc2..." - -# 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..." - -# same as above, but authorized_keys file in non standard location -__ssh_authorized_keys some-fancy-id \ - --file /etc/ssh/keys/user-name/authorized_keys \ - --owner user-name \ - --key "ssh-rsa AXYZAAB3NzaC1yc2..." - -# same as above, but directory and authorized_keys file is created elswhere -__ssh_authorized_keys some-fancy-id \ - --file /etc/ssh/keys/user-name/authorized_keys \ - --owner user-name \ - --noparent \ - --nofile \ - --key "ssh-rsa AXYZAAB3NzaC1yc2..." --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) - - -COPYING -------- -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 1c9df208..6a536e1b 100755 --- a/cdist/conf/type/__ssh_authorized_keys/manifest +++ b/cdist/conf/type/__ssh_authorized_keys/manifest @@ -21,16 +21,7 @@ owner="$(cat "$__object/parameter/owner" 2>/dev/null || echo "$__object_id")" state="$(cat "$__object/parameter/state" 2>/dev/null)" -if [ -f "$__object/parameter/file" ]; then - file="$(cat "$__object/parameter/file")" -else - home="$(cut -d':' -f 6 "$__object/explorer/passwd")" - if [ -z "$home" ]; then - echo "Failed to get home directory from explorer." >&2 - exit 1 - fi - file="$home/.ssh/authorized_keys" -fi +file="$(cat "$__object/explorer/file")" if [ ! -f "$__object/parameter/noparent" -o ! -f "$__object/parameter/nofile" ]; then group="$(cut -d':' -f 1 "$__object/explorer/group")" @@ -40,12 +31,8 @@ if [ ! -f "$__object/parameter/noparent" -o ! -f "$__object/parameter/nofile" ]; fi if [ ! -f "$__object/parameter/noparent" ]; then - # Ensure that the directory in which the authorized_keys shall be exists and - # has the right permissions. - ssh_directory="${file%/*}" - __directory "$ssh_directory" --state present --parents \ - --owner "$owner" --group "$group" --mode 0700 - export require="__directory/$ssh_directory" + __ssh_dot_ssh "$owner" + export require="__ssh_dot_ssh/$owner" fi if [ ! -f "$__object/parameter/nofile" ]; then # Ensure that authorized_keys file exists and has the right permissions. @@ -54,6 +41,7 @@ if [ ! -f "$__object/parameter/noparent" -o ! -f "$__object/parameter/nofile" ]; --group "$group" \ --mode 0600 \ --state exists + export require="__file/$file" fi fi @@ -67,22 +55,25 @@ __block "$__object_name" \ --text - << DONE remove legacy block DONE +export require="__block/$__object_name" _cksum() { echo "$1" | cksum | cut -d' ' -f 1 } while read key; do - cksum_key="$(_cksum "$key")" - line_id="${owner}-${cksum_key}" - - set -- "$line_id" + type_and_key="$(echo "$key" | tr ' ' '\n' | awk '/^(ssh|ecdsa)-[^ ]+/ { printf $1" "; getline; printf $1 }')" + object_id="$(_cksum "$file")-$(_cksum "$type_and_key")" + set -- "$object_id" set -- "$@" --file "$file" - set -- "$@" --regex ".*$key.*" - if [ "$state" = 'present' ]; then - set -- "$@" --line "$key" - fi + set -- "$@" --key "$key" set -- "$@" --state "$state" - # Ensure __line does not read stdin - require="__block/$__object_name" __line "$@" < /dev/null + if [ -f "$__object/parameter/option" ]; then + set -- "$@" --option "$(cat "$__object/parameter/option")" + fi + if [ -f "$__object/parameter/comment" ]; then + set -- "$@" --comment "$(cat "$__object/parameter/comment")" + fi + # Ensure __ssh_authorized_key does not read stdin + __ssh_authorized_key "$@" < /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 989750b3..21f9bc29 100644 --- a/cdist/conf/type/__ssh_authorized_keys/parameter/optional +++ b/cdist/conf/type/__ssh_authorized_keys/parameter/optional @@ -1,3 +1,5 @@ +comment +file +option owner state -file diff --git a/cdist/conf/type/__ssh_dot_ssh/explorer/group b/cdist/conf/type/__ssh_dot_ssh/explorer/group new file mode 100755 index 00000000..cdea6fe7 --- /dev/null +++ b/cdist/conf/type/__ssh_dot_ssh/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/explorer/passwd b/cdist/conf/type/__ssh_dot_ssh/explorer/passwd similarity index 90% rename from cdist/conf/type/__ssh_authorized_keys/explorer/passwd rename to cdist/conf/type/__ssh_dot_ssh/explorer/passwd index e6352ee0..3fbad06f 100755 --- a/cdist/conf/type/__ssh_authorized_keys/explorer/passwd +++ b/cdist/conf/type/__ssh_dot_ssh/explorer/passwd @@ -1,6 +1,7 @@ #!/bin/sh # # 2012 Steven Armstrong (steven-cdist at armstrong.cc) +# 2014 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -18,6 +19,6 @@ # along with cdist. If not, see . # -owner="$(cat "$__object/parameter/owner" 2>/dev/null || echo "$__object_id")" +owner="$__object_id" getent passwd "$owner" || true diff --git a/cdist/conf/type/__ssh_dot_ssh/man.rst b/cdist/conf/type/__ssh_dot_ssh/man.rst new file mode 100644 index 00000000..1b84c924 --- /dev/null +++ b/cdist/conf/type/__ssh_dot_ssh/man.rst @@ -0,0 +1,46 @@ +cdist-type__ssh_dot_ssh(7) +========================== +Manage .ssh directory + +Nico Schottelius + + +NAME +---- + + +DESCRIPTION +----------- +Adds or removes .ssh directory to a user home. + +This type is being used by __ssh_authorized_keys. + + +OPTIONAL PARAMETERS +------------------- +state + if the directory should be 'present' or 'absent', defaults to 'present'. + + +EXAMPLES +-------- + +.. code-block:: sh + + # Ensure root has ~/.ssh with the right permissions + __ssh_dot_ssh root + + # Nico does not need ~/.ssh anymore + __ssh_dot_ssh nico --state absent + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__ssh_authorized_keys(7) `_ + + +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/__ssh_dot_ssh/manifest b/cdist/conf/type/__ssh_dot_ssh/manifest new file mode 100755 index 00000000..4b797afb --- /dev/null +++ b/cdist/conf/type/__ssh_dot_ssh/manifest @@ -0,0 +1,44 @@ +#!/bin/sh +# +# 2012-2014 Steven Armstrong (steven-cdist at armstrong.cc) +# 2014 Nico Schottelius (nico-cdist at schottelius.org) +# +# This file is part of cdist. +# +# 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 . +# +# Hacked in Kalamata, Greece +# + +owner="$__object_id" +state="$(cat "$__object/parameter/state")" + +group="$(cut -d':' -f 1 "$__object/explorer/group")" +if [ -z "$group" ]; then + echo "Failed to get owners group from explorer." >&2 + exit 1 +fi + +home="$(cut -d':' -f 6 "$__object/explorer/passwd")" +if [ -z "$home" ]; then + echo "Failed to get home directory from explorer." >&2 + exit 1 +fi +ssh_directory="${home}/.ssh" + +# Ensure that the directory in which the authorized_keys shall be exists and +# has the right permissions. +__directory "$ssh_directory" \ + --state "$state" \ + --owner "$owner" --group "$group" --mode 0700 diff --git a/cdist/conf/type/__ssh_dot_ssh/parameter/default/state b/cdist/conf/type/__ssh_dot_ssh/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__ssh_dot_ssh/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__ssh_dot_ssh/parameter/optional b/cdist/conf/type/__ssh_dot_ssh/parameter/optional new file mode 100644 index 00000000..ff72b5c7 --- /dev/null +++ b/cdist/conf/type/__ssh_dot_ssh/parameter/optional @@ -0,0 +1 @@ +state diff --git a/cdist/conf/type/__staged_file/gencode-local b/cdist/conf/type/__staged_file/gencode-local new file mode 100755 index 00000000..1a236789 --- /dev/null +++ b/cdist/conf/type/__staged_file/gencode-local @@ -0,0 +1,99 @@ +#!/bin/sh +# +# 2015 Steven Armstrong (steven-cdist at armstrong.cc) +# 2015 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 . +# + +#set -x + +destination="$__object_id" +source="$(cat "$__object/parameter/source")" +cksum="$(cat "$__object/parameter/cksum")" +stage_dir="$(cat "$__object/parameter/stage-dir")" +state="$(cat "$__object/parameter/state")" +fetch_command="$(cat "$__object/parameter/fetch-command")" +stage_file="${stage_dir}/${destination}" +stage_file_dir="${stage_file%/*}" +source_file_name="${source##*/}" + +if [ "$state" = "absent" ]; then + # nothing to do + exit 0 +fi + +#printf 'set -x\n' + +if [ ! -d "$stage_dir" ]; then + printf 'mkdir -p "%s"\n' "$stage_dir" + printf 'chmod 700 "%s"\n' "$stage_dir" +fi + +if [ ! -d "$stage_file_dir" ]; then + printf 'mkdir -p "%s"\n' "$stage_file_dir" +fi + + +get_file() { + if [ -f "$__object/parameter/prepare-command" ]; then + fetch_and_prepare_file + else + fetch_file + fi +} + +fetch_file() { + printf "$fetch_command" "$source" + printf ' > "%s"\n' "$stage_file" +} + +fetch_and_prepare_file() { + printf 'tmpdir="$(mktemp -d --tmpdir="/tmp" "%s")"\n' "${__type##*/}.XXXXXXXXXX" + printf 'cd "$tmpdir"\n' + printf "$fetch_command > \"%s\"\n" "$source" "$source_file_name" + prepare_command="$(cat "$__object/parameter/prepare-command")" + printf "$prepare_command > \"%s\"\n" "$source_file_name" "$stage_file" + printf 'cd - >/dev/null\n' + printf 'rm -rf "$tmpdir"\n' +} + +cat << DONE +verify_cksum() { + cksum_is="\$(cksum "$stage_file" | cut -d' ' -f1,2)" + cksum_should="$(cat "$__object/parameter/cksum" | cut -d' ' -f1,2)" + if [ "\$cksum_is" = "\$cksum_should" ]; then + return 0 + else + return 1 + fi +} +DONE + +if [ ! -f "$stage_file" ]; then + get_file +else + printf 'verify_cksum || {\n' + get_file + printf '}\n' +fi + +cat << DONE +verify_cksum || { + echo "Failed to verify checksum for $__object_name" >&2 + exit 1 +} +DONE diff --git a/cdist/conf/type/__staged_file/man.rst b/cdist/conf/type/__staged_file/man.rst new file mode 100644 index 00000000..ed977b28 --- /dev/null +++ b/cdist/conf/type/__staged_file/man.rst @@ -0,0 +1,108 @@ +cdist-type__staged_file(7) +========================== +Manage staged files + +Steven Armstrong + + +DESCRIPTION +----------- +Manages a staged file that is downloaded on the server (the machine running +cdist) and then deployed to the target host using the __file type. + + +REQUIRED PARAMETERS +------------------- +source + the URL from which to retreive the source file. + e.g. + + * https://dl.bintray.com/mitchellh/consul/0.4.1_linux_amd64.zip + * file:///path/to/local/file + +cksum + the output of running the command: `cksum $source-file` + e.g.:: + + $ echo foobar > /tmp/foobar + $ cksum /tmp/foobar + 857691210 7 /tmp/foobar + + If either checksum or file size has changed the file will be + (re)fetched from the --source. The file name can be omitted and is + ignored if given. + + +OPTIONAL PARAMETERS +------------------- +fetch-command + the command used to fetch the staged file using printf formatting. + Where a single %s will be replaced with the value of the given --source + parameter. The --fetch-command is expected to output the fetched file to + stdout. + Defaults to 'curl -s -L "%s"'. + +group + see cdist-type__file + +owner + see cdist-type__file + +mode + see cdist-type__file + +prepare-command + the optional command used to prepare or preprocess the staged file for later + use by the file type. + If given, it must be a string in printf formatting where a single %s will + be replaced with the last segment (filename) of the value of the given + --source parameter. + It is executed in the same directory into which the fetched file has been + saved. The --prepare-command is expected to output the final file to stdout. + + So for example given a --source of https://example.com/my-zip.zip, and a + --prepare-command of 'unzip -p "%s"', the code `unzip -p "my-zip.zip"` will + be executed in the folder containing the downloaded file my-zip.zip. + A more complex example might be --prepare-command 'tar -xz "%s"; cat path/from/archive' +stage-dir + the directory in which to store downloaded and prepared files. + Defaults to '/var/tmp/cdist/__staged_file' + +state + see cdist-type__file + + +EXAMPLES +-------- + +.. code-block:: sh + + __staged_file /usr/local/bin/consul \ + --source file:///path/to/local/copy/consul \ + --cksum '428915666 15738724' \ + --state present \ + --group root \ + --owner root \ + --mode 755 + + __staged_file /usr/local/bin/consul \ + --source https://dl.bintray.com/mitchellh/consul/0.4.1_linux_amd64.zip \ + --cksum '428915666 15738724' \ + --fetch-command 'curl -s -L "%s"' \ + --prepare-command 'unzip -p "%s"' \ + --state present \ + --group root \ + --owner root \ + --mode 755 + + +SEE ALSO +-------- +- `cdist-type(7) `_ +- `cdist-type__file(7) `_ + + +COPYING +------- +Copyright \(C) 2015 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/__staged_file/manifest b/cdist/conf/type/__staged_file/manifest new file mode 100755 index 00000000..454948b4 --- /dev/null +++ b/cdist/conf/type/__staged_file/manifest @@ -0,0 +1,38 @@ +#!/bin/sh +# +# 2015 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 . +# + +destination="$__object_id" +source="$(cat "$__object/parameter/source")" +cksum="$(cat "$__object/parameter/cksum")" +stage_dir="$(cat "$__object/parameter/stage-dir")" +state="$(cat "$__object/parameter/state")" +fetch_command="$(cat "$__object/parameter/fetch-command")" +stage_file="${stage_dir}/${destination}" + +set -- "/${destination}" +for param in owner group mode state; do + if [ -f "$__object/parameter/$param" ]; then + set -- "$@" "--${param}" "$(cat "$__object/parameter/$param")" + fi +done +set -- "$@" --source "$stage_file" + +require="$__object_name" \ + __file "$@" diff --git a/cdist/conf/type/__staged_file/parameter/default/fetch-command b/cdist/conf/type/__staged_file/parameter/default/fetch-command new file mode 100644 index 00000000..b4dc1211 --- /dev/null +++ b/cdist/conf/type/__staged_file/parameter/default/fetch-command @@ -0,0 +1 @@ +curl -s -L "%s" diff --git a/cdist/conf/type/__staged_file/parameter/default/stage-dir b/cdist/conf/type/__staged_file/parameter/default/stage-dir new file mode 100644 index 00000000..9420b510 --- /dev/null +++ b/cdist/conf/type/__staged_file/parameter/default/stage-dir @@ -0,0 +1 @@ +/var/tmp/cdist/__staged_file diff --git a/cdist/conf/type/__staged_file/parameter/default/state b/cdist/conf/type/__staged_file/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__staged_file/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__staged_file/parameter/optional b/cdist/conf/type/__staged_file/parameter/optional new file mode 100644 index 00000000..18f4e87a --- /dev/null +++ b/cdist/conf/type/__staged_file/parameter/optional @@ -0,0 +1,7 @@ +fetch-command +group +owner +mode +prepare-command +stage-dir +state diff --git a/cdist/conf/type/__staged_file/parameter/required b/cdist/conf/type/__staged_file/parameter/required new file mode 100644 index 00000000..bfb1d5bf --- /dev/null +++ b/cdist/conf/type/__staged_file/parameter/required @@ -0,0 +1,2 @@ +cksum +source diff --git a/cdist/conf/type/__start_on_boot/explorer/state b/cdist/conf/type/__start_on_boot/explorer/state old mode 100755 new mode 100644 index e9e4318e..ca0f3a51 --- a/cdist/conf/type/__start_on_boot/explorer/state +++ b/cdist/conf/type/__start_on_boot/explorer/state @@ -1,6 +1,6 @@ #!/bin/sh # -# 2012-2013 Nico Schottelius (nico-cdist at schottelius.org) +# 2012-2015 Nico Schottelius (nico-cdist at schottelius.org) # 2013 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. @@ -24,42 +24,51 @@ os=$("$__explorer/os") runlevel=$("$__explorer/runlevel") +init=$("$__explorer/init") target_runlevel="$(cat "$__object/parameter/target_runlevel")" name="$__object_id" -case "$os" in - archlinux) - state=$(systemctl is-enabled "$name" >/dev/null 2>&1 \ - && echo present \ - || echo absent) - ;; +if [ "$init" = 'systemd' ]; then + # this handles ALL linux distros with systemd + # e.g. archlinux, gentoo, new RHEL and SLES versions + state=$(systemctl is-enabled "$name" >/dev/null 2>&1 \ + && echo present \ + || echo absent) - debian|ubuntu|openwrt) - state="present" - [ -f "/etc/rc$runlevel.d/S"??"$name" ] || state="absent" - ;; +else + case "$os" in + debian|openwrt|devuan) + state="present" + [ -f "/etc/rc$runlevel.d/S"??"$name" ] || state="absent" + ;; + ubuntu) + state="absent" + [ -f "/etc/rc$runlevel.d/S"??"$name" ] && state="present" + [ -f "/etc/init/${name}.conf" ] && state="present" + ;; - amazon|centos|fedora|owl|redhat) - state=$(chkconfig --level "$runlevel" "$name" || echo absent) - [ "$state" ] || state="present" - ;; - suse) - # check for target if set, usable for boot. services in runlevel B - if [ "$target_runlevel" != 'default' ]; then - runlevel="$target_runlevel" - fi - # suses chkconfig has the same name, but works different ... - state=$(chkconfig --check "$name" "$runlevel" || echo absent) - [ "$state" ] || state="present" - ;; - gentoo) - state="present" - [ -f "/etc/runlevels/${target_runlevel}/${name}" ] || state="absent" - ;; - *) - echo "Unsupported os: $os" >&2 - exit 1 - ;; -esac + amazon|centos|fedora|owl|redhat) + state=$(chkconfig --level "$runlevel" "$name" || echo absent) + [ "$state" ] || state="present" + ;; + suse) + # check for target if set, usable for boot. services in runlevel B + if [ "$target_runlevel" != 'default' ]; then + runlevel="$target_runlevel" + fi + # suses chkconfig has the same name, but works different ... + state=$(chkconfig --check "$name" "$runlevel" || echo absent) + [ "$state" ] || state="present" + ;; + gentoo) + state="present" + [ -f "/etc/runlevels/${target_runlevel}/${name}" ] || state="absent" + ;; + *) + echo "Unsupported os: $os" >&2 + exit 1 + ;; + esac +fi echo $state diff --git a/cdist/conf/type/__start_on_boot/gencode-remote b/cdist/conf/type/__start_on_boot/gencode-remote old mode 100755 new mode 100644 index 61b2b9fe..057f9f48 --- a/cdist/conf/type/__start_on_boot/gencode-remote +++ b/cdist/conf/type/__start_on_boot/gencode-remote @@ -1,7 +1,7 @@ #!/bin/sh # # 2012-2013 Nico Schottelius (nico-cdist at schottelius.org) -# 2013 Daniel Heule (hda at sfs.biz) +# 2016 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. # @@ -22,73 +22,96 @@ state_should="$(cat "$__object/parameter/state")" state_is=$(cat "$__object/explorer/state") +init=$(cat "$__global/explorer/init") target_runlevel="$(cat "$__object/parameter/target_runlevel")" # Short circuit if nothing is to be done [ "$state_should" = "$state_is" ] && exit 0 os=$(cat "$__global/explorer/os") +os_version=$(cat "$__global/explorer/os_version") name="$__object_id" case "$state_should" in present) - case "$os" in - archlinux) - echo "systemctl enable \"$name\"" - ;; - debian|ubuntu) - echo "update-rc.d \"$name\" defaults >/dev/null" - ;; + if [ "$init" = 'systemd' ]; then + # this handles ALL linux distros with systemd + # e.g. archlinux, gentoo in some cases, new RHEL and SLES versions + echo "systemctl -q enable \"$name\"" + else + case "$os" in + debian) + case "$os_version" in + [1-7]*) + echo "update-rc.d \"$name\" defaults >/dev/null" + ;; + 8*) + echo "systemctl enable \"$name\"" + ;; + *) + echo "Unsupported version $os_version of $os" >&2 + exit 1 + ;; + esac + ;; - gentoo) - echo rc-update add \"$name\" \"$target_runlevel\" - ;; + gentoo) + echo rc-update add \"$name\" \"$target_runlevel\" + ;; - amazon|centos|fedora|owl|redhat|suse) - echo chkconfig \"$name\" on - ;; + amazon|centos|fedora|owl|redhat|suse) + echo chkconfig \"$name\" on + ;; - openwrt) - # 'enable' can be successful and still return a non-zero exit - # code, deal with it by checking for success ourselves in that - # case (the || ... part). - echo "/etc/init.d/\"$name\" enable || [ -f /etc/rc.d/S??\"$name\" ]" - ;; + openwrt) + # 'enable' can be successful and still return a non-zero exit + # code, deal with it by checking for success ourselves in that + # case (the || ... part). + echo "/etc/init.d/\"$name\" enable || [ -f /etc/rc.d/S??\"$name\" ]" + ;; - *) - echo "Unsupported os: $os" >&2 - exit 1 - ;; - esac + ubuntu) + echo "update-rc.d \"$name\" defaults >/dev/null" + ;; + + *) + echo "Unsupported os: $os" >&2 + exit 1 + ;; + esac + fi ;; absent) - case "$os" in - archlinux) - echo "systemctl disable \"$name\"" - ;; - debian|ubuntu) - echo update-rc.d -f \"$name\" remove - ;; + if [ "$init" = 'systemd' ]; then + # this handles ALL linux distros with systemd + # e.g. archlinux, gentoo in some cases, new RHEL and SLES versions + echo "systemctl -q disable \"$name\"" - gentoo) - echo rc-update del \"$name\" \"$target_runlevel\" - ;; + else + case "$os" in + debian|ubuntu) + echo update-rc.d -f \"$name\" remove + ;; - centos|fedora|owl|redhat|suse) - echo chkconfig \"$name\" off - ;; + gentoo) + echo rc-update del \"$name\" \"$target_runlevel\" + ;; - openwrt) - echo "\"/etc/init.d/$name\" disable" - ;; + centos|fedora|owl|redhat|suse) + echo chkconfig \"$name\" off + ;; - *) - echo "Unsupported os: $os" >&2 - exit 1 - ;; - esac - + openwrt) + echo "\"/etc/init.d/$name\" disable" + ;; + + *) + echo "Unsupported os: $os" >&2 + exit 1 + ;; + esac + fi ;; *) diff --git a/cdist/conf/type/__start_on_boot/man.text b/cdist/conf/type/__start_on_boot/man.rst similarity index 57% rename from cdist/conf/type/__start_on_boot/man.text rename to cdist/conf/type/__start_on_boot/man.rst index dfada6d8..2fb2c7d9 100644 --- a/cdist/conf/type/__start_on_boot/man.text +++ b/cdist/conf/type/__start_on_boot/man.rst @@ -1,53 +1,51 @@ cdist-type__start_on_boot(7) ============================ +Manage stuff to be started at boot + Nico Schottelius -NAME ----- -cdist-type__start_on_boot - Manage stuff to be started at boot - - DESCRIPTION ----------- This cdist type allows you to enable or disable stuff to be started at boot of your operating system. Warning: This type has not been tested intensively and is not fully -supported (i.e. *bsd are not implemented). +supported (i.e. \*BSD are not implemented). REQUIRED PARAMETERS ------------------- None. + OPTIONAL PARAMETERS ------------------- -state:: +state Either "present" or "absent", defaults to "present" -target_runlevel:: +target_runlevel Runlevel which should be modified, defaults to "default" (only used on gentoo systems). EXAMPLES -------- --------------------------------------------------------------------------------- -# Ensure snmpd is started at boot -__start_on_boot snmpd +.. code-block:: sh -# Same, but more explicit -__start_on_boot snmpd --state present + # Ensure snmpd is started at boot + __start_on_boot snmpd -# Ensure legacy configuration management will not be started -__start_on_boot puppet --state absent --------------------------------------------------------------------------------- + # Same, but more explicit + __start_on_boot snmpd --state present + + # Ensure legacy configuration management will not be started + __start_on_boot puppet --state absent SEE ALSO -------- -- cdist-type(7) -- cdist-type__process(7) +- `cdist-type(7) `_ +- `cdist-type__process(7) `_ COPYING diff --git a/cdist/conf/type/__timezone/gencode-remote b/cdist/conf/type/__timezone/gencode-remote index b4782d4b..c07a61cb 100755 --- a/cdist/conf/type/__timezone/gencode-remote +++ b/cdist/conf/type/__timezone/gencode-remote @@ -24,7 +24,7 @@ timezone="$__object_id" os=$(cat "$__global/explorer/os") case "$os" in - ubuntu|debian) + ubuntu|debian|devuan) echo "echo \"$timezone\" > /etc/timezone" ;; esac diff --git a/cdist/conf/type/__timezone/man.text b/cdist/conf/type/__timezone/man.rst similarity index 56% rename from cdist/conf/type/__timezone/man.text rename to cdist/conf/type/__timezone/man.rst index 6f0c5101..083f4fe6 100644 --- a/cdist/conf/type/__timezone/man.text +++ b/cdist/conf/type/__timezone/man.rst @@ -1,13 +1,10 @@ cdist-type__timezone(7) ======================= +Allows one to configure the desired localtime timezone. + Ramon Salvadó -NAME ----- -cdist-type__timezone - Allows to configure the desired localtime timezone. - - DESCRIPTION ----------- This type creates a symlink (/etc/localtime) to the selected timezone @@ -27,18 +24,18 @@ None. EXAMPLES -------- --------------------------------------------------------------------------------- -#Set up Europe/Andorra as our timezone. -__timezone Europe/Andorra +.. code-block:: sh -#Set up US/Central as our timezone. -__timezone US/Central --------------------------------------------------------------------------------- + #Set up Europe/Andorra as our timezone. + __timezone Europe/Andorra + + #Set up US/Central as our timezone. + __timezone US/Central SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__timezone/manifest b/cdist/conf/type/__timezone/manifest index 81de0217..8ddfd122 100755 --- a/cdist/conf/type/__timezone/manifest +++ b/cdist/conf/type/__timezone/manifest @@ -1,7 +1,7 @@ #!/bin/sh # # 2011 Ramon Salvadó (rsalvado at gnuine dot com) -# 2012 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012-2015 Steven Armstrong (steven-cdist at armstrong.cc) # 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. @@ -24,16 +24,39 @@ timezone="$__object_id" os=$(cat "$__global/explorer/os") - + case "$os" in - archlinux|debian|ubuntu) + archlinux|debian|ubuntu|devuan) + __package tzdata + export require="__package/tzdata" + ;; + suse) + __package timezone + export require="__package/timezone" + ;; + freebsd|netbsd) + # whitelist + : + ;; + centos) __package tzdata --state present - require="__package/tzdata" __link /etc/localtime \ - --source "/usr/share/zoneinfo/${timezone}" \ - --type symbolic + export require="__package/tzdata" + __file /etc/sysconfig/clock \ + --owner root --group root --mode 644 \ + --state exists + require="__file/etc/sysconfig/clock" \ + __key_value ZONE \ + --file /etc/sysconfig/clock \ + --delimiter '=' \ + --value "\"$timezone\"" ;; *) - echo "Unsupported OS $os" >&2 + 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 + +__link /etc/localtime \ + --source "/usr/share/zoneinfo/${timezone}" \ + --type symbolic diff --git a/cdist/conf/type/__update_alternatives/man.text b/cdist/conf/type/__update_alternatives/man.rst similarity index 61% rename from cdist/conf/type/__update_alternatives/man.text rename to cdist/conf/type/__update_alternatives/man.rst index 2bcc1874..477ee88c 100644 --- a/cdist/conf/type/__update_alternatives/man.text +++ b/cdist/conf/type/__update_alternatives/man.rst @@ -1,13 +1,10 @@ cdist-type__update_alternatives(7) ================================== +Configure alternatives + Nico Schottelius -NAME ----- -cdist-type__update_alternatives - Configure alternatives - - DESCRIPTION ----------- On Debian and alike systems update-alternatives(1) can be used @@ -17,23 +14,23 @@ One of the most common used targets is the "editor". REQUIRED PARAMETERS ------------------- -path:: +path Use this path for the given alternative EXAMPLES -------- --------------------------------------------------------------------------------- -# Setup vim as the default editor -__update_alternatives editor --path /usr/bin/vim.basic --------------------------------------------------------------------------------- +.. code-block:: sh + + # Setup vim as the default editor + __update_alternatives editor --path /usr/bin/vim.basic SEE ALSO -------- -- cdist-type(7) -- cdist-type__debconf_set_selections(7) +- `cdist-type(7) `_ +- `cdist-type__debconf_set_selections(7) `_ - update-alternatives(8) diff --git a/cdist/conf/type/__user/explorer/shadow b/cdist/conf/type/__user/explorer/shadow index 59abaa8a..1a8fd809 100755 --- a/cdist/conf/type/__user/explorer/shadow +++ b/cdist/conf/type/__user/explorer/shadow @@ -27,7 +27,7 @@ os="$($__explorer/os)" database="shadow" case "$os" in - "freebsd"|"openbsd") database="passwd";; + "freebsd"|"netbsd"|"openbsd") database="passwd";; esac diff --git a/cdist/conf/type/__user/man.text b/cdist/conf/type/__user/man.rst similarity index 56% rename from cdist/conf/type/__user/man.text rename to cdist/conf/type/__user/man.rst index be70ec12..c690a559 100644 --- a/cdist/conf/type/__user/man.text +++ b/cdist/conf/type/__user/man.rst @@ -1,13 +1,10 @@ cdist-type__user(7) =================== +Manage users + Steven Armstrong -NAME ----- -cdist-type__user - Manage users - - DESCRIPTION ----------- This cdist type allows you to create or modify users on the target. @@ -20,63 +17,73 @@ None. OPTIONAL PARAMETERS ------------------- -state:: +state absent or present, defaults to present -comment:: + +comment see usermod(8) -home:: + +home see above -gid:: + +gid see above -password:: + +password see above -shell:: + +shell see above -uid:: + +uid see above + BOOLEAN PARAMETERS ------------------ -system:: +system see useradd(8), apply only on user create -create-home:: + +create-home see useradd(8), apply only on user create -remove-home:: + +remove-home see userdel(8), apply only on user delete MESSAGES -------- -mod:: +mod User is modified -add:: + +add New user added EXAMPLES -------- --------------------------------------------------------------------------------- -# Create user account for foobar with operating system default settings -__user foobar +.. code-block:: sh -# Same but with a different shell -__user foobar --shell /bin/zsh + # Create user account for foobar with operating system default settings + __user foobar -# Same but for a system account -__user foobar --system + # Same but with a different shell + __user foobar --shell /bin/zsh -# Set explicit uid and home -__user foobar --uid 1001 --shell /bin/zsh --home /home/foobar + # Same but for a system account + __user foobar --system -# Drop user if exists -__user foobar --state absent --------------------------------------------------------------------------------- + # Set explicit uid and home + __user foobar --uid 1001 --shell /bin/zsh --home /home/foobar + + # Drop user if exists + __user foobar --state absent SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ - usermod(8) or pw(8) diff --git a/cdist/conf/type/__user_groups/explorer/group b/cdist/conf/type/__user_groups/explorer/group index a8cb63af..5bad9a0b 100755 --- a/cdist/conf/type/__user_groups/explorer/group +++ b/cdist/conf/type/__user_groups/explorer/group @@ -20,4 +20,4 @@ user="$(cat "$__object/parameter/user" 2>/dev/null || echo "$__object_id")" -(id --groups --name "$user" | tr ' ' '\n' | sort) 2>/dev/null || true +(id -G -n "$user" | tr ' ' '\n' | sort) 2>/dev/null || true diff --git a/cdist/conf/type/__user_groups/explorer/oldusermod b/cdist/conf/type/__user_groups/explorer/oldusermod new file mode 100644 index 00000000..bf43fcec --- /dev/null +++ b/cdist/conf/type/__user_groups/explorer/oldusermod @@ -0,0 +1,28 @@ +#!/bin/sh +# +# 2015 Heule Daniel (hda 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 . +# + +os="$($__explorer/os)" + +if [ "$os" = "netbsd" ]; then + echo netbsd + exit +fi + +usermod --help | grep -q -- '-A group' && echo true || echo false diff --git a/cdist/conf/type/__user_groups/gencode-remote b/cdist/conf/type/__user_groups/gencode-remote index 9f11dd16..8b13f32c 100755 --- a/cdist/conf/type/__user_groups/gencode-remote +++ b/cdist/conf/type/__user_groups/gencode-remote @@ -20,6 +20,21 @@ user="$(cat "$__object/parameter/user" 2>/dev/null || echo "$__object_id")" state_should="$(cat "$__object/parameter/state")" +oldusermod="$(cat "$__object/explorer/oldusermod")" +os=$(cat "$__global/explorer/os") + +if [ "$os" = "netbsd" ]; then + # NetBSD does not have a command to remove a user from a group + oldusermod="true" + addparam="-G" + delparam=";;#" +elif [ "$oldusermod" = "true" ]; then + addparam="-A" + delparam="-R" +else + addparam="-a" + delparam="-d" +fi mkdir "$__object/files" # file has to be sorted for comparison with `comm` @@ -28,11 +43,11 @@ sort "$__object/parameter/group" > "$__object/files/group.sorted" case "$state_should" in present) changed_groups="$(comm -13 "$__object/explorer/group" "$__object/files/group.sorted")" - action="-a" + action="$addparam" ;; absent) changed_groups="$(comm -12 "$__object/explorer/group" "$__object/files/group.sorted")" - action="-d" + action="$delparam" ;; esac @@ -42,5 +57,9 @@ if [ -z "$changed_groups" ]; then fi for group in $changed_groups; do - echo "gpasswd $action \"$user\" \"$group\"" + if [ "$oldusermod" = "true" ]; then + echo "usermod $action \"$group\" \"$user\"" + else + echo "gpasswd $action \"$user\" \"$group\"" + fi done diff --git a/cdist/conf/type/__user_groups/man.text b/cdist/conf/type/__user_groups/man.rst similarity index 60% rename from cdist/conf/type/__user_groups/man.text rename to cdist/conf/type/__user_groups/man.rst index d45784fe..4458a6cf 100644 --- a/cdist/conf/type/__user_groups/man.text +++ b/cdist/conf/type/__user_groups/man.rst @@ -1,13 +1,10 @@ cdist-type__user_groups(7) ========================== +Manage user groups + Steven Armstrong -NAME ----- -cdist-type__user_groups - manage user groups - - DESCRIPTION ----------- Adds or removes a user from one or more groups. @@ -15,35 +12,35 @@ Adds or removes a user from one or more groups. REQUIRED PARAMETERS ------------------- -group:: +group the group to which this user should be added or removed. Can be specified multiple times. OPTIONAL PARAMETERS ------------------- -user:: +user the name of the user. Defaults to object_id -state:: +state absent or present. Defaults to present. EXAMPLES -------- --------------------------------------------------------------------------------- -__user_groups nginx --group webuser1 --group webuser2 +.. code-block:: sh -# remove user nginx from groups webuser2 -__user_groups nginx-webuser2 --user nginx \ - --group webuser2 --state absent --------------------------------------------------------------------------------- + __user_groups nginx --group webuser1 --group webuser2 + + # remove user nginx from groups webuser2 + __user_groups nginx-webuser2 --user nginx \ + --group webuser2 --state absent SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING 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.rst b/cdist/conf/type/__yum_repo/man.rst new file mode 100644 index 00000000..396f271c --- /dev/null +++ b/cdist/conf/type/__yum_repo/man.rst @@ -0,0 +1,121 @@ +cdist-type__yum_repo(7) +======================= +Manage yum repositories + +Steven Armstrong + + +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 +-------- + +.. code-block:: sh + + __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..6a4791e6 100644 --- a/cdist/conf/type/__zypper_repo/explorer/repo_id +++ b/cdist/conf/type/__zypper_repo/explorer/repo_id @@ -1,6 +1,6 @@ #!/bin/sh # -# 2013 Daniel Heule (hda at sfs.biz) +# 2013-2014 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. # @@ -18,12 +18,12 @@ # 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 -echo $(zypper lr -u | grep -E "\<$uri\>" | cut -d'|' -f 1 | grep -E '^[0-9]' ) +echo $(zypper lr -u | grep -F "$uri" | cut -d'|' -f 1 | grep -E '^[0-9]' ) 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.rst b/cdist/conf/type/__zypper_repo/man.rst new file mode 100644 index 00000000..e3bc1d4f --- /dev/null +++ b/cdist/conf/type/__zypper_repo/man.rst @@ -0,0 +1,70 @@ +cdist-type__zypper_repo(7) +========================== +Repository management with zypper + +Daniel Heule + + +DESCRIPTION +----------- +zypper is usually used on the SuSE distribution to manage repositories. + + +REQUIRED PARAMETERS +------------------- +None + + +OPTIONAL PARAMETERS +------------------- +state + Either "present" or "absent" or "enabled" or "disabled", defaults to "present" + + * **present** - make sure that the repo is available, 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, which makes it inaccessible + +uri + If supplied, use the uri and not the object id as repo uri. + +repo_desc + If supplied, use the description and not the object id as repo description, only used if the state is present and the repo has to be created + +repo_id + If supplied, use the id and not the object id as repo id, can be used with state absent, enabled and disabled + + +EXAMPLES +-------- + +.. code-block:: sh + + # Ensure testrepo in installed + __zypper_repo testrepo --state present --uri http://url.to.your.repo/with/path + + # Drop repo by repo uri + __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 + + # enable repo by id + __zypper_repo testrepo2 --state enabled --repo_id 2 + + # enable repo by uri + __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 + + +SEE ALSO +-------- +- `cdist-type(7) `_ + + +COPYING +------- +Copyright \(C) 2013 Daniel Heule. 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/__zypper_repo/man.text b/cdist/conf/type/__zypper_repo/man.text deleted file mode 100644 index 6ea88f16..00000000 --- a/cdist/conf/type/__zypper_repo/man.text +++ /dev/null @@ -1,73 +0,0 @@ -cdist-type__zypper_repo(7) -========================== -Daniel Heule - - -NAME ----- -cdist-type__zypper_repo - repository management with zypper - - -DESCRIPTION ------------ -zypper is usually used on the SuSE distribution to manage repositories. - - -REQUIRED PARAMETERS -------------------- -None - - -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 + - #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:: - If supplied, use the uri and not the object id as repo uri. - -repo_desc:: - If supplied, use the description and not the object id as repo description, only used if the state is present and the repo has to be created - -repo_id:: - If supplied, use the id and not the object id as repo id, can be used with state absent, enabled and disabled - - -EXAMPLES --------- - --------------------------------------------------------------------------------- -# Ensure testrepo in installed -__zypper_repo testrepo --state present --repo_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 - -# Drop repo by id number (attention: repos are always numbered from 1 to max) -__zypper_repo testrepo --state absent --repo_id 1 - -# enable repo by id -__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 - -# disable a repo works like enabling it -__zypper_repo testrepo4 --state disabled --repo_id 4 --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) - - -COPYING -------- -Copyright \(C) 2013 Daniel Heule. 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/__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..6eee47fb 100644 --- a/cdist/conf/type/__zypper_service/explorer/service_uri +++ b/cdist/conf/type/__zypper_service/explorer/service_uri @@ -20,11 +20,9 @@ # # 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 -# simpler command which works only on SLES11 SP3 or newer: -# echo $(zypper ls -u -E | grep -E "\<$uri\>" | cut -d'|' -f 7) -echo $(zypper ls -u | grep -E '^([^|]+\|){3,3} Yes' | grep -E "\<$uri\>" | cut -d'|' -f 7 ) +echo $(zypper ls -u | awk 'BEGIN { FS = "[ ]+\\|[ ]+" } ; $4 == "Yes" && $NF == "'$uri'" {print $NF}') 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.rst b/cdist/conf/type/__zypper_service/man.rst new file mode 100644 index 00000000..377d30e1 --- /dev/null +++ b/cdist/conf/type/__zypper_service/man.rst @@ -0,0 +1,63 @@ +cdist-type__zypper_service(7) +============================= +Service management with zypper + +Daniel Heule + + +DESCRIPTION +----------- +zypper is usually used on SuSE systems to manage services. + + +REQUIRED PARAMETERS +------------------- +uri + Uri of the service + + +OPTIONAL PARAMETERS +------------------- +service_desc + If supplied, use the service_desc and not the object id as descritpion for the service. + +state + Either "present" or "absent", defaults to "present" + +type + Defaults to "ris", the standard type of services at SLES11. For other values, see manpage of zypper. + + +BOOLEAN PARAMETERS +------------------ +remove-all-other-services + Drop all other services found on the target host before adding the new one. + +remove-all-repos + If supplied, remove all existing repos prior to setup the new service. + + +EXAMPLES +-------- + +.. code-block:: sh + + # 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" --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" --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 --uri "http://path/to/your/ris/dir" + + +SEE ALSO +-------- +- `cdist-type(7) `_ + + +COPYING +------- +Copyright \(C) 2013 Daniel Heule. 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/__zypper_service/man.text b/cdist/conf/type/__zypper_service/man.text deleted file mode 100644 index 31543d93..00000000 --- a/cdist/conf/type/__zypper_service/man.text +++ /dev/null @@ -1,67 +0,0 @@ -cdist-type__zypper_service(7) -============================= -Daniel Heule - - -NAME ----- -cdist-type__zypper_service - service management with zypper - - -DESCRIPTION ------------ -zypper is usually used on SuSE systems to manage services. - - -REQUIRED PARAMETERS -------------------- -service_uri:: - Uri of the service - - -OPTIONAL PARAMETERS -------------------- -service_desc:: - If supplied, use the service_desc and not the object id as descritpion for the service. - -state:: - Either "present" or "absent", defaults to "present" - -type:: - Defaults to "ris", the standard type of services at SLES11. For other values, see manpage of zypper. - - -BOOLEAN PARAMETERS ------------------- -remove-all-other-services:: - Drop all other services found on the target host before adding the new one. - -remove-all-repos:: - If supplied, remove all existing repos prior to setup the new service. - - -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 - -# 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" - -# 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" - --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) - - -COPYING -------- -Copyright \(C) 2013 Daniel Heule. 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/__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/config.py b/cdist/config.py index 73ba4710..f5e62ce1 100644 --- a/cdist/config.py +++ b/cdist/config.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- # -# 2010-2013 Nico Schottelius (nico-cdist at schottelius.org) +# 2010-2015 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -26,6 +26,7 @@ import shutil import sys import time import pprint +import itertools import cdist @@ -53,6 +54,27 @@ class Config(object): self.local.create_files_dirs() self.remote.create_files_dirs() + @staticmethod + def hosts(source): + """Yield hosts from source. + Source can be a sequence or filename (stdin if \'-\'). + In case of filename each line represents one host. + """ + if isinstance(source, str): + import fileinput + try: + for host in fileinput.input(files=(source)): + # remove leading and trailing whitespace + yield host.strip() + except (IOError, OSError) as e: + raise cdist.Error("Error reading hosts from \'{}\'".format( + source)) + else: + if source: + for host in source: + yield host + + @classmethod def commandline(cls, args): """Configure remote system""" @@ -60,6 +82,13 @@ class Config(object): # FIXME: Refactor relict - remove later log = logging.getLogger("cdist") + + if args.manifest == '-' and args.hostfile == '-': + raise cdist.Error(("Cannot read both, manifest and host file, " + "from stdin")) + # if no host source is specified then read hosts from stdin + if not (args.hostfile or args.host): + args.hostfile = '-' initial_manifest_tempfile = None if args.manifest == '-': @@ -79,8 +108,11 @@ class Config(object): process = {} failed_hosts = [] time_start = time.time() - - for host in args.host: + + hostcnt = 0 + for host in itertools.chain(cls.hosts(args.host), + cls.hosts(args.hostfile)): + hostcnt += 1 if args.parallel: log.debug("Creating child process for %s", host) process[host] = multiprocessing.Process(target=cls.onehost, args=(host, args, True)) @@ -101,7 +133,7 @@ class Config(object): failed_hosts.append(host) time_end = time.time() - log.info("Total processing time for %s host(s): %s", len(args.host), + log.info("Total processing time for %s host(s): %s", hostcnt, (time_end - time_start)) if len(failed_hosts) > 0: @@ -162,7 +194,8 @@ class Config(object): def object_list(self): """Short name for object list retrieval""" for cdist_object in core.CdistObject.list_objects(self.local.object_path, - self.local.type_path): + self.local.type_path, + self.local.object_marker_name): if cdist_object.cdist_type.is_install: self.log.debug("Running in config mode, ignoring install object: {0}".format(cdist_object)) else: @@ -229,12 +262,12 @@ class Config(object): for requirement in cdist_object.requirements_unfinished(cdist_object.autorequire): autorequire_names.append(requirement.name) - requirements = ", ".join(requirement_names) - autorequire = ", ".join(autorequire_names) - info_string.append("%s requires: %s autorequires: %s" % (cdist_object.name, requirements, autorequire)) + requirements = "\n ".join(requirement_names) + autorequire = "\n ".join(autorequire_names) + info_string.append("%s requires:\n %s\n%s autorequires:\n %s" % (cdist_object.name, requirements, cdist_object.name, autorequire)) - raise cdist.UnresolvableRequirementsError("The requirements of the following objects could not be resolved: %s" % - ("; ".join(info_string))) + raise cdist.UnresolvableRequirementsError("The requirements of the following objects could not be resolved:\n%s" % + ("\n".join(info_string))) def object_prepare(self, cdist_object): """Prepare object: Run type explorer + manifest""" diff --git a/cdist/core/__init__.py b/cdist/core/__init__.py index 66ee00a5..d773fc01 100644 --- a/cdist/core/__init__.py +++ b/cdist/core/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # # 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2014-2015 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -23,7 +24,6 @@ from cdist.core.cdist_type import CdistType from cdist.core.cdist_type import NoSuchTypeError from cdist.core.cdist_object import CdistObject from cdist.core.cdist_object import IllegalObjectIdError -from cdist.core.cdist_object import OBJECT_MARKER from cdist.core.explorer import Explorer from cdist.core.manifest import Manifest from cdist.core.code import Code diff --git a/cdist/core/cdist_object.py b/cdist/core/cdist_object.py index e8c58a67..8c6ee9c9 100644 --- a/cdist/core/cdist_object.py +++ b/cdist/core/cdist_object.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # 2011 Steven Armstrong (steven-cdist at armstrong.cc) -# 2011-2013 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2015 Nico Schottelius (nico-cdist at schottelius.org) # 2014 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. @@ -32,9 +32,6 @@ from cdist.util import fsproperty log = logging.getLogger(__name__) -OBJECT_MARKER = '.cdist' - - class IllegalObjectIdError(cdist.Error): def __init__(self, object_id, message=None): self.object_id = object_id @@ -66,40 +63,46 @@ class CdistObject(object): STATE_RUNNING = "running" STATE_DONE = "done" - def __init__(self, cdist_type, base_path, object_id=''): + def __init__(self, cdist_type, base_path, object_marker, object_id): self.cdist_type = cdist_type # instance of Type self.base_path = base_path self.object_id = object_id + self.object_marker = object_marker + self.validate_object_id() self.sanitise_object_id() self.name = self.join_name(self.cdist_type.name, self.object_id) - self.path = os.path.join(self.cdist_type.path, self.object_id, OBJECT_MARKER) + self.path = os.path.join(self.cdist_type.path, self.object_id, self.object_marker) + self.absolute_path = os.path.join(self.base_path, self.path) self.code_local_path = os.path.join(self.path, "code-local") self.code_remote_path = os.path.join(self.path, "code-remote") self.parameter_path = os.path.join(self.path, "parameter") @classmethod - def list_objects(cls, object_base_path, type_base_path): + def list_objects(cls, object_base_path, type_base_path, object_marker): """Return a list of object instances""" - for object_name in cls.list_object_names(object_base_path): + for object_name in cls.list_object_names(object_base_path, object_marker): type_name, object_id = cls.split_name(object_name) - yield cls(cdist.core.CdistType(type_base_path, type_name), object_base_path, object_id=object_id) + yield cls(cdist.core.CdistType(type_base_path, type_name), + base_path=object_base_path, + object_marker=object_marker, + object_id=object_id) + + @classmethod + def list_object_names(cls, object_base_path, object_marker): + """Return a list of object names""" + for path, dirs, files in os.walk(object_base_path): + if object_marker in dirs: + yield os.path.relpath(path, object_base_path) @classmethod def list_type_names(cls, object_base_path): """Return a list of type names""" return os.listdir(object_base_path) - @classmethod - def list_object_names(cls, object_base_path): - """Return a list of object names""" - for path, dirs, files in os.walk(object_base_path): - if OBJECT_MARKER in dirs: - yield os.path.relpath(path, object_base_path) - @staticmethod def split_name(object_name): """split_name('__type_name/the/object_id') -> ('__type_name', 'the/object_id') @@ -127,8 +130,8 @@ class CdistObject(object): """Validate the given object_id and raise IllegalObjectIdError if it's not valid. """ if self.object_id: - if OBJECT_MARKER in self.object_id.split(os.sep): - raise IllegalObjectIdError(self.object_id, 'object_id may not contain \'%s\'' % OBJECT_MARKER) + if self.object_marker in self.object_id.split(os.sep): + raise IllegalObjectIdError(self.object_id, 'object_id may not contain \'%s\'' % self.object_marker) if '//' in self.object_id: raise IllegalObjectIdError(self.object_id, 'object_id may not contain //') if self.object_id == '.': @@ -155,12 +158,13 @@ class CdistObject(object): base_path = self.base_path type_path = self.cdist_type.base_path + object_marker = self.object_marker type_name, object_id = self.split_name(object_name) cdist_type = self.cdist_type.__class__(type_path, type_name) - return self.__class__(cdist_type, base_path, object_id=object_id) + return self.__class__(cdist_type, base_path, object_marker, object_id=object_id) def __repr__(self): return '' % self.name diff --git a/cdist/core/cdist_type.py b/cdist/core/cdist_type.py index ff1ebaec..d5b4ea3e 100644 --- a/cdist/core/cdist_type.py +++ b/cdist/core/cdist_type.py @@ -204,11 +204,13 @@ class CdistType(object): try: defaults_dir = os.path.join(self.absolute_path, "parameter", "default") for name in os.listdir(defaults_dir): - with open(os.path.join(defaults_dir, name)) as fd: - defaults[name] = fd.read().strip() + try: + with open(os.path.join(defaults_dir, name)) as fd: + defaults[name] = fd.read().strip() + except EnvironmentError: + pass # Swallow errors raised by open() or read() except EnvironmentError: - # error ignored - pass + pass # Swallow error raised by os.listdir() finally: self.__parameter_defaults = defaults return self.__parameter_defaults diff --git a/cdist/core/manifest.py b/cdist/core/manifest.py index 95bf4c25..240e57a1 100644 --- a/cdist/core/manifest.py +++ b/cdist/core/manifest.py @@ -144,4 +144,4 @@ class Manifest(object): type_manifest = os.path.join(self.local.type_path, cdist_object.cdist_type.manifest_path) message_prefix = cdist_object.name if os.path.isfile(type_manifest): - self.local.run_script(type_manifest, env=self.env_type_manifest(cdist_object)) + self.local.run_script(type_manifest, env=self.env_type_manifest(cdist_object), message_prefix=message_prefix) diff --git a/cdist/emulator.py b/cdist/emulator.py index 41834fbf..3f553412 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# 2011-2013 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2015 Nico Schottelius (nico-cdist at schottelius.org) # 2012 Steven Armstrong (steven-cdist at armstrong.cc) # 2014 Daniel Heule (hda at sfs.biz) # @@ -64,9 +64,10 @@ class Emulator(object): self.global_path = self.env['__global'] self.target_host = self.env['__target_host'] - # Internally only + # Internal variables self.object_source = self.env['__cdist_manifest'] self.type_base_path = self.env['__cdist_type_base_path'] + self.object_marker = self.env['__cdist_object_marker'] except KeyError as e: raise MissingRequiredEnvironmentVariableError(e.args[0]) @@ -131,13 +132,16 @@ class Emulator(object): self.log.debug('Args: %s' % self.args) def setup_object(self): - # Setup object_id - FIXME: unset / do not setup anymore! - if not self.cdist_type.is_singleton: + # Setup object - and ensure it is not in args + if self.cdist_type.is_singleton: + self.object_id = '' + else: self.object_id = self.args.object_id[0] del self.args.object_id # Instantiate the cdist object we are defining - self.cdist_object = core.CdistObject(self.cdist_type, self.object_base_path, self.object_id) + self.cdist_object = core.CdistObject(self.cdist_type, + self.object_base_path, self.object_marker, self.object_id) # Create object with given parameters self.parameters = {} diff --git a/cdist/exec/local.py b/cdist/exec/local.py index 6b0ad9b5..fa003cb0 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- # # 2011 Steven Armstrong (steven-cdist at armstrong.cc) -# 2011-2013 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2015 Nico Schottelius (nico-cdist at schottelius.org) +# 2016 Darko Poljak (darko.poljak at gmail.com) # # This file is part of cdist. # @@ -53,9 +54,18 @@ class Local(object): # FIXME: stopped: create base that does not require moving later if base_path: - self.base_path = base_path + base_path_parent = base_path else: - self.base_path = tempfile.mkdtemp() + base_path_parent = tempfile.mkdtemp() + import atexit + atexit.register(lambda: shutil.rmtree(base_path_parent)) + self.hostdir = self._hostdir() + self.base_path = os.path.join(base_path_parent, self.hostdir) + + self._init_log() + self._init_permissions() + + self.mkdir(self.base_path) # FIXME: as well self._init_cache_dir(None) @@ -65,12 +75,10 @@ class Local(object): self._add_conf_dirs = add_conf_dirs - self._init_log() - self._init_permissions() self._init_paths() + self._init_object_marker() self._init_conf_dirs() - @property def dist_conf_dir(self): return os.path.abspath(os.path.join(os.path.dirname(cdist.__file__), "conf")) @@ -82,6 +90,13 @@ class Local(object): else: return None + def _hostdir(self): + if os.path.isabs(self.target_host): + hostdir = self.target_host[1:] + else: + hostdir = self.target_host + return hostdir + def _init_log(self): self.log = logging.getLogger(self.target_host) @@ -105,6 +120,12 @@ class Local(object): self.type_path = os.path.join(self.conf_path, "type") + def _init_object_marker(self): + self.object_marker_file = os.path.join(self.base_path, "object_marker") + + # Does not need to be secure - just randomly different from .cdist + self.object_marker_name = tempfile.mktemp(prefix='.cdist-', dir='') + def _init_conf_dirs(self): self.conf_dirs = [] @@ -127,6 +148,7 @@ class Local(object): def _init_directories(self): self.mkdir(self.conf_path) self.mkdir(self.global_explorer_out_path) + self.mkdir(self.object_path) self.mkdir(self.bin_path) def create_files_dirs(self): @@ -134,6 +156,13 @@ class Local(object): self._create_conf_path_and_link_conf_dirs() self._create_messages() self._link_types_for_emulator() + self._setup_object_marker_file() + + def _setup_object_marker_file(self): + with open(self.object_marker_file, 'w') as fd: + fd.write("%s\n" % self.object_marker_name) + + self.log.debug("Object marker %s saved in %s" % (self.object_marker_name, self.object_marker_file)) def _init_cache_dir(self, cache_dir): @@ -168,6 +197,9 @@ class Local(object): # Export __target_host for use in __remote_{copy,exec} scripts env['__target_host'] = self.target_host + # Export for emulator + env['__cdist_object_marker'] = self.object_marker_name + if message_prefix: message = cdist.message.Message(message_prefix, self.messages_path) env.update(message.env) @@ -180,7 +212,7 @@ class Local(object): except subprocess.CalledProcessError: raise cdist.Error("Command failed: " + " ".join(command)) except OSError as error: - raise cdist.Error(" ".join(*args) + ": " + error.args[1]) + raise cdist.Error(" ".join(command) + ": " + error.args[1]) finally: if message_prefix: message.merge_messages() @@ -195,13 +227,9 @@ class Local(object): return self.run(command=command, env=env, return_output=return_output, message_prefix=message_prefix) - def save_cache(self): - if os.path.isabs(self.target_host): - hostdir = self.target_host[1:] - else: - hostdir = self.target_host - destination = os.path.join(self.cache_path, hostdir) + def save_cache(self): + destination = os.path.join(self.cache_path, self.hostdir) self.log.debug("Saving " + self.base_path + " to " + destination) try: diff --git a/cdist/exec/remote.py b/cdist/exec/remote.py index 9b7d5d1c..77e2c8be 100644 --- a/cdist/exec/remote.py +++ b/cdist/exec/remote.py @@ -130,12 +130,28 @@ class Remote(object): # FIXME: replace this by -o SendEnv name -o SendEnv name ... to ssh? # can't pass environment to remote side, so prepend command with # variable declarations + + # cdist command prepended with variable assignments expects + # posix shell (bourne, bash) at the remote as user default shell. + # If remote user shell isn't poxis shell, but for e.g. csh/tcsh + # then these var assignments are not var assignments for this + # remote shell, it tries to execute it as a command and fails. + # So really do this by default: + # /bin/sh -c 'export ; command' + # so that constructed remote command isn't dependent on remote + # shell. Do this only if env is not None. env breaks this. + # Explicitly use /bin/sh, because var assignments assume poxis + # shell already. + # This leaves the posibility to write script that needs to be run + # remotely in e.g. csh and setting up CDIST_REMOTE_SHELL to e.g. + # /bin/csh will execute this script in the right way. if env: - remote_env = ["%s=%s" % item for item in env.items()] - cmd.extend(remote_env) - - cmd.extend(command) - + remote_env = [" export %s=%s;" % item for item in env.items()] + string_cmd = ("/bin/sh -c '" + " ".join(remote_env) + + " ".join(command) + "'") + cmd.append(string_cmd) + else: + cmd.extend(command) return self._run_command(cmd, env=env, return_output=return_output) def _run_command(self, command, env=None, return_output=False): diff --git a/cdist/message.py b/cdist/message.py index b840a84d..f9b0c313 100644 --- a/cdist/message.py +++ b/cdist/message.py @@ -37,12 +37,14 @@ class Message(object): self.prefix = prefix self.global_messages = messages - self.messages_in = tempfile.mkstemp(suffix='.cdist_message_in')[1] - self.messages_out = tempfile.mkstemp(suffix='.cdist_message_out')[1] + in_fd, self.messages_in = tempfile.mkstemp(suffix='.cdist_message_in') + out_fd, self.messages_out = tempfile.mkstemp(suffix='.cdist_message_out') + + os.close(in_fd) + os.close(out_fd) self._copy_messages() - @property def env(self): env = {} diff --git a/cdist/shell.py b/cdist/shell.py index 8ca68115..d0921bc9 100644 --- a/cdist/shell.py +++ b/cdist/shell.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# 2013 Nico Schottelius (nico-cdist at schottelius.org) +# 2013-2015 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # diff --git a/cdist/test/cdist_object/__init__.py b/cdist/test/cdist_object/__init__.py index 3c25a959..9c075acb 100644 --- a/cdist/test/cdist_object/__init__.py +++ b/cdist/test/cdist_object/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) -# 2012 Nico Schottelius (nico-cdist at schottelius.org) +# 2012-2015 Nico Schottelius (nico-cdist at schottelius.org) # 2014 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. @@ -23,6 +23,7 @@ import os import shutil +import tempfile from cdist import test from cdist import core @@ -32,37 +33,48 @@ import cdist import os.path as op my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') -object_base_path = op.join(fixtures, 'object') type_base_path = op.join(fixtures, 'type') +OBJECT_MARKER_NAME = '.cdist-pseudo-random' + +expected_object_names = sorted([ + '__first/child', + '__first/dog', + '__first/man', + '__first/woman', + '__second/on-the', + '__second/under-the', + '__third/moon']) + + class ObjectClassTestCase(test.CdistTestCase): def setUp(self): - self.expected_object_names = sorted([ - '__first/child', - '__first/dog', - '__first/man', - '__first/woman', - '__second/on-the', - '__second/under-the', - '__third/moon']) + + self.tempdir = tempfile.mkdtemp(prefix="cdist.test") + self.object_base_path = self.tempdir self.expected_objects = [] - for cdist_object_name in self.expected_object_names: + for cdist_object_name in expected_object_names: 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) + cdist_object = core.CdistObject(core.CdistType(type_base_path, cdist_type), self.object_base_path, + OBJECT_MARKER_NAME, cdist_object_id) + cdist_object.create() self.expected_objects.append(cdist_object) + def tearDown(self): + shutil.rmtree(self.tempdir) + def test_list_object_names(self): - found_object_names = sorted(list(core.CdistObject.list_object_names(object_base_path))) - self.assertEqual(found_object_names, self.expected_object_names) + found_object_names = sorted(list(core.CdistObject.list_object_names(self.object_base_path, OBJECT_MARKER_NAME))) + self.assertEqual(found_object_names, expected_object_names) def test_list_type_names(self): - type_names = list(cdist.core.CdistObject.list_type_names(object_base_path)) + type_names = list(cdist.core.CdistObject.list_type_names(self.object_base_path)) self.assertEqual(sorted(type_names), ['__first', '__second', '__third']) def test_list_objects(self): - found_objects = sorted(list(core.CdistObject.list_objects(object_base_path, type_base_path))) + found_objects = sorted(list(core.CdistObject.list_objects(self.object_base_path, type_base_path, OBJECT_MARKER_NAME))) self.assertEqual(found_objects, self.expected_objects) def test_create_singleton(self): @@ -77,41 +89,65 @@ class ObjectClassTestCase(test.CdistTestCase): self.expected_objects[0].object_from_name("__first") class ObjectIdTestCase(test.CdistTestCase): + + def setUp(self): + self.tempdir = tempfile.mkdtemp(prefix="cdist.test") + self.object_base_path = self.tempdir + + self.expected_objects = [] + for cdist_object_name in expected_object_names: + cdist_type, cdist_object_id = cdist_object_name.split("/", 1) + cdist_object = core.CdistObject(core.CdistType(type_base_path, cdist_type), self.object_base_path, + OBJECT_MARKER_NAME, cdist_object_id) + cdist_object.create() + self.expected_objects.append(cdist_object) + + def tearDown(self): + shutil.rmtree(self.tempdir) + def test_object_id_contains_double_slash(self): cdist_type = core.CdistType(type_base_path, '__third') illegal_object_id = '/object_id//may/not/contain/double/slash' with self.assertRaises(core.IllegalObjectIdError): - core.CdistObject(cdist_type, object_base_path, illegal_object_id) + core.CdistObject(cdist_type, self.object_base_path, OBJECT_MARKER_NAME, illegal_object_id) def test_object_id_contains_object_marker(self): cdist_type = core.CdistType(type_base_path, '__third') - illegal_object_id = 'object_id/may/not/contain/%s/anywhere' % core.OBJECT_MARKER + illegal_object_id = 'object_id/may/not/contain/%s/anywhere' % OBJECT_MARKER_NAME with self.assertRaises(core.IllegalObjectIdError): - core.CdistObject(cdist_type, object_base_path, illegal_object_id) + core.CdistObject(cdist_type, self.object_base_path, OBJECT_MARKER_NAME, illegal_object_id) def test_object_id_contains_object_marker_string(self): cdist_type = core.CdistType(type_base_path, '__third') - illegal_object_id = 'object_id/may/contain_%s_in_filename' % core.OBJECT_MARKER - core.CdistObject(cdist_type, object_base_path, illegal_object_id) + illegal_object_id = 'object_id/may/contain_%s_in_filename' % OBJECT_MARKER_NAME + core.CdistObject(cdist_type, self.object_base_path, OBJECT_MARKER_NAME, illegal_object_id) # if we get here, the test passed def test_object_id_contains_only_dot(self): cdist_type = core.CdistType(type_base_path, '__third') illegal_object_id = '.' with self.assertRaises(core.IllegalObjectIdError): - core.CdistObject(cdist_type, object_base_path, illegal_object_id) + core.CdistObject(cdist_type, self.object_base_path, OBJECT_MARKER_NAME, illegal_object_id) def test_object_id_on_singleton_type(self): cdist_type = core.CdistType(type_base_path, '__test_singleton') illegal_object_id = 'object_id' with self.assertRaises(core.IllegalObjectIdError): - core.CdistObject(cdist_type, object_base_path, illegal_object_id) + core.CdistObject(cdist_type, self.object_base_path, OBJECT_MARKER_NAME, illegal_object_id) class ObjectTestCase(test.CdistTestCase): def setUp(self): + self.tempdir = tempfile.mkdtemp(prefix="cdist.test") + self.object_base_path = self.tempdir + self.cdist_type = core.CdistType(type_base_path, '__third') - self.cdist_object = core.CdistObject(self.cdist_type, object_base_path, 'moon') + self.cdist_object = core.CdistObject(self.cdist_type, self.object_base_path, OBJECT_MARKER_NAME, 'moon') + self.cdist_object.create() + + self.cdist_object.parameters['planet'] = 'Saturn' + self.cdist_object.parameters['name'] = 'Prometheus' + def tearDown(self): self.cdist_object.prepared = False @@ -121,6 +157,8 @@ class ObjectTestCase(test.CdistTestCase): self.cdist_object.code_remote = '' self.cdist_object.state = '' + shutil.rmtree(self.tempdir) + def test_name(self): self.assertEqual(self.cdist_object.name, '__third/moon') @@ -128,22 +166,22 @@ class ObjectTestCase(test.CdistTestCase): self.assertEqual(self.cdist_object.object_id, 'moon') def test_path(self): - self.assertEqual(self.cdist_object.path, '__third/moon/.cdist') + self.assertEqual(self.cdist_object.path, "__third/moon/%s" % OBJECT_MARKER_NAME) def test_absolute_path(self): - self.assertEqual(self.cdist_object.absolute_path, os.path.join(object_base_path, '__third/moon/.cdist')) + self.assertEqual(self.cdist_object.absolute_path, os.path.join(self.object_base_path, "__third/moon/%s" % OBJECT_MARKER_NAME)) def test_code_local_path(self): - self.assertEqual(self.cdist_object.code_local_path, '__third/moon/.cdist/code-local') + self.assertEqual(self.cdist_object.code_local_path, "__third/moon/%s/code-local" % OBJECT_MARKER_NAME) def test_code_remote_path(self): - self.assertEqual(self.cdist_object.code_remote_path, '__third/moon/.cdist/code-remote') + self.assertEqual(self.cdist_object.code_remote_path, "__third/moon/%s/code-remote" % OBJECT_MARKER_NAME) def test_parameter_path(self): - self.assertEqual(self.cdist_object.parameter_path, '__third/moon/.cdist/parameter') + self.assertEqual(self.cdist_object.parameter_path, "__third/moon/%s/parameter" % OBJECT_MARKER_NAME) def test_explorer_path(self): - self.assertEqual(self.cdist_object.explorer_path, '__third/moon/.cdist/explorer') + self.assertEqual(self.cdist_object.explorer_path, "__third/moon/%s/explorer" % OBJECT_MARKER_NAME) def test_parameters(self): expected_parameters = {'planet': 'Saturn', 'name': 'Prometheus'} diff --git a/cdist/test/cdist_object/fixtures/object/__third/moon/.cdist/parameter/name b/cdist/test/cdist_object/fixtures/object/__third/moon/.cdist/parameter/name deleted file mode 100644 index 4129a761..00000000 --- a/cdist/test/cdist_object/fixtures/object/__third/moon/.cdist/parameter/name +++ /dev/null @@ -1 +0,0 @@ -Prometheus diff --git a/cdist/test/cdist_object/fixtures/object/__third/moon/.cdist/parameter/planet b/cdist/test/cdist_object/fixtures/object/__third/moon/.cdist/parameter/planet deleted file mode 100644 index 8e6ee422..00000000 --- a/cdist/test/cdist_object/fixtures/object/__third/moon/.cdist/parameter/planet +++ /dev/null @@ -1 +0,0 @@ -Saturn diff --git a/cdist/test/cdist_type/__init__.py b/cdist/test/cdist_type/__init__.py index 36a524b4..ccbf6742 100644 --- a/cdist/test/cdist_type/__init__.py +++ b/cdist/test/cdist_type/__init__.py @@ -153,3 +153,10 @@ class TypeTestCase(test.CdistTestCase): self.assertFalse('optional2' in cdist_type.parameter_defaults) self.assertEqual(cdist_type.parameter_defaults['optional1'], 'value1') + def test_directory_in_default(self): + base_path = fixtures + cdist_type = core.CdistType(base_path, '__directory_in_default') + self.assertEqual( + list(sorted(cdist_type.parameter_defaults.keys())), + ['bar', 'foo'] + ) diff --git a/cdist/test/cdist_type/fixtures/__directory_in_default/parameter/default/a/.gitkeep b/cdist/test/cdist_type/fixtures/__directory_in_default/parameter/default/a/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/cdist/test/cdist_type/fixtures/__directory_in_default/parameter/default/bar b/cdist/test/cdist_type/fixtures/__directory_in_default/parameter/default/bar new file mode 100644 index 00000000..e69de29b diff --git a/cdist/test/cdist_type/fixtures/__directory_in_default/parameter/default/foo b/cdist/test/cdist_type/fixtures/__directory_in_default/parameter/default/foo new file mode 100644 index 00000000..e69de29b diff --git a/cdist/test/cdist_type/fixtures/__directory_in_default/parameter/optional b/cdist/test/cdist_type/fixtures/__directory_in_default/parameter/optional new file mode 100644 index 00000000..3bd1f0e2 --- /dev/null +++ b/cdist/test/cdist_type/fixtures/__directory_in_default/parameter/optional @@ -0,0 +1,2 @@ +foo +bar diff --git a/cdist/test/code/__init__.py b/cdist/test/code/__init__.py index 796e8a51..689fcff6 100644 --- a/cdist/test/code/__init__.py +++ b/cdist/test/code/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # 2011 Steven Armstrong (steven-cdist at armstrong.cc) -# 2012-2013 Nico Schottelius (nico-cdist at schottelius.org) +# 2012-2015 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -61,7 +61,7 @@ class CodeTestCase(test.CdistTestCase): self.code = code.Code(self.target_host, self.local, self.remote) self.cdist_type = core.CdistType(self.local.type_path, '__dump_environment') - self.cdist_object = core.CdistObject(self.cdist_type, self.local.object_path, 'whatever') + self.cdist_object = core.CdistObject(self.cdist_type, self.local.object_path, 'whatever', self.local.object_marker_name) self.cdist_object.create() def tearDown(self): diff --git a/cdist/test/config/__init__.py b/cdist/test/config/__init__.py index 70501c89..a36567de 100644 --- a/cdist/test/config/__init__.py +++ b/cdist/test/config/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) -# 2012-2013 Nico Schottelius (nico-cdist at schottelius.org) +# 2012-2015 Nico Schottelius (nico-cdist at schottelius.org) # 2014 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. @@ -23,6 +23,7 @@ import os import shutil +import tempfile from cdist import test from cdist import core @@ -35,10 +36,14 @@ import cdist.core.cdist_object import os.path as op my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') -object_base_path = op.join(fixtures, 'object') type_base_path = op.join(fixtures, 'type') add_conf_dir = op.join(fixtures, 'conf') +expected_object_names = sorted([ + '__first/man', + '__second/on-the', + '__third/moon']) + class ConfigRunTestCase(test.CdistTestCase): def setUp(self): @@ -54,6 +59,20 @@ class ConfigRunTestCase(test.CdistTestCase): target_host=self.target_host, base_path=self.local_dir) + # Setup test objects + self.object_base_path = op.join(self.temp_dir, 'object') + + self.objects = [] + for cdist_object_name in expected_object_names: + cdist_type, cdist_object_id = cdist_object_name.split("/", 1) + cdist_object = core.CdistObject(core.CdistType(type_base_path, cdist_type), self.object_base_path, + self.local.object_marker_name, cdist_object_id) + cdist_object.create() + self.objects.append(cdist_object) + + self.object_index = dict((o.name, o) for o in self.objects) + self.object_names = [o.name for o in self.objects] + self.remote_dir = os.path.join(self.temp_dir, "remote") os.mkdir(self.remote_dir) self.remote = cdist.exec.remote.Remote( @@ -62,15 +81,11 @@ class ConfigRunTestCase(test.CdistTestCase): remote_exec=self.remote_exec, base_path=self.remote_dir) - self.local.object_path = object_base_path + self.local.object_path = self.object_base_path self.local.type_path = type_base_path self.config = cdist.config.Config(self.local, self.remote) - self.objects = list(core.CdistObject.list_objects(object_base_path, type_base_path)) - self.object_index = dict((o.name, o) for o in self.objects) - self.object_names = [o.name for o in self.objects] - def tearDown(self): for o in self.objects: o.requirements = [] diff --git a/cdist/test/emulator/__init__.py b/cdist/test/emulator/__init__.py index 870d6245..f90e5320 100644 --- a/cdist/test/emulator/__init__.py +++ b/cdist/test/emulator/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) -# 2012-2013 Nico Schottelius (nico-cdist at schottelius.org) +# 2012-2015 Nico Schottelius (nico-cdist at schottelius.org) # 2014 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. @@ -57,10 +57,15 @@ class EmulatorTestCase(test.CdistTestCase): self.manifest = core.Manifest(self.target_host, self.local) self.env = self.manifest.env_initial_manifest(self.script) + self.env['__cdist_object_marker'] = self.local.object_marker_name def tearDown(self): shutil.rmtree(self.temp_dir) +# def test_missing_object_marker_variable(self): +# del self.env['__cdist_object_marker'] +# self.assertRaises(KeyError, emulator.Emulator, argv, env=self.env) + def test_nonexistent_type_exec(self): argv = ['__does-not-exist'] self.assertRaises(core.cdist_type.NoSuchTypeError, emulator.Emulator, argv, env=self.env) @@ -73,7 +78,7 @@ class EmulatorTestCase(test.CdistTestCase): def test_illegal_object_id_requirement(self): argv = ['__file', '/tmp/foobar'] - self.env['require'] = '__file/bad/id/with/.cdist/inside' + self.env['require'] = "__file/bad/id/with/%s/inside" % self.local.object_marker_name emu = emulator.Emulator(argv, env=self.env) self.assertRaises(core.IllegalObjectIdError, emu.run) @@ -118,10 +123,10 @@ class EmulatorTestCase(test.CdistTestCase): 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') + erde_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, 'erde') + mars_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, 'mars') cdist_type = core.CdistType(self.local.type_path, '__file') - file_object = core.CdistObject(cdist_type, self.local.object_path, '/tmp/cdisttest') + file_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, '/tmp/cdisttest') # now test the recorded requirements self.assertTrue(len(erde_object.requirements) == 0) self.assertEqual(list(mars_object.requirements), ['__planet/erde']) @@ -150,7 +155,7 @@ class AutoRequireEmulatorTestCase(test.CdistTestCase): initial_manifest = os.path.join(self.local.manifest_path, "init") self.manifest.run_initial_manifest(initial_manifest) cdist_type = core.CdistType(self.local.type_path, '__saturn') - cdist_object = core.CdistObject(cdist_type, self.local.object_path) + cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, '') self.manifest.run_type_manifest(cdist_object) expected = ['__planet/Saturn', '__moon/Prometheus'] self.assertEqual(sorted(cdist_object.autorequire), sorted(expected)) @@ -172,6 +177,7 @@ class OverrideTestCase(test.CdistTestCase): self.manifest = core.Manifest(self.target_host, self.local) self.env = self.manifest.env_initial_manifest(self.script) + self.env['__cdist_object_marker'] = self.local.object_marker_name def tearDown(self): shutil.rmtree(self.temp_dir) @@ -211,6 +217,7 @@ class ArgumentsTestCase(test.CdistTestCase): self.manifest = core.Manifest(self.target_host, self.local) self.env = self.manifest.env_initial_manifest(self.script) + self.env['__cdist_object_marker'] = self.local.object_marker_name def tearDown(self): shutil.rmtree(self.temp_dir) @@ -222,7 +229,7 @@ class ArgumentsTestCase(test.CdistTestCase): emu.run() cdist_type = core.CdistType(self.local.type_path, '__arguments_with_dashes') - cdist_object = core.CdistObject(cdist_type, self.local.object_path, 'some-id') + cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, 'some-id') self.assertTrue('with-dash' in cdist_object.parameters) def test_boolean(self): @@ -234,7 +241,7 @@ class ArgumentsTestCase(test.CdistTestCase): emu.run() cdist_type = core.CdistType(self.local.type_path, type_name) - cdist_object = core.CdistObject(cdist_type, self.local.object_path, object_id) + cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, object_id) self.assertTrue('boolean1' in cdist_object.parameters) self.assertFalse('boolean2' in cdist_object.parameters) # empty file -> True @@ -242,17 +249,17 @@ class ArgumentsTestCase(test.CdistTestCase): def test_required_arguments(self): """check whether assigning required parameter works""" + type_name = '__arguments_required' object_id = 'some-id' value = 'some value' argv = [type_name, object_id, '--required1', value, '--required2', value] -# print(self.env) os.environ.update(self.env) emu = emulator.Emulator(argv) emu.run() cdist_type = core.CdistType(self.local.type_path, type_name) - cdist_object = core.CdistObject(cdist_type, self.local.object_path, object_id) + cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, object_id) self.assertTrue('required1' in cdist_object.parameters) self.assertTrue('required2' in cdist_object.parameters) self.assertEqual(cdist_object.parameters['required1'], value) @@ -278,7 +285,7 @@ class ArgumentsTestCase(test.CdistTestCase): emu.run() cdist_type = core.CdistType(self.local.type_path, type_name) - cdist_object = core.CdistObject(cdist_type, self.local.object_path, object_id) + cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, object_id) self.assertTrue('optional1' in cdist_object.parameters) self.assertFalse('optional2' in cdist_object.parameters) self.assertEqual(cdist_object.parameters['optional1'], value) @@ -293,7 +300,7 @@ class ArgumentsTestCase(test.CdistTestCase): emu.run() cdist_type = core.CdistType(self.local.type_path, type_name) - cdist_object = core.CdistObject(cdist_type, self.local.object_path, object_id) + cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, object_id) self.assertTrue('optional1' in cdist_object.parameters) self.assertFalse('optional2' in cdist_object.parameters) self.assertEqual(cdist_object.parameters['optional1'], value) @@ -316,10 +323,6 @@ class StdinTestCase(test.CdistTestCase): self.local.create_files_dirs() - self.manifest = core.Manifest( - target_host=self.target_host, - local = self.local) - def tearDown(self): os.environ = self.orig_environ shutil.rmtree(self.temp_dir) @@ -340,13 +343,16 @@ class StdinTestCase(test.CdistTestCase): object_id = "cdist-test-id" argv = [type_name, object_id] - initial_manifest_path = "/cdist-test/path/that/does/not/exist" - env = self.manifest.env_initial_manifest(initial_manifest_path) + env = os.environ.copy() + env['__cdist_manifest'] = "/cdist-test/path/that/does/not/exist" + env['__cdist_object_marker'] = self.local.object_marker_name + env['__cdist_type_base_path'] = self.local.type_path + env['__global'] = self.local.base_path ###################################################################### # Create path where stdin should reside at cdist_type = core.CdistType(self.local.type_path, type_name) - cdist_object = core.CdistObject(cdist_type, self.local.object_path, object_id) + cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, object_id) stdin_out_path = os.path.join(cdist_object.absolute_path, 'stdin') ###################################################################### diff --git a/cdist/test/exec/fixtures/conf/type/__cdist_test_type/gencode-local b/cdist/test/exec/fixtures/conf/type/__cdist_test_type/gencode-local new file mode 100755 index 00000000..771894fb --- /dev/null +++ b/cdist/test/exec/fixtures/conf/type/__cdist_test_type/gencode-local @@ -0,0 +1,8 @@ +#!/bin/sh + +echo "echo __target_host: $__target_host" +echo "echo __global: $__global" +echo "echo __type: $__type" +echo "echo __object: $__object" +echo "echo __object_id: $__object_id" +echo "echo __object_name: $__object_name" diff --git a/cdist/test/exec/fixtures/conf/type/__cdist_test_type/gencode-remote b/cdist/test/exec/fixtures/conf/type/__cdist_test_type/gencode-remote new file mode 120000 index 00000000..7b427cac --- /dev/null +++ b/cdist/test/exec/fixtures/conf/type/__cdist_test_type/gencode-remote @@ -0,0 +1 @@ +gencode-local \ No newline at end of file diff --git a/cdist/test/exec/local.py b/cdist/test/exec/local.py index 6cb0c605..12a0d47b 100644 --- a/cdist/test/exec/local.py +++ b/cdist/test/exec/local.py @@ -2,6 +2,7 @@ # # 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) # 2012 Nico Schottelius (nico-cdist at schottelius.org) +# 2016 Darko Poljak (darko.poljak at gmail.com) # # This file is part of cdist. # @@ -35,17 +36,21 @@ my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') conf_dir = op.join(fixtures, "conf") +bin_true = "true" +bin_false = "false" + class LocalTestCase(test.CdistTestCase): def setUp(self): target_host = 'localhost' self.temp_dir = self.mkdtemp() - self.out_path = self.temp_dir + self.out_parent_path = self.temp_dir + self.out_path = op.join(self.out_parent_path, target_host) self.local = local.Local( target_host=target_host, - out_path=self.out_path, + base_path=self.out_parent_path, exec_path=test.cdist_exec_path ) @@ -63,7 +68,7 @@ class LocalTestCase(test.CdistTestCase): self.assertEqual(self.local.conf_path, os.path.join(self.out_path, "conf")) def test_out_path(self): - self.assertEqual(self.local.out_path, self.out_path) + self.assertEqual(self.local.base_path, self.out_path) def test_bin_path(self): self.assertEqual(self.local.bin_path, os.path.join(self.out_path, "bin")) @@ -94,7 +99,7 @@ class LocalTestCase(test.CdistTestCase): link_test_local = local.Local( target_host='localhost', - out_path=self.out_path, + base_path=self.out_parent_path, exec_path=test.cdist_exec_path, ) @@ -111,7 +116,7 @@ class LocalTestCase(test.CdistTestCase): link_test_local = local.Local( target_host='localhost', - out_path=self.out_path, + base_path=self.out_parent_path, exec_path=test.cdist_exec_path, add_conf_dirs=[conf_dir] ) @@ -131,7 +136,7 @@ class LocalTestCase(test.CdistTestCase): link_test_local = local.Local( target_host='localhost', - out_path=self.out_path, + base_path=self.out_parent_path, exec_path=test.cdist_exec_path, ) @@ -144,21 +149,21 @@ class LocalTestCase(test.CdistTestCase): ### other tests def test_run_success(self): - self.local.run(['/bin/true']) + self.local.run([bin_true]) def test_run_fail(self): - self.assertRaises(cdist.Error, self.local.run, ['/bin/false']) + self.assertRaises(cdist.Error, self.local.run, [bin_false]) def test_run_script_success(self): handle, script = self.mkstemp(dir=self.temp_dir) with os.fdopen(handle, "w") as fd: - fd.writelines(["#!/bin/sh\n", "/bin/true"]) + fd.writelines(["#!/bin/sh\n", bin_true]) self.local.run_script(script) def test_run_script_fail(self): handle, script = self.mkstemp(dir=self.temp_dir) with os.fdopen(handle, "w") as fd: - fd.writelines(["#!/bin/sh\n", "/bin/false"]) + fd.writelines(["#!/bin/sh\n", bin_false]) self.assertRaises(cdist.Error, self.local.run_script, script) def test_run_script_get_output(self): @@ -180,6 +185,11 @@ class LocalTestCase(test.CdistTestCase): def test_create_files_dirs(self): self.local.create_files_dirs() - self.assertTrue(os.path.isdir(self.local.out_path)) + self.assertTrue(os.path.isdir(self.local.base_path)) self.assertTrue(os.path.isdir(self.local.bin_path)) self.assertTrue(os.path.isdir(self.local.conf_path)) + +if __name__ == "__main__": + import unittest + + unittest.main() diff --git a/cdist/test/exec/remote.py b/cdist/test/exec/remote.py index 8e7d408a..89e9dbc8 100644 --- a/cdist/test/exec/remote.py +++ b/cdist/test/exec/remote.py @@ -39,7 +39,7 @@ class RemoteTestCase(test.CdistTestCase): user = getpass.getuser() remote_exec = "ssh -o User=%s -q" % user remote_copy = "scp -o User=%s -q" % user - self.remote = remote.Remote(self.target_host, self.base_path, remote_exec, remote_copy) + self.remote = remote.Remote(self.target_host, base_path=self.base_path, remote_exec=remote_exec, remote_copy=remote_copy) def tearDown(self): shutil.rmtree(self.temp_dir) @@ -125,7 +125,7 @@ class RemoteTestCase(test.CdistTestCase): os.chmod(remote_exec_path, 0o755) remote_exec = remote_exec_path remote_copy = "echo" - r = remote.Remote(self.target_host, self.base_path, remote_exec, remote_copy) + r = remote.Remote(self.target_host, base_path=self.base_path, remote_exec=remote_exec, remote_copy=remote_copy) self.assertEqual(r.run('/bin/true', return_output=True), "%s\n" % self.target_host) def test_run_script_target_host_in_env(self): @@ -135,8 +135,40 @@ class RemoteTestCase(test.CdistTestCase): os.chmod(remote_exec_path, 0o755) remote_exec = remote_exec_path remote_copy = "echo" - r = remote.Remote(self.target_host, self.base_path, remote_exec, remote_copy) + r = remote.Remote(self.target_host, base_path=self.base_path, remote_exec=remote_exec, remote_copy=remote_copy) handle, script = self.mkstemp(dir=self.temp_dir) with os.fdopen(handle, "w") as fd: fd.writelines(["#!/bin/sh\n", "/bin/true"]) self.assertEqual(r.run_script(script, return_output=True), "%s\n" % self.target_host) + + def test_run_script_with_env_target_host_in_env(self): + handle, script = self.mkstemp(dir=self.temp_dir) + with os.fdopen(handle, "w") as fd: + fd.writelines(["#!/bin/sh\n", 'if [ "$__object" ]; then echo $__object; else echo no_env; fi\n']) + os.chmod(script, 0o755) + handle, remote_exec_path = self.mkstemp(dir=self.temp_dir) + with os.fdopen(handle, 'w') as fd: + fd.writelines(["#!/bin/sh\n", 'shift; cmd=$1; shift; $cmd "$@"\n']) + os.chmod(remote_exec_path, 0o755) + remote_exec = remote_exec_path + remote_copy = "echo" + r = remote.Remote(self.target_host, base_path=self.base_path, remote_exec=remote_exec, remote_copy=remote_copy) + output = r.run_script(script, return_output=True) + self.assertEqual(output, "no_env\n") + + handle, remote_exec_path = self.mkstemp(dir=self.temp_dir) + with os.fdopen(handle, 'w') as fd: + fd.writelines(["#!/bin/sh\n", 'shift; cmd=$1; eval $cmd\n']) + os.chmod(remote_exec_path, 0o755) + remote_exec = remote_exec_path + env = { + '__object': 'test_object', + } + r = remote.Remote(self.target_host, base_path=self.base_path, remote_exec=remote_exec, remote_copy=remote_copy) + output = r.run_script(script, env=env, return_output=True) + self.assertEqual(output, "test_object\n") + +if __name__ == '__main__': + import unittest + + unittest.main() diff --git a/cdist/test/explorer/__init__.py b/cdist/test/explorer/__init__.py index 92ef75a3..335d0e32 100644 --- a/cdist/test/explorer/__init__.py +++ b/cdist/test/explorer/__init__.py @@ -127,7 +127,7 @@ class ExplorerClassTestCase(test.CdistTestCase): def test_transfer_object_parameters(self): cdist_type = core.CdistType(self.local.type_path, '__test_type') - cdist_object = core.CdistObject(cdist_type, self.local.object_path, 'whatever') + cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, 'whatever') cdist_object.create() cdist_object.parameters = {'first': 'first value', 'second': 'second value'} self.explorer.transfer_object_parameters(cdist_object) @@ -137,14 +137,14 @@ class ExplorerClassTestCase(test.CdistTestCase): def test_run_type_explorer(self): cdist_type = core.CdistType(self.local.type_path, '__test_type') - cdist_object = core.CdistObject(cdist_type, self.local.object_path, 'whatever') + cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, 'whatever') self.explorer.transfer_type_explorers(cdist_type) output = self.explorer.run_type_explorer('world', cdist_object) self.assertEqual(output, 'hello\n') def test_run_type_explorers(self): cdist_type = core.CdistType(self.local.type_path, '__test_type') - cdist_object = core.CdistObject(cdist_type, self.local.object_path, 'whatever') + cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, 'whatever') cdist_object.create() self.explorer.run_type_explorers(cdist_object) self.assertEqual(cdist_object.explorers, {'world': 'hello'}) diff --git a/cdist/test/manifest/__init__.py b/cdist/test/manifest/__init__.py index c375a80f..cc60c844 100644 --- a/cdist/test/manifest/__init__.py +++ b/cdist/test/manifest/__init__.py @@ -84,7 +84,7 @@ class ManifestTestCase(test.CdistTestCase): def test_type_manifest_environment(self): cdist_type = core.CdistType(self.local.type_path, '__dump_environment') - cdist_object = core.CdistObject(cdist_type, self.local.object_path, 'whatever') + cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, 'whatever') handle, output_file = self.mkstemp(dir=self.temp_dir) os.close(handle) os.environ['__cdist_test_out'] = output_file 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 84462764..dada1d90 100644 --- a/docs/changelog +++ b/docs/changelog @@ -1,15 +1,138 @@ Changelog --------- - * Changes are always commented with their author in (braces) - * Exception: No braces means author == Nico Schottelius +4.1.0: 2016-05-27 + * Documentation: Migrate to reStructuredText format and sphinx (Darko Poljak) + * Core: Add -f option to read additional hosts from file/stdin (Darko Poljak) + * Type __apt_key: Use pool.sks-keyservers.net as keyserver (Steven Armstrong) +4.0.0: 2016-05-04 + * Core: Fix bug with parallel hosts operation when output path is specifed (Darko Poljak) + * Type __package_pip: Add support for running as specified user (useful for pip in venv) (Darko Poljak) + * New type: __pyvenv: Manage python virtualenv (Darko Poljak) + * Core: Add CDIST_REMOTE_COPY/EXEC env variables and multiplexing options for default scp/ssh (Darko Poljak) + * Types: Remove bashisms in scripts (Darko Poljak) + * Core: Fix bug in remote command with environment (Darko Poljak) + * Core: Fix bug in local code execution (Darko Poljak) + * Documentation: Fix spelling in manual pages (Dmitry Bogatov) + * New type: __pacman_conf: Manage pacman.conf (Dominique Roux) + * New type: __pacman_conf_integrate: cdist compatible pacman.conf (Dominique Roux) + * Type __consul: Do not install unused package unzip (Steven Armstrong) + * Type __consul: Add source & cksum for 0.5.2 (Steven Armstrong) + * Core: Support object ids '.cdist' (Nico Schottelius) + * Type __apt_norecommends: Also setup autoremove options (Dmitry Bogatov) + * Type __user_groups: Add NetBSD support (Jonathan A. Kollasch) + * Type __timezone: Add NetBSD support (Jonathan A. Kollasch) + * Type __ccollect_source: Add NetBSD support (Jonathan A. Kollasch) + * Type __directory: Add NetBSD support (Jonathan A. Kollasch) + * Type __file: Add NetBSD support (Jonathan A. Kollasch) + * Type __group: Add NetBSD support (Jonathan A. Kollasch) + * Type __consul: Add new consul versions (Nico Schottelius) + * Type __apt_ppa: Do not install legacy package python-software-properties (Steven Armstrong) + +3.1.13: 2015-05-16 + * Type __block: Fix support for non stdin blocks (Dominique Roux) + * Type __consul: Install package unzip (Nico Schottelius) + * Type __consul: Add source & cksum for 0.5.1 (Nico Schottelius) + * Type __consul_agent: Use systemd for Debian 8 (Nico Schottelius) + * Type __firewalld_rule: Ensure firewalld package is present (David Hürlimann) + * Type __locale: Support CentOS (David Hürlimann) + * Type __staged_file: Fix comparision operator (Nico Schottelius) + * Type __user_groups: Support old Linux versions (Daniel Heule) + +3.1.12: 2015-03-19 + * Core: Support object ids '.cdist' (Nico Schottelius) + * New type: __firewalld_rule (Nico Schottelius) + * Type __consul_agent: add support for acl options (Steven Armstrong) + * Type __consul_agent: add support for Debian (Nico Schottelius) + * Type __package_apt: Use default parameters (Antoine Catton) + * Type __package_luarocks: Use default parameters (Antoine Catton) + * Type __package_opkg: Use default parameters (Antoine Catton) + * Type __package_pacman: Use default parameters (Antoine Catton) + * Type __package_pip: Use default parameters (Antoine Catton) + * Type __package_pkg_freebsd: Use default parameters (Antoine Catton) + * Type __package_pkg_openbsd: Use default parameters (Antoine Catton) + * Type __package_pkgng_openbsd: Use default parameters (Antoine Catton) + +3.1.11: 2015-02-27 + * New type: __staged_file: Manage staged files (Steven Armstrong) + * New type: __config_file: Manage configuration files and run code on change (Steven Armstrong) + * New type: __consul: install consul (Steven Armstrong) + * New type: __consul_agent: manage the consul agent (Steven Armstrong) + * New type: __consul_check: manages consul checks (Steven Armstrong) + * New type: __consul_reload: reload consul (Steven Armstrong) + * New type: __consul_service: manages consul services (Steven Armstrong) + * New type: __consul_template: manage the consul-template service (Steven Armstrong) + * New type: __consul_template_template: manage consul-template templates (Steven Armstrong) + * New type: __consul_watch_checks: manages consul checks watches (Steven Armstrong) + * New type: __consul_watch_event: manages consul event watches (Steven Armstrong) + * New type: __consul_watch_key: manages consul key watches (Steven Armstrong) + * New type: __consul_watch_keyprefix: manages consul keyprefix watches (Steven Armstrong) + * New type: __consul_watch_nodes: manages consul nodes watches (Steven Armstrong) + * New type: __consul_watch_service: manages consul service watches (Steven Armstrong) + * New type: __consul_watch_services: manages consul services watches (Steven Armstrong) + * New Type: __rsync (Nico Schottelius) + * Type __start_on_boot: Support Ubuntu upstart (Nico Schottelius) + * Type __timezone: Added support for FreeBSD (Christian Kruse) + +3.1.10: 2015-02-10 + * Core: Fix too many open files bug (#343) + * Type __ssh_authorized_keys: Remove unneeded explorer (Steven Armstrong) + * Type __ssh_authorized_keys: Fix empty output bug of entry explorer (Steven Armstrong) + * Type __package_apt: Add support for --target-release (Nico Schottelius) + * Type __locale: Add support for Ubuntu (Nico Schottelius) + * Type __group: Rewrite (Steven Armstrong) + * Documentation: Fix typo in maintainer file (Stephan Kulla) + +3.1.9: 2014-10-17 + * Type __package_emerge: Fix handling of slotted packages (Daniel Heule) + * Type __package_apt: Use --force-confdef (Ricardo Catalinas Jiménez) + * Type __package_update_index: Decrease verbosity (Ricardo Catalinas Jiménez) + * Type __package_upgrade_all: Decrease verbosity (Ricardo Catalinas Jiménez) + +3.1.8: 2014-10-01 + * New Type: __package_update_index (Ricardo Catalinas Jiménez) + * New Type: __package_upgrade_all (Ricardo Catalinas Jiménez) + +3.1.7: 2014-09-29 + * Type __cdistmarker: Fix typo (Ricardo Catalinas Jiménez) + * Core: Bugfix: Export messaging to manifests (Ricardo Catalinas Jiménez) + * Explorer cpu_cores, cpu_sockets, memory: Add Mac OS X support (Manuel Hutter) + * Type __ssh_authorized_keys: Ensure keys are correctly added (Steven Armstrong) + * New Type: __ssh_authorized_key (Steven Armstrong) + * New Type: __package_pkgng_freebsd (Jake Guffey) + +3.1.6: 2014-08-18 + * New Type: __ssh_dot_ssh (Nico Schottelius) + * Type __package_yum: Support retrieving package via URL (Nico Schottelius) + * Type __hostname: Support SuSE and have CentOS use sysconfig value (Nico Schottelius) + * Type __locale: Support SuSE (Nico Schottelius) + * Type __locale: Support Archlinux (Nico Schottelius) + * Type __timezone: Support SuSE (Nico Schottelius) + * Type __file: Support MacOS X (Manuel Hutter) + * Type __iptables_apply: Add "reset" to init.d script of iptables (Nico Schottelius) + * Type __ssh_authorized_key: Use new type __ssh_dot_ssh (Nico Schottelius) + * Type __zypper_repo: Bugfix for pattern matching (Daniel Heule) + +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 (Nico Schottelius) 3.1.2: 2014-04-12 - * Documentation: Add missing environment variables to reference - * Type __qemu_img: size is optional, if state is not present + * Documentation: Add missing environment variables to reference (Nico Schottelius) + * Type __qemu_img: size is optional, if state is not present (Nico Schottelius) * Type __key_value: Rewrite using awk (Daniel Heule) - * New Type: __dog_vdi + * New Type: __dog_vdi (Nico Schottelius) 3.1.1: 2014-03-26 * Core: Make __object and __object_id available to code (Daniel Heule) @@ -23,11 +146,11 @@ Changelog * Type __package_pkg_openbsd: Improve error handling (og) 3.1.0: 2014-03-19 - * New Type: __rbenv + * New Type: __rbenv (Nico Schottelius) * Type __file: Enhance OpenBSD Support (og) - * Type __git: Pass onwer/group/mode values to __directory + * Type __git: Pass onwer/group/mode values to __directory (Nico Schottelius) * Type __iptable_rule: Fix example documentation (Antoine Catton) - * Type __key_value: Add messaging support + * Type __key_value: Add messaging support (Nico Schottelius) * 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) @@ -35,7 +158,7 @@ Changelog 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 __locale: Error out in case of unsupported OS (Nico Schottelius) * 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) @@ -59,7 +182,7 @@ Changelog * New Type: __apt_key_uri (Steven Armstrong) * New Type: __apt_norecommends (Steven Armstrong) * New Type: __apt_source (Steven Armstrong) - * New Type: __ccollect_source + * New Type: __ccollect_source (Nico Schottelius) * Type __git: Use default parameters (Daniel Heule) * Type __jail: Use default parameters (Daniel Heule) * Type __package_yum: Use default parameters (Daniel Heule) @@ -69,24 +192,24 @@ Changelog 3.0.5: 2014-02-05 * Core: Introduce override concept (Daniel Heule) * Type __process: Make --state absent work (Steven Armstrong) - * Documentation: Update documentation for environment variables + * Documentation: Update documentation for environment variables (Nico Schottelius) 3.0.4: 2014-01-29 - * Core: Ignore install types in config mode - * Documentation: Update reference (files path in object space) - * Documentation: Update best practise: Replaces templates/ with files/ + * Core: Ignore install types in config mode (Nico Schottelius) + * Documentation: Update reference (files path in object space) (Nico Schottelius) + * Documentation: Update best practise: Replaces templates/ with files/ (Nico Schottelius) * Type __apt_ppa: Install required software (Steven Armstrong) - * Type __debconf_set_selections: Support --file - to read from stdin + * Type __debconf_set_selections: Support --file - to read from stdin (Nico Schottelius) * Type __jail: Fix jaildir parameter handling (Jake Guffey) 3.0.3: 2014-01-22 - * Core: Enhance error message when requirement is missing object id + * Core: Enhance error message when requirement is missing object id (Nico Schottelius) * Core: Add environment variable to select shell for executing scripts (Daniel Heule) - * Explorer hostname: Return host name by using uname -n + * Explorer hostname: Return host name by using uname -n (Nico Schottelius) * New Type: __hostname (Steven Armstrong) * Type __cdist: Use default paremeters (Daniel Heule) * Type __key_value: Use default paremeters (Daniel Heule) - * Type __line: Use printf instead of echo for printing user input + * Type __line: Use printf instead of echo for printing user input (Nico Schottelius) * Type __qemu_img: Use default paremeters (Daniel Heule) * Type __zypper_repo: Use default paremeters (Daniel Heule) * Type __zypper_service: Use default paremeters (Daniel Heule) @@ -100,16 +223,16 @@ Changelog 3.0.1: 2014-01-14 * Core: Copy only files, not directories (Steven Armstrong) - * Core: Allow hostnames to start with / - * Type __line: Remove unecessary backslash escape + * Core: Allow hostnames to start with / (Nico Schottelius) + * Type __line: Remove unecessary backslash escape (Nico Schottelius) * Type __directory: Add messaging support (Daniel Heule) * Type __directory: Do not generate code if mode is 0xxx (Daniel Heule) * Type __package: Fix typo in optional parameter ptype (Daniel Heule) * Type __start_on_boot: Fix for SuSE's chkconfig (Daniel Heule) 3.0.0: 2013-12-24 - * Core: Added messaging support - * Core: Removed unused "changed" attribute of objects + * Core: Added messaging support (Nico Schottelius) + * Core: Removed unused "changed" attribute of objects (Nico Schottelius) * Core: Support default values for multiple parameters (Steven Armstrong) * Core: Ensure Object Parameter file contains \n (Steven Armstrong) * New Type: __zypper_repo (Daniel Heule) @@ -119,8 +242,8 @@ Changelog * Type __cron: Add support for raw lines (Daniel Heule) * Type __cron: Suppress stderr output from crontab (Daniel Heule) * Type __cron: Fix quoting issue (Daniel Heule) - * Type __file: Do not generate code if mode is 0xxx - * Type __iptables_rule: Use default parameter + * Type __file: Do not generate code if mode is 0xxx (Nico Schottelius) + * Type __iptables_rule: Use default parameter (Nico Schottelius) * Type __key_value: Fix quoting issue (Steven Armstrong) * Type __package: Use state --present by default (Steven Armstrong) * Type __package_zypper: Support non packages as well (Daniel Heule) @@ -128,7 +251,7 @@ Changelog * Type __postfix_*: Depend on __postfix Type (Steven Armstrong) * Type __postfix_postconf: Enable support for SuSE (Daniel Heule) * Type __postfix: Enable support for SuSE (Daniel Heule) - * Type __start_on_boot: Use default parameter state + * Type __start_on_boot: Use default parameter state (Nico Schottelius) * Type __start_on_boot: Add support for gentoo (Daniel Heule) * Type __user: Add support for state parameter (Daniel Heule) * Type __user: Add support for system users (Daniel Heule) @@ -140,19 +263,19 @@ Changelog * Type __file: Only remove file when state is absent (Steven Armstrong) * Type __link: Only remove link when state is absent (Steven Armstrong) * Type __directory: Only remove directory when state is absent (Steven Armstrong) - * Type __directory: Fix newly introduced quoting issue + * Type __directory: Fix newly introduced quoting issue (Nico Schottelius) * Type __package_zypper: Fix explorer and parameter issue (Daniel Heule) - * Core: Fix backtrace when cache cannot be deleted + * Core: Fix backtrace when cache cannot be deleted (Nico Schottelius) 2.3.6: 2013-11-25 - * New Type: __locale - * Type __line: Ensure special characters are not interpreted + * New Type: __locale (Nico Schottelius) + * Type __line: Ensure special characters are not interpreted (Nico Schottelius) 2.3.5: 2013-10-10 * Core: Unit test fix for remote_copy (Steven Armstrong) * Documentation: Updated manpages of __package and __file (Alex Greif) * Documentation: Add more examples to cdist-manifest (Dan Levin) - * Type __package_apt: Do not install recommends by default + * Type __package_apt: Do not install recommends by default (Nico Schottelius) 2.3.4: 2013-10-03 * Core: Add missing bits to support dry run (Steven Armstrong) @@ -170,51 +293,51 @@ Changelog * Type __start_on_boot: Bugfix for systemd (Steven Armstrong) 2.3.2: 2013-09-05 - * Build: Ensure tests don't change attributes of non-test files - * Core: Fix typo in argument parser + * Build: Ensure tests don't change attributes of non-test files (Nico Schottelius) + * Core: Fix typo in argument parser (Nico Schottelius) * Core: Code cleanup: Remove old install code (Steven Armstrong) - * Core: Improve error message when using non-existing type in requirement - * New Type: __iptables_rule - * New Type: __iptables_apply - * Type __cdist: Also create home directory - * Type __cdist: Add support for --shell parameter - * Type __motd: Regenerate motd on Debian and Ubuntu + * Core: Improve error message when using non-existing type in requirement (Nico Schottelius) + * New Type: __iptables_rule (Nico Schottelius) + * New Type: __iptables_apply (Nico Schottelius) + * Type __cdist: Also create home directory (Nico Schottelius) + * Type __cdist: Add support for --shell parameter (Nico Schottelius) + * Type __motd: Regenerate motd on Debian and Ubuntu (Nico Schottelius) 2.3.1: 2013-08-28 - * Core: Support relative paths for configuration directories - * Core: Code cleanup (removed context class, added log class) - * Documentation: Add more best practises - * Documentation: Add troubleshooting chapter + * Core: Support relative paths for configuration directories (Nico Schottelius) + * Core: Code cleanup (removed context class, added log class) (Nico Schottelius) + * Documentation: Add more best practises (Nico Schottelius) + * Documentation: Add troubleshooting chapter (Nico Schottelius) * Type __key_value: Fix quoting problem (Steven Armstrong) 2.3.0: 2013-08-12 - * Core: Added support for cdist shell - * Documentation: Improved some manpages + * Core: Added support for cdist shell (Nico Schottelius) + * Documentation: Improved some manpages (Nico Schottelius) 2.2.0: 2013-07-12 - * Build: Cleanup the Makefile - * Type __package_opkg: Use shortcut version + * Build: Cleanup the Makefile (Nico Schottelius) + * Type __package_opkg: Use shortcut version (Nico Schottelius) * Core: Remove old pseudo object id "singleton" (Steven Armstrong) 2.1.2: 2013-07-09 - * Build: Change clean-dist target to "distclean" + * Build: Change clean-dist target to "distclean" (Nico Schottelius) * Build: Moved a lot of build logic into Makefile for dependency resolution * Core: Make global explorers available to initial manifest (Arkaitz Jimenez) - * Core: Change execution order to run object as one unit + * Core: Change execution order to run object as one unit (Nico Schottelius) * Documentation: Improved documentation (Tomáš Pospíšek) * New Remote Example: Add support for sudo operations (Chase James) - * New Type: __update_alternatives - * New Type: __cdist + * New Type: __update_alternatives (Nico Schottelius) + * New Type: __cdist (Nico Schottelius) * Type __apt_ppa: Fix comparison operator (Tyler Akins) - * Type __start_on_boot: Archlinux changed to use systemd - adapt type + * Type __start_on_boot: Archlinux changed to use systemd - adapt type (Nico Schottelius) * Type __git: Missing quotes added (Chase James) * Type __postgres_database: Make state parameter optional (Chase James) * Type __postgres_role: Make state parameter optional, fix password bug (Chase James) - * Type __process: Make state parameter optional - * Type __cron: Simplyfied and syntax change + * Type __process: Make state parameter optional (Nico Schottelius) + * Type __cron: Simplyfied and syntax change (Nico Schottelius) 2.1.1: 2013-04-08 - * Core: Use dynamic dependency resolver to allow indirect self dependencies + * Core: Use dynamic dependency resolver to allow indirect self dependencies (Nico Schottelius) * Core: Remove umask call - protect /var/lib/cdist only (Arkaitz Jimenez) * Explorer os: Added Slackware support (Eivind Uggedal) * Type __git: Support mode and fix owner/group settings (contradict) @@ -224,90 +347,90 @@ Changelog * Type __user: Add support for creating user home (Arkaitz Jimenez) 2.1.0: 2012-12-09 - * Core: Ensure global explorers are executable + * Core: Ensure global explorers are executable (Nico Schottelius) * Core: Ensure type explorers are executable (Steven Armstrong) - * New Type: __git + * New Type: __git (Nico Schottelius) * New Type: __ssh_authorized_keys (Steven Armstrong) * New Type: __user_groups (Steven Armstrong) - * Type __rvm_gemset: Change parameter "default" to be boolean + * Type __rvm_gemset: Change parameter "default" to be boolean (Nico Schottelius) * Type __user: Remove --groups support (now provided by __user_groups) * Type __apt_ppa: Bugfix: Installeded ppa detection (Steven Armstrong) * Type __jail: Change optional parameter "started" to boolean "stopped" parameter, change optional parameter "devfs-enable" to boolean "devfs-disable" parameter and - change optional parameter "onboot" to boolean. - * Type __package_pip: Bugfix: Installeded the package, not pyro - * Remove Type __ssh_authorized_key: Superseeded by __ssh_authorized_keys + change optional parameter "onboot" to boolean. (Nico Schottelius) + * Type __package_pip: Bugfix: Installeded the package, not pyro (Nico Schottelius) + * Remove Type __ssh_authorized_key: Superseeded by __ssh_authorized_keys (Nico Schottelius) * Support for CDIST_PATH (Steven Armstrong) 2.1.0pre8: 2012-11-15 * Type cleanup: __apt_ppa, __apt_ppa_update_index, __file, __ssh_authorized_key, __timezone, all install types (Steven Armstrong) - * Types: Remove all parameter changing code - * Type __rvm_ruby: Change parameter "default" to be boolean - * Documentation: Web documentation clean up + * Types: Remove all parameter changing code (Nico Schottelius) + * Type __rvm_ruby: Change parameter "default" to be boolean (Nico Schottelius) + * Documentation: Web documentation clean up (Nico Schottelius) 2.1.0pre7: 2012-11-07 - * Core: All unit tests restored back to working - * Core: Print error message when missing the initial manifest + * Core: All unit tests restored back to working (Nico Schottelius) + * Core: Print error message when missing the initial manifest (Nico Schottelius) 2.1.0pre6: 2012-11-05 - * New Example: Turn remote calls into local calls (used for unittesting) - * Core: Export PYTHONPATH, it's also needed by emulator - * Bugfix Type __rvm_ruby: Add clean package dependencies - * Bugfix Type __rvm_gem: Run rvm as user, not as root - * Cleanup Type __rvm, __rvm_gemset: Use shortcut version - * Bugfix __rvm_gemset: Correctly check for gemsets + * New Example: Turn remote calls into local calls (used for unittesting) (Nico Schottelius) + * Core: Export PYTHONPATH, it's also needed by emulator (Nico Schottelius) + * Bugfix Type __rvm_ruby: Add clean package dependencies (Nico Schottelius) + * Bugfix Type __rvm_gem: Run rvm as user, not as root (Nico Schottelius) + * Cleanup Type __rvm, __rvm_gemset: Use shortcut version (Nico Schottelius) + * Bugfix __rvm_gemset: Correctly check for gemsets (Nico Schottelius) * Cleanup Type __postgres_database, __postgres_role: Reference each other - in documentation - * Cleanp Type __postgres_role: Use boolean parameters where appropriate - * Cleanp Type __postgres_role: Use shortcut version + in documentation (Nico Schottelius) + * Cleanp Type __postgres_role: Use boolean parameters where appropriate (Nico Schottelius) + * Cleanp Type __postgres_role: Use shortcut version (Nico Schottelius) 2.1.0pre5: 2012-11-01 - * Core: First round of tests updated to work with multiple configuration directories + * Core: First round of tests updated to work with multiple configuration directories (Nico Schottelius) 2.1.0pre4: 2012-10-31 - * Dist: PyPi: Moved cdist.py to script/cdist to avoid double import - * Core: Added support for multiple configuration directories (no documentation) + * Dist: PyPi: Moved cdist.py to script/cdist to avoid double import (Nico Schottelius) + * Core: Added support for multiple configuration directories (no documentation) (Nico Schottelius) 2.1.0pre3: 2012-10-30 - * Dist: PyPi: Types and explorer included as package data + * Dist: PyPi: Types and explorer included as package data (Nico Schottelius) 2.1.0pre2: 2012-10-26 - * Dist: PyPi: Add conf/ directory to distribution - * Dist: Initial support for archlinux packaging + * Dist: PyPi: Add conf/ directory to distribution (Nico Schottelius) + * Dist: Initial support for archlinux packaging (Nico Schottelius) 2.1.0pre1: 2012-10-26 - * Core: Removed obsolete variable __self - * Removed type __addifnosuchline (replaced by __line) - * Removed type __removeline (replaced by __line) - * Type __directory: Parameter --parents and --recursive are now boolean + * Core: Removed obsolete variable __self (Nico Schottelius) + * Removed type __addifnosuchline (replaced by __line) (Nico Schottelius) + * Removed type __removeline (replaced by __line) (Nico Schottelius) + * Type __directory: Parameter --parents and --recursive are now boolean (Nico Schottelius) * Type __package_apt, __package_luarocks, __package_opkg, __package_pacman, __package_pkg_freebsd, __package_pkg_openbsd, __package_rubygem, __package_yum, __process: - Parameter state accepts only "present" and "absent" - * Dist: Initial support for pypi packaging + Parameter state accepts only "present" and "absent" (Nico Schottelius) + * Dist: Initial support for pypi packaging (Nico Schottelius) 2.0.15: 2012-11-02 * Core: Make variable __object_name available in type explorers (Steven Armtrong) - * New Type: __qemu_img - * New Type: __line + * New Type: __qemu_img (Nico Schottelius) + * New Type: __line (Nico Schottelius) * New Type: __pf_apply (Jake Guffey) * New Type: __pf_ruleset (Jake Guffey) - * Bugfix Type: __rvm: Make type work if rvm is already installed + * Bugfix Type: __rvm: Make type work if rvm is already installed (Nico Schottelius) 2.0.14: 2012-09-07 * Bugfix Type: __jail: Use correct variable (Jake Guffey) * Change Type: __jail: Parameter jailbase now optional (Jake Guffey) * Bugfix Type: __user: Use passwd database on FreeBSD (Jake Guffey) - * Bugfix Type: __start_on_boot: Do not change parameters + * Bugfix Type: __start_on_boot: Do not change parameters (Nico Schottelius) * Feature __user: Added support for BSDs (Sébastien Gross) * Feature __group: Added support for FreeBSD (Jake Guffey) - * New Type: __package_zypper - * Feature Types: Initial Support for SuSE Linux + * New Type: __package_zypper (Nico Schottelius) + * Feature Types: Initial Support for SuSE Linux (Nico Schottelius) 2.0.13: 2012-06-05 * Bugfix __ssh_authorized_key: Ensure it sets proper group (contradict) - * Bugfix __addifnosuchline: Fixed quotes/interpolation bug ("a b" became "a b") + * Bugfix __addifnosuchline: Fixed quotes/interpolation bug ("a b" became "a b") (Nico Schottelius) * New Explorer: interfaces (Sébastien Gross) * Feature core: Support reading from stdin in types (Steven Armstrong) * Feature core: Support multiple parameters for types (Steven Armstrong) @@ -315,24 +438,24 @@ Changelog 2.0.12: 2012-05-29 * Core: Correctly raise error on Python < 3.2 (Steven Armtrong) - * Core: Add support for --remote-exec and --remote-copy parameters + * Core: Add support for --remote-exec and --remote-copy parameters (Nico Schottelius) * Documentation: Debian Squeeze hints (Sébastien Gross) 2.0.11: 2012-05-23 - * Fix insecure file/directory creation: Use umask 077 + * Fix insecure file/directory creation: Use umask 077 (Nico Schottelius) 2.0.10: 2012-05-18 * Cleanup __group: No getent gshadow in old Redhat, use groupmod -g (Matt Coddington) - * Bugfix __package_yum: Missing cat + * Bugfix __package_yum: Missing cat (Nico Schottelius) * Bugfix __start_on_boot: Correctly use sed and quotes (Steven Armstrong) * Feature __file: Support for --state exists (Steven Armstrong) - * Feature core: Make variable __manifest available to type manifests + * Feature core: Make variable __manifest available to type manifests (Nico Schottelius) * Feature core: Correct parent dependency handling (Steven Armstrong) * Bugfix several types: Fix sed for FreeBSD (Istvan Beregszaszi) * New Type: __jail (Jake Guffey) * Change Type: __rvm*: --state present/absent not installed/remvoed (Evax Software) - * Bugfix Type: __cron: Hide error output from crontab + * Bugfix Type: __cron: Hide error output from crontab (Nico Schottelius) * Various smaller bugfixes (Chris Lamb) 2.0.9: 2012-03-12 @@ -346,19 +469,19 @@ Changelog * Feature __start_on_boot: Support for OpenWRT (Giel van Schijndel) * Feature __start_on_boot: Support for Amazon Linux (Matt Coddington) * New Example: Use rsync to backup files (Matt Coddington) - * Feature core: Exit non-zero, if configuration failed + * Feature core: Exit non-zero, if configuration failed (Nico Schottelius) * Documentation: Describe how to do templating (Aurélien Bondis) 2.0.8: 2012-02-20 - * Bugfix core: Remove another nasty traceback when sending SIGINT (aka Ctrl-C) - * Cleanup: Better hint to source of error - * Cleanup: Do not output failing script, but path to script only + * Bugfix core: Remove another nasty traceback when sending SIGINT (aka Ctrl-C) (Nico Schottelius) + * Cleanup: Better hint to source of error (Nico Schottelius) + * Cleanup: Do not output failing script, but path to script only (Nico Schottelius) * Cleanup: Remove support for __debug variable in manifests (Type != Core - debugging) + debugging) (Nico Schottelius) * Cleanup: Change __package_* to support absent/present (default state - name now). The values removed/installed will be removed in cdist 2.1. + name now). The values removed/installed will be removed in cdist 2.1. (Nico Schottelius) * Cleanup: Change __process to support absent/present (default state - name now). The values running/stopped will be removed in cdist 2.1. + name now). The values running/stopped will be removed in cdist 2.1. (Nico Schottelius) * Feature Core: Support boolean parameters (Steven Armstrong) 2.0.7: 2012-02-13 @@ -367,9 +490,9 @@ Changelog * Bugfix __link: Properly handle existing links (Steven Armstrong) * Bugfix __key_value: More robust implementation (Steven Armstrong) * Bugfix __user: Fix for changing a user's group by name (Matt Coddington) - * New Type: __package_pip + * New Type: __package_pip (Nico Schottelius) * Bugfix/Cleanup: Correctly allow Object ID to start and end with /, but - not contain //. + not contain //. (Nico Schottelius) 2.0.6: 2012-01-28 * Bugfix __apt_ppa: @@ -388,8 +511,8 @@ Changelog 2.0.5: 2012-01-18 * Bugfix __key_value: Use correct delimiters (Steven Armstrong, Daniel Maher) - * Cleanup: Explicitly require Python >= 3.2 (do not fail implicitly) - * Documentation: (Re)write of the tutorial + * Cleanup: Explicitly require Python >= 3.2 (do not fail implicitly) (Nico Schottelius) + * Documentation: (Re)write of the tutorial (Nico Schottelius) * Feature: __addifnosuchline supports matching on regular expressions (Daniel Maher) * Feature: __directory, __file, __link: @@ -398,11 +521,11 @@ Changelog * New Type: __cdistmarker (Daniel Maher) 2.0.4: 2011-11-18 - * Bugfix core: Remove traceback when sending SIGINT (aka Ctrl-C) + * Bugfix core: Remove traceback when sending SIGINT (aka Ctrl-C) (Nico Schottelius) * Bugfix core: Accept parameters with - in the name (Steven Armstrong) - * Cleanup: __object_fq variable removed (never used) - * Cleanup: Environment variable __self DEPRECATED, use __object_name instead - * Cleanup: Environment variable __self scheduled for removal in cdist 2.1 + * Cleanup: __object_fq variable removed (never used) (Nico Schottelius) + * Cleanup: Environment variable __self DEPRECATED, use __object_name instead (Nico Schottelius) + * Cleanup: Environment variable __self scheduled for removal in cdist 2.1 (Nico Schottelius) * Documentation: Many examples for use of __remote_* (Steven Armstrong) * Feature: Automatically require all used objects (Steven Armstrong) * New Type: __cron (Steven Armstrong) @@ -410,28 +533,28 @@ Changelog 2.0.3: 2011-10-18 * Improved logging, added --verbose, by more quiet by default * Bugfix __user: Correct quoting (Steven Armstrong) - * Bugfix __addifnosuchline: Falsely exited - * Bugfix requirements: Restore original require="" behaviour - * Feature requirements: Check for broken object_ids and abort + * Bugfix __addifnosuchline: Falsely exited (Nico Schottelius) + * Bugfix requirements: Restore original require="" behaviour (Nico Schottelius) + * Feature requirements: Check for broken object_ids and abort (Nico Schottelius) * Massive refactoring and unittesting introduced (Steven Armstrong) 2.0.2: 2011-09-27 * Add support for detection of OpenWall Linux (Matthias Teege) - * Add support for __debug variable in manifests - * Bugfix core: Various issues with type emulator + * Add support for __debug variable in manifests (Nico Schottelius) + * Bugfix core: Various issues with type emulator (Nico Schottelius) 2.0.1: 2011-09-23 - * Bugfix core: Always print source of error in case of exec errors - * Bugfix core: Various smaller bugs in string concatenation - * Feature: Add marker "changed" to changed objects + * Bugfix core: Always print source of error in case of exec errors (Nico Schottelius) + * Bugfix core: Various smaller bugs in string concatenation (Nico Schottelius) + * Feature: Add marker "changed" to changed objects (Nico Schottelius) 2.0.0: 2011-09-16 * New Type: __package_rubygem (Chase Allen James) - * __self replaced by __object_fq - * Rewrote cdist in Python + * __self replaced by __object_fq (Nico Schottelius) + * Rewrote cdist in Python (Nico Schottelius) 1.7.1: 2011-07-26 - * Documentation: Add explorers to reference + * Documentation: Add explorers to reference (Nico Schottelius) * Documentation: Typo cleanup (Derek Brost) * Type __key_value: Bugfix (Steven Armstrong) * New Type: __postgres_role (Steven Armstrong) @@ -441,42 +564,42 @@ Changelog * Bugfix type __package_yum: Fix redhat support (Ramon Salvadó) * Improved type __package_yum: Add centos support (Ramon Salvadó) * New Type: __timezone (Ramon Salvadó) - * Renamed explorer: hardware_type to machine - * Core: Do not execute empty code fragments + * Renamed explorer: hardware_type to machine (Nico Schottelius) + * Core: Do not execute empty code fragments (Nico Schottelius) 1.6.2: 2011-04-19 - * Core: Introduce __cdist_tmp_base_dir - * Core: Cleanup and enhance cdist-type-template - * Core: cdist-mass-deploy: Report failed cdist-deploy-to instances + * Core: Introduce __cdist_tmp_base_dir (Nico Schottelius) + * Core: Cleanup and enhance cdist-type-template (Nico Schottelius) + * Core: cdist-mass-deploy: Report failed cdist-deploy-to instances (Nico Schottelius) * New Type: __ssh_authorized_key (Aurélien Bondis) 1.6.1: 2011-04-07 - * Improved logging: Show code responsible for abort - * Improved logging: Consistently prefix with current object or core - * Bugfix: Type __debconf_set_selections used wrong contens for selection - * Bugfix: Don't fail, if cache directory is not existing - * Bugfix: __user and __group exited non-zero if no change was necessary - * New Explorer: hardware_type + * Improved logging: Show code responsible for abort (Nico Schottelius) + * Improved logging: Consistently prefix with current object or core (Nico Schottelius) + * Bugfix: Type __debconf_set_selections used wrong contens for selection (Nico Schottelius) + * Bugfix: Don't fail, if cache directory is not existing (Nico Schottelius) + * Bugfix: __user and __group exited non-zero if no change was necessary (Nico Schottelius) + * New Explorer: hardware_type (Nico Schottelius) * New Type: __package_pkg_openbsd (Andi Brönnimann) * New Type: __autofs_map (Steven Armstrong) * New Type: __autofs_master (Steven Armstrong) 1.6.0: 2011-04-06 - * New Type: __package_yum - * New type: __debconf_set_selections - * New explorer: os_version - * Bugfix: Type __group failed in case of __group NAME syntax + * New Type: __package_yum (Nico Schottelius) + * New type: __debconf_set_selections (Nico Schottelius) + * New explorer: os_version (Nico Schottelius) + * Bugfix: Type __group failed in case of __group NAME syntax (Nico Schottelius) * Bugfix: __package* types: consistently name --state removed instead of - uninstalled or deinstalled - * Type __package: Added Fedora support - * Type __package_apt: Removed --preseed support - * Explorer os gained Fedora support - * Simplified types __user and __group - * New helper binary: cdist-mass-deploy + uninstalled or deinstalled (Nico Schottelius) + * Type __package: Added Fedora support (Nico Schottelius) + * Type __package_apt: Removed --preseed support (Nico Schottelius) + * Explorer os gained Fedora support (Nico Schottelius) + * Simplified types __user and __group (Nico Schottelius) + * New helper binary: cdist-mass-deploy (Nico Schottelius) 1.5.0: 2011-04-01 - * Add basic cache functionality - * New type: __process + * Add basic cache functionality (Nico Schottelius) + * New type: __process (Nico Schottelius) * Restructured execution: (Steven Armstrong) Orientate processing on objects, resolve dependencies and ensure correct execution order. @@ -486,77 +609,77 @@ Changelog 1.4.1: 2011-03-25 * New type: __key_value (Steven Armstrong) * New type: __apt_ppa (Steven Armstrong) - * Documentation: Manpage generation cleanup + * Documentation: Manpage generation cleanup (Nico Schottelius) * Documentation: Manpage fix for __apt_ppa 1.4.0: 2011-03-24 - * Add --recursive to __directory - * Move cdist generated stuff to .cdist of an object - * Allow objects to be redefined + * Add --recursive to __directory (Nico Schottelius) + * Move cdist generated stuff to .cdist of an object (Nico Schottelius) + * Allow objects to be redefined (Nico Schottelius) 1.3.2: 2011-03-21 - * Add --source to __motd - * Add --preseed to __package_apt - * Include HTML documentation of manpages and publish them + * Add --source to __motd (Nico Schottelius) + * Add --preseed to __package_apt (Nico Schottelius) + * Include HTML documentation of manpages and publish them (Nico Schottelius) 1.3.1: 2011-03-21 - * Document: cdist-type-build-emulation - * Document: cdist-type-emulator - * Document: cdist-remote-explorer-run - * Fix dependencies in cdist-code-run - * Fix dependencies in cdist-manifest-run-all - * Add --source to __issue and fix os check + * Document: cdist-type-build-emulation (Nico Schottelius) + * Document: cdist-type-emulator (Nico Schottelius) + * Document: cdist-remote-explorer-run (Nico Schottelius) + * Fix dependencies in cdist-code-run (Nico Schottelius) + * Fix dependencies in cdist-manifest-run-all (Nico Schottelius) + * Add --source to __issue and fix os check (Nico Schottelius) 1.3.0: 2011-03-20 - * Add support for local and remote code generation and execution - * Bugfix: Remove obsolete $@ call in cdist-remote-explorer-run - * Bugfix: Correct manpage for __removeline (broke manpage generation) + * Add support for local and remote code generation and execution (Nico Schottelius) + * Bugfix: Remove obsolete $@ call in cdist-remote-explorer-run (Nico Schottelius) + * Bugfix: Correct manpage for __removeline (broke manpage generation) (Nico Schottelius) 1.2.0: 2011-03-19 - * Added dependencies (see cdist-type(7)) + * Added dependencies (see cdist-type(7)) (Nico Schottelius) * New type: __removeline (Daniel Roth) * New type: __group (Steven Armstrong) * New type: __user (Steven Armstrong) - * Documentation: cdist-run-remote - * Documentation: cdist-code-run-all - * Documentation: cdist-object-gencode - * Documentation: cdist-explorer-run-global - * Documentation: cdist-manifest-run-init - * Documentation: cdist-manifest-run-all - * Documentation: cdist-object-gencode-all - * Documentation: cdist-manifest-run + * Documentation: cdist-run-remote (Nico Schottelius) + * Documentation: cdist-code-run-all (Nico Schottelius) + * Documentation: cdist-object-gencode (Nico Schottelius) + * Documentation: cdist-explorer-run-global (Nico Schottelius) + * Documentation: cdist-manifest-run-init (Nico Schottelius) + * Documentation: cdist-manifest-run-all (Nico Schottelius) + * Documentation: cdist-object-gencode-all (Nico Schottelius) + * Documentation: cdist-manifest-run (Nico Schottelius) 1.1.0: 2011-03-16 - * Replace type __file with __file, __directory, __link - * Documentation: cdist-env - * Documentation: cdist-config - * Documentation: cdist-dir - * Documentation: cdist-quickstart + * Replace type __file with __file, __directory, __link (Nico Schottelius) + * Documentation: cdist-env (Nico Schottelius) + * Documentation: cdist-config (Nico Schottelius) + * Documentation: cdist-dir (Nico Schottelius) + * Documentation: cdist-quickstart (Nico Schottelius) 1.0.4: 2011-03-15 - * New type: __motd + * New type: __motd (Nico Schottelius) * New type: __addifnosuchline (Daniel Roth) - * New type: __user - * Document type: __issue - * Document type: __package - * Document type: __package_pacman - * Document type: __package_apt - * New parameter for __file: --owner and --group + * New type: __user (Nico Schottelius) + * Document type: __issue (Nico Schottelius) + * Document type: __package (Nico Schottelius) + * Document type: __package_pacman (Nico Schottelius) + * Document type: __package_apt (Nico Schottelius) + * New parameter for __file: --owner and --group (Nico Schottelius) 1.0.3: 2011-03-11 - * Update regexp used for sane characters - * Allow types without parameters - * Allow type to be singleton - * Type __file learned --type symlink + * Update regexp used for sane characters (Nico Schottelius) + * Allow types without parameters (Nico Schottelius) + * Allow type to be singleton (Nico Schottelius) + * Type __file learned --type symlink (Nico Schottelius) 1.0.2: 2011-03-09 - * Add manpages: cdist-type, cdist-type__file, cdist-reference, cdist-explorer - * Make doc/man/ usable as MANPATH entry + * Add manpages: cdist-type, cdist-type__file, cdist-reference, cdist-explorer (Nico Schottelius) + * Make doc/man/ usable as MANPATH entry (Nico Schottelius) 1.0.1: 2011-03-08 - * Added cdist-type-template including manpage - * Fix manpage building - * Add new manpages: cdist-stages, cdist-bin-transfer + * Added cdist-type-template including manpage (Nico Schottelius) + * Fix manpage building (Nico Schottelius) + * Add new manpages: cdist-stages, cdist-bin-transfer (Nico Schottelius) 1.0.0: 2011-03-07 - * Initial release + * Initial release (Nico Schottelius) diff --git a/docs/dev/logs/2014-05-06.object-marker b/docs/dev/logs/2014-05-06.object-marker new file mode 100644 index 00000000..4878a2f5 --- /dev/null +++ b/docs/dev/logs/2014-05-06.object-marker @@ -0,0 +1,14 @@ +Change object marker from .cdist to .cdist-TEMPNAME to allow using +object ids that contain / are .cdist. + +Changes required: + + cdist/emulator.py: + needs to know suffix/name + tests: + allow object id named /.cdist + tests: + many + cdist/config.py: + have suffix + diff --git a/docs/dev/logs/2014-09-10.preos-keys b/docs/dev/logs/2014-09-10.preos-keys new file mode 100644 index 00000000..53d3721a --- /dev/null +++ b/docs/dev/logs/2014-09-10.preos-keys @@ -0,0 +1,18 @@ + +cdist preos keyramfs --keyfile --keyfile + +[17:51] freiheit:vcs% mkdir preos-keys +[17:51] freiheit:vcs% mkdir -p preos-keys/root/.ssh +[17:56] freiheit:vcs% + +chown root:root -R preos-keys/ +chmod 0600 preos-keys/root/.ssh/authorized_keys + +chmod 0700 preos-keys/root/ +chmod 0700 preos-keys/root/.ssh/ + +[18:20:17] freiheit:/home/users/nico/.ungleich/ungleich/vcs/preos-keys# find . | cpio -H newc -o | gzip -9 > ../initramfs.cpio.gz +4 blocks +[18:21:08] freiheit:/home/users/nico/.ungleich/ungleich/vcs/preos-keys# + + diff --git a/docs/dev/logs/2014-11-11.discussion b/docs/dev/logs/2014-11-11.discussion new file mode 100644 index 00000000..a04d2823 --- /dev/null +++ b/docs/dev/logs/2014-11-11.discussion @@ -0,0 +1,104 @@ +- logging/cache destination + local: + ~/.cdist/log/by-host/$__target/host/config/YYYY/MM/DD/hhmmss/ + ~/.cdist/log/by-session/YYYY/MM/DD/hhmmss/$__target_host/ + config/ + install/ + export/ + remote: + /var/lib/cdist/YYYY-MM-DD-hhmmss-$sourcehost.$pid + + rm old directories on remote side + +- support for tags + - for partial configuration + - supports also install + - on object definition, define + - a) don't care (i.e. no tags) + - b) require tag (only if this tag is setup) + - c) require not tag (only if this tag is *not* setup) + - d) what if both given (conflicting) + - names for parameters: + - cdist config / cdist type + --if-tag / --not-if-tag / --require-tag + --not-if-tag + +- logging + - command line + - stdin of cdist + - stdout/stderr/stdin of types + - new: stdout/stderr + - initial manifest + - if coming from stdin + +- logging configurable + - to be discussed + +- sudo remote + - cp to tmp & mv + - umask issue? + +- install + - via tagged types + - + +- export + - one /export script per type + - exports of type running after object's code is done + - global export should also exist after everything + - PR & merge + - change DONE status to CODE_DONE + - introduce EXPORT_DONE + + +- preos + - merge with debian support only + - we are open to support --os-type later + +- stackable remotes + - change API for remote_exec and remote_copy + - new minor version + - PR & merge + +- locking + - optional + - remote lock + - based on $(ls /var/lib/cdist/) > 0 + +- ideas for parallelisation + - run explorer in parallel + - type + - object + - objects without dependencies can be run in parallel + +- connection test + - just implement + +- multi user environment + - not really needed [at the moment] + - can be implemented by + - git branches + - setting the output dir + +- python2 support with __future__ + - steven votes against it + - nico does not care too much to object + + +- pull based + - sshd / stdin + stdout + - use Use ProxyCommand with stdin/stdout + - http://www.nico.schottelius.org/blog/openssh-6.2-add-callback-functionality-using-dynamic-remote-port-forwarding/ + + - cdist grant-pull-access + - generate user + - ssh pubkeypair + - call wraper script on targethost + - it is shell! + - ssh cdistuser@controlhost + +- config replay/redo/undo + - not now + + +- have a new discussion about handling uris diff --git a/docs/dev/logs/2015-02-22.allow_dot_cdist b/docs/dev/logs/2015-02-22.allow_dot_cdist new file mode 100644 index 00000000..58a1b041 --- /dev/null +++ b/docs/dev/logs/2015-02-22.allow_dot_cdist @@ -0,0 +1,29 @@ +- locate code that references .cdist + - cdist_object.py +- need to change code that handles objects? + - setup object marker + exec/local.py + - cdist/emulator.py + - need to know the marker name + - shell.py + - test/manifest/__init__.py + - core/code.py: + - core/manifest.py: + - core/manifest.py: + - list_object_names() needs to know the marker -- used BY: + - list_objects + - cdist/test/cdist_object/__init__.py + - cdist/config.py + - cdist/test/cdist_object/__init__.py + + - list_object_names + - needs to have object_marker + +- or modify object code to load name +- setup a per-run random name + - local.py +- use the per-run random name +- create test + + def __init__(self, cdist_type, base_path, object_marker=".cdist", object_id=''): + diff --git a/docs/dev/logs/dependency-tree-with-fruits b/docs/dev/logs/dependency-tree-with-fruits new file mode 100644 index 00000000..322dc6e3 --- /dev/null +++ b/docs/dev/logs/dependency-tree-with-fruits @@ -0,0 +1,29 @@ +1. Manifests need type explorers to be run before + Only this way the manifest can use the values + +2. Type explorers can depend on the (successful) execution of other objects + A type explorer may lookup values (ownership, size, processes, etc.) + that are depending on the code of other objects. + +3. The 'require="a" b' dependency specifies only that execution of b needs to wait until a is finished + Other requirements given at another position may not be + executed before b, as cdist interprets require="a" as + "a is everything that is needed to realise b" + +4. The 'require' state is thus *not* suitable to trigger reloads + A type b, which uses the require="" statement to wait for all + require="" dependencies, may be executed in an incomplete + status. + +5. Depending on multiple dependencies defined at different locations requires all objects to be present + Because otherwise the dependent object cannot be sure that the + list of objects it waits for is complete. + +6. If a statement requires all objects to be present, all manifests must have run already. + If all manifests have run already, also all type explorers have run already (#1). + If all type explorers have run already, some objects may have been finished completly already (#2). + +7. Because of #4 and #6, we need to introduce another dependency that allows reloading after + +8. Because the object could be finished already due to a 'require' dependency, we need another script + Maybe "gen-post-run-local", "gen-post-run-remote" diff --git a/docs/dev/todo/TAKEME b/docs/dev/todo/TAKEME index 87fc91c5..4d097091 100644 --- a/docs/dev/todo/TAKEME +++ b/docs/dev/todo/TAKEME @@ -5,10 +5,6 @@ Feel free to pick one! CORE ---- -- support default parameter -- document and add paremeters for remote-copy and remote-exec! - - remove hack, make a feature of it - - remove var=foo calls on remote side. Use -o SendEnv (yeah, see ssh_config(5)) TESTS @@ -23,9 +19,6 @@ TESTS USER INTERFACE -------------- -- How to cleanly implement "restart service if config file changed" - -> document - - Cache - add example how to use - export variable $__cache @@ -45,7 +38,6 @@ TYPES - Add testing framework (proposed by Evax Software) - __user add option to include --create-home -- Merge __addifnosuchline and __removeline into __line + --state present|absent - __cron: Support --file to be used instead of user cron (probably direct support of /etc/cron.d) diff --git a/docs/man/Makefile b/docs/man/Makefile new file mode 100644 index 00000000..721acaf6 --- /dev/null +++ b/docs/man/Makefile @@ -0,0 +1,230 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) + $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don\'t have Sphinx installed, grab it from http://sphinx-doc.org/) +endif + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " applehelp to make an Apple Help Book" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " epub3 to make an epub3" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + @echo " coverage to run coverage check of the documentation (if enabled)" + @echo " dummy to check syntax errors of document sources" + +.PHONY: clean +clean: + rm -rf $(BUILDDIR)/* + +.PHONY: html +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +.PHONY: dirhtml +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +.PHONY: singlehtml +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +.PHONY: pickle +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +.PHONY: json +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +.PHONY: htmlhelp +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +.PHONY: qthelp +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/cdist-docs.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/cdist-docs.qhc" + +.PHONY: applehelp +applehelp: + $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp + @echo + @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." + @echo "N.B. You won't be able to view it unless you put it in" \ + "~/Library/Documentation/Help or install it in your application" \ + "bundle." + +.PHONY: devhelp +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/cdist-docs" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/cdist-docs" + @echo "# devhelp" + +.PHONY: epub +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +.PHONY: epub3 +epub3: + $(SPHINXBUILD) -b epub3 $(ALLSPHINXOPTS) $(BUILDDIR)/epub3 + @echo + @echo "Build finished. The epub3 file is in $(BUILDDIR)/epub3." + +.PHONY: latex +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +.PHONY: latexpdf +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +.PHONY: latexpdfja +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +.PHONY: text +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +.PHONY: man +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +.PHONY: texinfo +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +.PHONY: info +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +.PHONY: gettext +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +.PHONY: changes +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +.PHONY: linkcheck +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +.PHONY: doctest +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +.PHONY: coverage +coverage: + $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage + @echo "Testing of coverage in the sources finished, look at the " \ + "results in $(BUILDDIR)/coverage/python.txt." + +.PHONY: xml +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +.PHONY: pseudoxml +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." + +.PHONY: dummy +dummy: + $(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy + @echo + @echo "Build finished. Dummy builder generates no files." diff --git a/docs/man/cdist-reference.text.sh b/docs/man/cdist-reference.rst.sh similarity index 80% rename from docs/man/cdist-reference.text.sh rename to docs/man/cdist-reference.rst.sh index c6e5053f..0dd7c634 100755 --- a/docs/man/cdist-reference.text.sh +++ b/docs/man/cdist-reference.rst.sh @@ -37,11 +37,9 @@ exec > "$dest" cat << eof cdist-reference(7) ================== -Nico Schottelius +Variable, path and type reference for cdist -NAME ----- -cdist-reference - Variable, path and type reference for cdist +Nico Schottelius EXPLORERS @@ -51,7 +49,7 @@ The following global explorers are available: eof ( cd ../../cdist/conf/explorer - for explorer in *; do + for explorer in $(ls * | LC_ALL=C sort); do echo "- $explorer" done ) @@ -60,101 +58,101 @@ cat << eof PATHS ----- -\$HOME/.cdist:: +\$HOME/.cdist The standard cdist configuration directory relative to your home directory This is usually the place you want to store your site specific configuration -cdist/conf/:: +cdist/conf/ The distribution configuration directory This contains types and explorers to be used -confdir:: +confdir Cdist will use all available configuration directories and create a temporary confdir containing links to the real configuration directories. This way it is possible to merge configuration directories. By default it consists of everything in \$HOME/.cdist and cdist/conf/. For more details see cdist(1) -confdir/files/:: +confdir/files/ Cdist does not care about this directory besides providing access to it. It is thought to be a general file storage area. -confdir/manifest/init:: +confdir/manifest/init This is the central entry point. It is an executable (+x bit set) shell script that can use values from the explorers to decide which configuration to create for the specified target host. Its intent is to used to define mapping from configurations to hosts. -confdir/manifest/*:: +confdir/manifest/* All other files in this directory are not directly used by cdist, but you - can seperate configuration mappings, if you have a lot of code in the + can separate configuration mappings, if you have a lot of code in the conf/manifest/init file. This may also be helpful to have different admins maintain different groups of hosts. -confdir/explorer/:: +confdir/explorer/ Contains explorers to be run on the target hosts, see cdist-explorer(7). -confdir/type/:: +confdir/type/ Contains all available types, which are used to provide some kind of functionality. See cdist-type(7). -confdir/type//:: +confdir/type// Home of the type . This directory is referenced by the variable __type (see below). -confdir/type//man.text:: - Manpage in Asciidoc format (required for inclusion into upstream) +confdir/type//man.rst + Manpage in reStructuredText format (required for inclusion into upstream) -confdir/type//manifest:: +confdir/type//manifest Used to generate additional objects from a type. -confdir/type//gencode-local:: +confdir/type//gencode-local Used to generate code to be executed on the source host -confdir/type//gencode-remote:: +confdir/type//gencode-remote Used to generate code to be executed on the target host -confdir/type//parameter/required:: - Parameters required by type, \n seperated list. +confdir/type//parameter/required + Parameters required by type, \n separated list. -confdir/type//parameter/optional:: - Parameters optionally accepted by type, \n seperated list. +confdir/type//parameter/optional + Parameters optionally accepted by type, \n separated list. -confdir/type//parameter/default/*:: +confdir/type//parameter/default/* Default values for optional parameters. Assuming an optional parameter name of 'foo', it's default value would be read from the file confdir/type//parameter/default/foo. -confdir/type//parameter/boolean:: - Boolean parameters accepted by type, \n seperated list. +confdir/type//parameter/boolean + Boolean parameters accepted by type, \n separated list. -confdir/type//explorer:: +confdir/type//explorer Location of the type specific explorers. This directory is referenced by the variable __type_explorer (see below). See cdist-explorer(7). -confdir/type//files:: +confdir/type//files This directory is reserved for user data and will not be used by cdist at any time. It can be used for storing supplementary files (like scripts to act as a template or configuration files). -out/:: +out/ This directory contains output of cdist and is usually located in a temporary directory and thus will be removed after the run. This directory is referenced by the variable __global (see below). -out/explorer:: +out/explorer Output of general explorers. -out/object:: +out/object Objects created for the host. -out/object/:: +out/object/ Contains all object specific information. This directory is referenced by the variable __object (see below). -out/object//explorers:: +out/object//explorers Output of type specific explorers, per object. TYPES @@ -163,14 +161,15 @@ The following types are available: eof -for type in man7/cdist-type__*.text; do +for type in $(ls man7/cdist-type__*.rst | LC_ALL=C sort); do no_dir="${type#man7/}"; no_type="${no_dir#cdist-type}"; - name="${no_type%.text}"; + name="${no_type%.rst}"; name_no_underline="$(echo $name | sed 's/^__/\\__/g')" - man="${no_dir%.text}(7)" + manref="${no_dir%.rst}" + man="${manref}(7)" - echo "- $name_no_underline" "($man)" + echo "- $name_no_underline" "(\`${man} <${manref}.html>\`_)" done cat << eof @@ -181,14 +180,14 @@ OBJECTS For object to object communication and tests, the following paths are usable within a object directory: -files:: +files This directory is reserved for user data and will not be used by cdist at any time. It can be used freely by the type (for instance to store template results). -changed:: +changed This empty file exists in an object directory, if the object has - code to be excuted (either remote or local) -stdin:: + code to be executed (either remote or local) +stdin This file exists and contains data, if data was provided on stdin when the type was called. @@ -197,44 +196,44 @@ ENVIRONMENT VARIABLES (FOR READING) ----------------------------------- The following environment variables are exported by cdist: -__explorer:: +__explorer Directory that contains all global explorers. Available for: initial manifest, explorer, type explorer, shell -__files:: +__files Directory that contains content from the "files" subdirectories from the configuration directories. Available for: initial manifest, type manifest, type gencode, shell -__manifest:: +__manifest Directory that contains the initial manifest. Available for: initial manifest, type manifest, shell -__global:: +__global Directory that contains generic output like explorer. Available for: initial manifest, type manifest, type gencode, shell -__messages_in:: - File to read messages from +__messages_in + File to read messages from. Available for: initial manifest, type manifest, type gencode -__messages_out:: - File to write messages +__messages_out + File to write messages. Available for: initial manifest, type manifest, type gencode -__object:: +__object Directory that contains the current object. Available for: type manifest, type explorer, type gencode and code scripts -__object_id:: +__object_id The type unique object id. 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. -__object_name:: +__object_name The full qualified name of the current object. Available for: type manifest, type explorer, type gencode -__target_host:: +__target_host The host we are deploying to. Available for: explorer, initial manifest, type explorer, type manifest, type gencode, shell -__type:: +__type Path to the current type. Available for: type manifest, type gencode -__type_explorer:: +__type_explorer Directory that contains the type explorers. Available for: type explorer @@ -242,24 +241,30 @@ ENVIRONMENT VARIABLES (FOR WRITING) ----------------------------------- The following environment variables influence the behaviour of cdist: -require:: +require Setup dependencies between objects (see cdist-manifest(7)) -CDIST_LOCAL_SHELL:: +CDIST_LOCAL_SHELL Use this shell locally instead of /bin/sh to execute scripts -CDIST_REMOTE_SHELL:: +CDIST_REMOTE_SHELL Use this shell remotely instead of /bin/sh to execute scripts -CDIST_OVERRIDE:: +CDIST_OVERRIDE Allow overwriting type parameters (see cdist-manifest(7)) -CDIST_ORDER_DEPENDENCY:: +CDIST_ORDER_DEPENDENCY Create dependencies based on the execution order (see cdist-manifest(7)) +CDIST_REMOTE_EXEC + Use this command for remote execution (should behave like ssh) + +CDIST_REMOTE_COPY + Use this command for remote copy (should behave like scp) + SEE ALSO -------- -- cdist(1) +- \`cdist(1) <../man1/cdist.html>\`_ COPYING diff --git a/docs/man/conf.py b/docs/man/conf.py new file mode 100644 index 00000000..7df4ed25 --- /dev/null +++ b/docs/man/conf.py @@ -0,0 +1,305 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# cdist-docs documentation build configuration file, created by +# sphinx-quickstart on Fri May 6 21:45:28 2016. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +#sys.path.insert(0, os.path.abspath('.')) + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +source_suffix = ['.rst'] + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = 'cdist' +#copyright = '2016, Darko Poljak' +#author = 'Darko Poljak' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +import cdist.version +version = cdist.version.VERSION +# The full version, including alpha/beta/rc tags. +release = version + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This patterns also effect to html_static_path and html_extra_path +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +#keep_warnings = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +import sphinx_rtd_theme +html_theme = 'sphinx_rtd_theme' +html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. +# " v documentation" by default. +#html_title = 'cdist-docs v0.0.1' + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (relative to this directory) to use as a favicon of +# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +#html_extra_path = [] + +# If not None, a 'Last updated on:' timestamp is inserted at every page +# bottom, using the given strftime format. +# The empty string is equivalent to '%b %d, %Y'. +#html_last_updated_fmt = None + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None +#html_file_suffix = "" + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja' +# 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr', 'zh' +#html_search_language = 'en' + +# A dictionary with options for the search language support, empty by default. +# 'ja' uses this config value. +# 'zh' user can custom change `jieba` dictionary path. +#html_search_options = {'type': 'default'} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +#html_search_scorer = 'scorer.js' + +# Output file base name for HTML help builder. +htmlhelp_basename = 'cdistdoc' + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', + +# Latex figure (float) alignment +#'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'cdist.tex', 'cdist Documentation', + 'Darko Poljak', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +mandir = os.path.dirname(os.path.realpath(__file__)) +man_pages = [] +for mansubdir in ('man1', 'man7'): + for root, dirs, files in os.walk(os.path.join(mandir, mansubdir)): + for fname in files: + froot, fext = os.path.splitext(fname) + if fext == '.rst': + man_page = (os.path.join(mansubdir, froot), froot, '', + [], mansubdir[-1]) + man_pages.append(man_page) + +#man_pages = [ +# ('cdist-type', 'cdist-type', 'cdist-type documentation', +# [author], 1), +# ('man7/cdist-type__file', 'cdist-type__file', +# '', [], 1), +# ('cdist-type__directory', 'cdist-type__directory', +# 'cdist-type__directory documentation', [author], 1), +#] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'cdist', 'cdist Documentation', + '', 'cdist', 'Configuration management system.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +#texinfo_no_detailmenu = False diff --git a/docs/man/index.rst b/docs/man/index.rst new file mode 100644 index 00000000..f0638779 --- /dev/null +++ b/docs/man/index.rst @@ -0,0 +1,12 @@ +Welcome to cdist documentation +============================== + +Contents: + +.. toctree:: + :titlesonly: + :glob: + :numbered: + + man1/* + man7/* diff --git a/docs/man/man1/cdist.text b/docs/man/man1/cdist.rst similarity index 51% rename from docs/man/man1/cdist.text rename to docs/man/man1/cdist.rst index e8c12991..21edee11 100644 --- a/docs/man/man1/cdist.text +++ b/docs/man/man1/cdist.rst @@ -1,22 +1,22 @@ cdist(1) ======== +Usable Configuration Management + Nico Schottelius -NAME ----- -cdist - Usable Configuration Management - - SYNOPSIS -------- -cdist [-h] [-d] [-v] [-V] {banner,config,shell} ... -cdist banner [-h] [-d] [-v] +:: -cdist config [-h] [-d] [-V] [-c CONF_DIR] [-i MANIFEST] [-p] [-s] host [host ...] + cdist [-h] [-d] [-v] [-V] {banner,config,shell} ... -cdist shell [-h] [-d] [-v] [-s SHELL] + cdist banner [-h] [-d] [-v] + + cdist config [-h] [-d] [-V] [-c CONF_DIR] [-f HOSTFILE] [-i MANIFEST] [-p] [-s] [host [host ...]] + + cdist shell [-h] [-d] [-v] [-s SHELL] DESCRIPTION @@ -26,18 +26,22 @@ cdist supports different subcommands as explained below. GENERAL ------- -All commands except the following options: +All commands accept the following options: + +.. option:: -d, --debug --d, --debug:: Set log level to debug --h, --help:: +.. option:: -h, --help + Show the help screen --v, --verbose: +.. option:: -v, --verbose + Set log level to info, be more verbose --V, --version:: +.. option:: -V, --version + Show version and exit @@ -51,10 +55,12 @@ CONFIG ------ Configure one or more hosts --h, --help:: +.. option:: -h, --help + Show the help screen --c CONF_DIR, --conf-dir CONF_DIR:: +.. option:: -c CONF_DIR, --conf-dir CONF_DIR + Add a configuration directory. Can be specified multiple times. If configuration directories contain conflicting types, explorers or manifests, then the last one found is used. Additionally this can also @@ -63,19 +69,31 @@ Configure one or more hosts --conf-dir argument have higher precedence over those set through the environment variable. --i MANIFEST, --initial-manifest MANIFEST:: +.. option:: -f HOSTFILE, --file HOSTFILE + + Read additional hosts to operate on from specified file + or from stdin if '-' (each host on separate line). + If no host or host file is specified then, by default, + read hosts from stdin. + +.. option:: -i MANIFEST, --initial-manifest MANIFEST + Path to a cdist manifest or - to read from stdin --p, --parallel:: +.. option:: -p, --parallel + Operate on multiple hosts in parallel --s, --sequential:: +.. option:: -s, --sequential + Operate on multiple hosts sequentially ---remote-copy REMOTE_COPY: +.. option:: --remote-copy REMOTE_COPY + Command to use for remote copy (should behave like scp) ---remote-exec REMOTE_EXEC: +.. option:: --remote-exec REMOTE_EXEC + Command to use for remote execution (should behave like ssh) SHELL @@ -85,74 +103,81 @@ to the types as commands. It can be thought as an "interactive manifest" environment. See below for example usage. Its primary use is for debugging type parameters. --s/--shell:: +.. option:: -s/--shell + Select shell to use, defaults to current shell EXAMPLES -------- --------------------------------------------------------------------------------- -# Configure ikq05.ethz.ch with debug enabled -% cdist config -d ikq05.ethz.ch +.. code-block:: sh -# Configure hosts in parallel and use a different configuration directory -% cdist config -c ~/p/cdist-nutzung \ - -p ikq02.ethz.ch ikq03.ethz.ch ikq04.ethz.ch + # Configure ikq05.ethz.ch with debug enabled + % cdist config -d ikq05.ethz.ch -# Use custom remote exec / copy commands -% cdist config --remote-exec /path/to/my/remote/exec \ - --remote-copy /path/to/my/remote/copy \ - -p ikq02.ethz.ch ikq03.ethz.ch ikq04.ethz.ch + # Configure hosts in parallel and use a different configuration directory + % cdist config -c ~/p/cdist-nutzung \ + -p ikq02.ethz.ch ikq03.ethz.ch ikq04.ethz.ch -# Display banner -cdist banner + # Use custom remote exec / copy commands + % cdist config --remote-exec /path/to/my/remote/exec \ + --remote-copy /path/to/my/remote/copy \ + -p ikq02.ethz.ch ikq03.ethz.ch ikq04.ethz.ch -# Show help -% cdist --help + # Configure hosts read from file loadbalancers + % cdist config -f loadbalancers -# Show Version -% cdist --version + # Display banner + cdist banner -# Enter a shell that has access to emulated types -% cdist shell -% __git -usage: __git --source SOURCE [--state STATE] [--branch BRANCH] - [--group GROUP] [--owner OWNER] [--mode MODE] object_id + # Show help + % cdist --help + # Show Version + % cdist --version --------------------------------------------------------------------------------- + # Enter a shell that has access to emulated types + % cdist shell + % __git + usage: __git --source SOURCE [--state STATE] [--branch BRANCH] + [--group GROUP] [--owner OWNER] [--mode MODE] object_id ENVIRONMENT ----------- -TMPDIR, TEMP, TMP:: +TMPDIR, TEMP, TMP Setup the base directory for the temporary directory. See http://docs.python.org/py3k/library/tempfile.html for more information. This is rather useful, if the standard directory used does not allow executables. -CDIST_LOCAL_SHELL:: +CDIST_LOCAL_SHELL Selects shell for local script execution, defaults to /bin/sh -CDIST_REMOTE_SHELL:: +CDIST_REMOTE_SHELL Selects shell for remote scirpt execution, defaults to /bin/sh +CDIST_REMOTE_EXEC + Use this command for remote execution (should behave like ssh) + +CDIST_REMOTE_COPY + Use this command for remote copy (should behave like scp) EXIT STATUS ----------- The following exit values shall be returned: -0:: +0 Successful completion -1:: +1 One or more host configurations failed SEE ALSO -------- -- cdist(7) -- cdist-reference(7) +- `cdist-type(7) <../man7/cdist-type.html>`_ +- `cdist-reference(7) <../man7/cdist-reference.html>`_ COPYING diff --git a/docs/man/man7/cdist-best-practice.rst b/docs/man/man7/cdist-best-practice.rst new file mode 100644 index 00000000..13d65cce --- /dev/null +++ b/docs/man/man7/cdist-best-practice.rst @@ -0,0 +1,238 @@ +cdist-best-practice(7) +====================== +Practices used in real environments + +Nico Schottelius + + +PASSWORDLESS CONNECTIONS +------------------------ +It is recommended to run cdist with public key authentication. +This requires a private/public key pair and the entry +"PermitRootLogin without-password" in the sshd server. +See sshd_config(5) and ssh-keygen(1). + + +SPEEDING UP SSH CONNECTIONS +--------------------------- +When connecting to a new host, the initial delay with ssh connections +is pretty big. You can work around this by +"sharing of multiple sessions over a single network connection" +(quote from ssh_config(5)). The following code is suitable for +inclusion into your ~/.ssh/config:: + + Host * + ControlPath ~/.ssh/master-%l-%r@%h:%p + ControlMaster auto + ControlPersist 10 + + +SPEEDING UP SHELL EXECUTION +---------------------------- +On the source host, ensure that /bin/sh is *not* bash: bash is quite slow for +script execution. Instead, you could use dash after installing it:: + + ln -sf /bin/dash /bin/sh + + +MULTI MASTER OR ENVIRONMENT SETUPS +---------------------------------- +If you plan to distribute cdist among servers or use different +environments, you can do so easily with the included version +control git. For instance if you plan to use the typical three +environments production, integration and development, you can +realise this with git branches:: + + # Go to cdist checkout + cd /path/to/cdist + + # Create branches + git branch development + git branch integration + git branch production + + # Make use of a branch, for instance production + git checkout production + +Similar if you want to have cdist checked out at multiple machines, +you can clone it multiple times:: + + machine-a % git clone git://your-git-server/cdist + machine-b % git clone git://your-git-server/cdist + + +SEPERATING WORK BY GROUPS +------------------------- +If you are working with different groups on one cdist-configuration, +you can delegate to other manifests and have the groups edit only +their manifests. You can use the following snippet in +**conf/manifests/init**:: + + # Include other groups + sh -e "$__manifest/systems" + + sh -e "$__manifest/cbrg" + + +MAINTAINING MULTIPLE CONFIGURATIONS +----------------------------------- +When you need to manage multiple sites with cdist, like company_a, company_b +and private for instance, you can easily use git for this purpose. +Including a possible common base that is reused across the different sites:: + + # create branches + git branch company_a company_b common private + + # make stuff for company a + git checkout company_a + # work, commit, etc. + + # make stuff for company b + git checkout company_b + # work, commit, etc. + + # make stuff relevant for all sites + git checkout common + # work, commit, etc. + + # change to private and include latest common stuff + git checkout private + git merge common + + +The following **.git/config** is taken from a a real world scenario:: + + # Track upstream, merge from time to time + [remote "upstream"] + url = git://git.schottelius.org/cdist + fetch = +refs/heads/*:refs/remotes/upstream/* + + # Same as upstream, but works when being offline + [remote "local"] + fetch = +refs/heads/*:refs/remotes/local/* + url = /home/users/nico/p/cdist + + # Remote containing various ETH internal branches + [remote "eth"] + url = sans.ethz.ch:/home/services/sans/git/cdist-eth + fetch = +refs/heads/*:refs/remotes/eth/* + + # Public remote that contains my private changes to cdist upstream + [remote "nico"] + url = git.schottelius.org:/home/services/git/cdist-nico + fetch = +refs/heads/*:refs/remotes/nico/* + + # The "nico" branch will be synced with the remote nico, branch master + [branch "nico"] + remote = nico + merge = refs/heads/master + + # ETH stable contains rock solid configurations used in various places + [branch "eth-stable"] + remote = eth + merge = refs/heads/stable + +Have a look at git-remote(1) to adjust the remote configuration, which allows + + +MULTIPLE DEVELOPERS WITH DIFFERENT TRUST +---------------------------------------- +If you are working in an environment that requires different people to +work on the same configuration, but having different privileges, you can +implement this scenario with a gateway host and sudo: + +- Create a dedicated user (for instance **cdist**) +- Setup the ssh-pubkey for this user that has the right to configure all hosts +- Create a wrapper to update the cdist configuration in ~cdist/cdist +- Allow every developer to execute this script via sudo as the user cdist +- Allow run of cdist as user cdist on specific hosts on a per user/group base + + - f.i. nico ALL=(ALL) NOPASSWD: /home/cdist/bin/cdist config hostabc + +For more details consult sudoers(5) + + +TEMPLATING +---------- +* create directory files/ in your type (convention) +* create the template as an executable file like files/basic.conf.sh, it will output text using shell variables for the values + +.. code-block:: sh + + #!/bin/sh + # in the template, use cat << eof (here document) to output the text + # and use standard shell variables in the template + # output everything in the template script to stdout + cat << EOF + server { + listen 80; + server_name $SERVERNAME; + root $ROOT; + + access_log /var/log/nginx/$SERVERNAME_access.log + error_log /var/log/nginx/$SERVERNAME_error.log + } + EOF + +* in the manifest, export the relevant variables and add the following lines in your manifest: + +.. code-block:: console + + # export variables needed for the template + export SERVERNAME='test" + export ROOT='/var/www/test' + # render the template + mkdir -p "$__object/files" + "$__type/files/basic.conf.sh" > "$__object/files/basic.conf" + # send the rendered template + __file /etc/nginx/sites-available/test.conf \ + --state present + --source "$__object/files/basic.conf" + + +TESTING A NEW TYPE +------------------ +If you want to test a new type on a node, you can tell cdist to only use an +object of this type: Use the '--initial-manifest' parameter +with - (stdin) as argument and feed object into stdin +of cdist: + +.. code-block:: sh + + # Singleton type without parameter + echo __ungleich_munin_server | cdist --initial-manifest - munin.panter.ch + + # Singleton type with parameter + echo __ungleich_munin_node --allow 1.2.3.4 | \ + cdist --initial-manifest - rails-19.panter.ch + + # Normal type + echo __file /tmp/stdintest --mode 0644 | \ + cdist --initial-manifest - cdist-dev-01.ungleich.ch + + +OTHER CONTENT IN CDIST REPOSITORY +--------------------------------- +Usually the cdist repository contains all configuration +items. Sometimes you may have additional resources that +you would like to store in your central configuration +repositiory (like password files from KeepassX, +Libreoffice diagrams, etc.). + +It is recommended to use a subfolder named "non-cdist" +in the repository for such content: It allows you to +easily distinguish what is used by cdist and what not +and also to store all important files in one +repository. + + +SEE ALSO +-------- +- `cdist(1) <../man1/cdist.html>`_ +- `cdist-tutorial(7) `_ + + +COPYING +------- +Copyright \(C) 2011-2013 Nico Schottelius. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/docs/man/man7/cdist-best-practice.text b/docs/man/man7/cdist-best-practice.text deleted file mode 100644 index a818be60..00000000 --- a/docs/man/man7/cdist-best-practice.text +++ /dev/null @@ -1,247 +0,0 @@ -cdist-best-practice(7) -====================== -Nico Schottelius - -NAME ----- -cdist-best-practice - Practices used in real environments - - -PASSWORDLESS CONNECTIONS ------------------------- -It is recommended to run cdist with public key authentication. -This requires a private/public key pair and the entry -"PermitRootLogin without-password" in the sshd server. -See sshd_config(5) and ssh-keygen(1). - - -SPEEDING UP SSH CONNECTIONS ---------------------------- -When connecting to a new host, the initial delay with ssh connections -is pretty big. You can work around this by -"sharing of multiple sessions over a single network connection" -(quote from ssh_config(5)). The following code is suitable for -inclusion into your ~/.ssh/config: - --------------------------------------------------------------------------------- -Host * - ControlPath ~/.ssh/master-%l-%r@%h:%p - ControlMaster auto - ControlPersist 10 --------------------------------------------------------------------------------- - -SPEEDING UP SHELL EXECUTION ----------------------------- -On the source host, ensure that /bin/sh is *not* bash: bash is quite slow for -script execution. Instead, you could use dash after installing it: - --------------------------------------------------------------------------------- -ln -sf /bin/dash /bin/sh --------------------------------------------------------------------------------- - - -MULTI MASTER OR ENVIRONMENT SETUPS ----------------------------------- -If you plan to distribute cdist among servers or use different -environments, you can do so easily with the included version -control git. For instance if you plan to use the typical three -environments production, integration and development, you can -realise this with git branches: - --------------------------------------------------------------------------------- -# Go to cdist checkout -cd /path/to/cdist - -# Create branches -git branch development -git branch integration -git branch production - -# Make use of a branch, for instance production -git checkout production --------------------------------------------------------------------------------- - -Similar if you want to have cdist checked out at multiple machines, -you can clone it multiple times: - --------------------------------------------------------------------------------- -machine-a % git clone git://your-git-server/cdist -machine-b % git clone git://your-git-server/cdist --------------------------------------------------------------------------------- - -SEPERATING WORK BY GROUPS -------------------------- -If you are working with different groups on one cdist-configuration, -you can delegate to other manifests and have the groups edit only -their manifests. You can use the following snippet in -**conf/manifests/init**: - --------------------------------------------------------------------------------- -# Include other groups -sh -e "$__manifest/systems" - -sh -e "$__manifest/cbrg" --------------------------------------------------------------------------------- - - -MAINTAINING MULTIPLE CONFIGURATIONS ------------------------------------ -When you need to manage multiple sites with cdist, like company_a, company_b -and private for instance, you can easily use git for this purpose. -Including a possible common base that is reused accross the different sites: - --------------------------------------------------------------------------------- -# create branches -git branch company_a company_b common private - -# make stuff for company a -git checkout company_a -# work, commit, etc. - -# make stuff for company b -git checkout company_b -# work, commit, etc. - -# make stuff relevant for all sites -git checkout common -# work, commit, etc. - -# change to private and include latest common stuff -git checkout private -git merge common --------------------------------------------------------------------------------- - -The following **.git/config** is taken from a a real world scenario: --------------------------------------------------------------------------------- -# Track upstream, merge from time to time -[remote "upstream"] - url = git://git.schottelius.org/cdist - fetch = +refs/heads/*:refs/remotes/upstream/* - -# Same as upstream, but works when being offline -[remote "local"] - fetch = +refs/heads/*:refs/remotes/local/* - url = /home/users/nico/p/cdist - -# Remote containing various ETH internal branches -[remote "eth"] - url = sans.ethz.ch:/home/services/sans/git/cdist-eth - fetch = +refs/heads/*:refs/remotes/eth/* - -# Public remote that contains my private changes to cdist upstream -[remote "nico"] - url = git.schottelius.org:/home/services/git/cdist-nico - fetch = +refs/heads/*:refs/remotes/nico/* - -# The "nico" branch will be synced with the remote nico, branch master -[branch "nico"] - remote = nico - merge = refs/heads/master - -# ETH stable contains rock solid configurations used in various places -[branch "eth-stable"] - remote = eth - merge = refs/heads/stable --------------------------------------------------------------------------------- - -Have a look at git-remote(1) to adjust the remote configuration, which allows - - -MULTIPLE DEVELOPERS WITH DIFFERENT TRUST ----------------------------------------- -If you are working in an environment that requires different people to -work on the same configuration, but having different privileges, you can -implement this scenario with a gateway host and sudo: - -- Create a dedicated user (for instance **cdist**) -- Setup the ssh-pubkey for this user that has the right to configure all hosts -- Create a wrapper to update the cdist configuration in ~cdist/cdist -- Allow every developer to execute this script via sudo as the user cdist -- Allow run of cdist as user cdist on specific hosts on a per user/group base - - f.i. nico ALL=(ALL) NOPASSWD: /home/cdist/bin/cdist config hostabc - -For more details consult sudoers(5) - -TEMPLATING ----------- -* create directory files/ in your type (convention) -* create the template as an executable file like files/basic.conf.sh, it will output text using shell variables for the values - --------------------------------------------------------------------------------- -#!/bin/sh -# in the template, use cat << eof (here document) to output the text -# and use standard shell variables in the template -# output everything in the template script to stdout -cat << EOF -server { - listen 80; - server_name $SERVERNAME; - root $ROOT; - - access_log /var/log/nginx/$SERVERNAME_access.log - error_log /var/log/nginx/$SERVERNAME_error.log -} -EOF --------------------------------------------------------------------------------- - -* in the manifest, export the relevant variables and add the following lines in your manifest: --------------------------------------------------------------------------------- -# export variables needed for the template - export SERVERNAME='test" - export ROOT='/var/www/test' -# render the template - mkdir -p "$__object/files" - "$__type/files/basic.conf.sh" > "$__object/files/basic.conf" -# send the rendered template - __file /etc/nginx/sites-available/test.conf \ - --state present - --source "$__object/files/basic.conf" --------------------------------------------------------------------------------- - - -TESTING A NEW TYPE ------------------- -If you want to test a new type on a node, you can tell cdist to only use an -object of this type: Use the '--initial-manifest' parameter -with - (stdin) as argument and feed object into stdin -of cdist: - --------------------------------------------------------------------------------- -# Singleton type without parameter -echo __ungleich_munin_server | cdist --initial-manifest - munin.panter.ch - -# Singleton type with parameter -echo __ungleich_munin_node --allow 1.2.3.4 | \ - cdist --initial-manifest - rails-19.panter.ch - -# Normal type -echo __file /tmp/stdintest --mode 0644 | \ - cdist --initial-manifest - cdist-dev-01.ungleich.ch --------------------------------------------------------------------------------- - - -OTHER CONTENT IN CDIST REPOSITORY ---------------------------------- -Usually the cdist repository contains all configuration -items. Sometimes you may have additional resources that -you would like to store in your central configuration -repositiory (like password files from KeepassX, -Libreoffice diagrams, etc.). - -It is recommended to use a subfolder named "non-cdist" -in the repository for such content: It allows you to -easily distinguish what is used by cdist and what not -and also to store all important files in one -repository. - - -SEE ALSO --------- -- cdist(1) -- cdist-tutorial(7) - - -COPYING -------- -Copyright \(C) 2011-2013 Nico Schottelius. Free use of this software is -granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/docs/man/man7/cdist-bootstrap.text b/docs/man/man7/cdist-bootstrap.rst similarity index 57% rename from docs/man/man7/cdist-bootstrap.text rename to docs/man/man7/cdist-bootstrap.rst index 985d0f53..df55e2af 100644 --- a/docs/man/man7/cdist-bootstrap.text +++ b/docs/man/man7/cdist-bootstrap.rst @@ -1,13 +1,10 @@ cdist-bootstrap(7) ================== +Setup cdist environment + Nico Schottelius -NAME ----- -cdist-bootstrap - setup cdist environment - - INTRODUCTION ------------ This document describes the usual steps recommended for a new @@ -25,7 +22,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 @@ -42,23 +39,21 @@ you are on the **master** branch. The master branch reflects the latest development of cdist. As this is the development branch, it may or may not work. There are also version branches available, which are kept in a stable state. Let's use **git branch -r** -to list all branches: +to list all branches:: --------------------------------------------------------------------------------- -cdist% git branch -r - origin/1.0 - origin/1.1 - origin/1.2 - origin/1.3 - origin/1.4 - origin/1.5 - origin/1.6 - origin/1.7 - origin/2.0 - origin/HEAD -> origin/master - origin/archive_shell_function_approach - origin/master --------------------------------------------------------------------------------- + cdist% git branch -r + origin/1.0 + origin/1.1 + origin/1.2 + origin/1.3 + origin/1.4 + origin/1.5 + origin/1.6 + origin/1.7 + origin/2.0 + origin/HEAD -> origin/master + origin/archive_shell_function_approach + origin/master So **2.0** is the latest version branch in this example. All versions (2.0.x) within one version branch (2.0) are compatible to each @@ -75,16 +70,14 @@ your own work. Now it's time to create your branch, which contains your local changes. I usually name it by the company/area I am working for: ethz-systems, localch, customerX, ... But this is pretty much up to you. -In this tutorial I use the branch **mycompany**: +In this tutorial I use the branch **mycompany**:: --------------------------------------------------------------------------------- -cdist% git checkout -b mycompany origin/master -Branch mycompany set up to track remote branch master from origin. -Switched to a new branch 'mycompany' -cdist-user% git branch - master -* mycompany --------------------------------------------------------------------------------- + cdist% git checkout -b mycompany origin/master + Branch mycompany set up to track remote branch master from origin. + Switched to a new branch 'mycompany' + cdist-user% git branch + master + * mycompany From now on, you can use git as usual to commit your changes in your own branch. @@ -95,51 +88,47 @@ Usually a development machine like a notebook should be considered temporary only. For this reason and to enable shareability, the configuration should be published to another device as early as possible. The following example shows how to publish the configuration to another host that is -reachable via ssh and has git installed: +reachable via ssh and has git installed:: --------------------------------------------------------------------------------- -# Create bare git repository on the host named "loch" -cdist% ssh loch "GIT_DIR=/home/nutzer/cdist git init" -Initialized empty Git repository in /home/nutzer/cdist/ + # Create bare git repository on the host named "loch" + cdist% ssh loch "GIT_DIR=/home/nutzer/cdist git init" + Initialized empty Git repository in /home/nutzer/cdist/ -# Add remote git repo to git config -cdist% git remote add loch loch:/home/nutzer/cdist + # Add remote git repo to git config + cdist% git remote add loch loch:/home/nutzer/cdist -# Configure the mycompany branch to push to loch -cdist% git config branch.mycompany.remote loch + # Configure the mycompany branch to push to loch + cdist% git config branch.mycompany.remote loch -# Configure mycompany branch to push into remote master branch -cdist% git config branch.mycompany.merge refs/heads/master + # Configure mycompany branch to push into remote master branch + cdist% git config branch.mycompany.merge refs/heads/master -# Push mycompany branch to remote branch master initially -cdist% git push loch mycompany:refs/heads/master --------------------------------------------------------------------------------- + # Push mycompany branch to remote branch master initially + cdist% git push loch mycompany:refs/heads/master Now you have setup the git repository to synchronise the **mycompany** branch with the **master** branch on the host **loch**. Thus you can commit -as usual in your branch and push out changes by entering ***git push***. +as usual in your branch and push out changes by entering **git push**. UPDATING FROM ORIGIN -------------------- -Whenever you want to update your cdist installation, you can use git to do so: +Whenever you want to update your cdist installation, you can use git to do so:: --------------------------------------------------------------------------------- -# Update git repository with latest changes from origin -cdist% git fetch origin + # Update git repository with latest changes from origin + cdist% git fetch origin -# Update current branch with master branch from origin -cdist% git merge origin/master + # Update current branch with master branch from origin + cdist% git merge origin/master -# Alternative: Update current branch with 2.0 branch from origin -cdist% git merge origin/2.0 --------------------------------------------------------------------------------- + # Alternative: Update current branch with 2.0 branch from origin + cdist% git merge origin/2.0 SEE ALSO -------- -- cdist(1) -- cdist-tutorial(7) +- `cdist(1) <../man1/cdist.html>`_ +- `cdist-tutorial(7) `_ COPYING diff --git a/docs/man/man7/cdist-explorer.text b/docs/man/man7/cdist-explorer.rst similarity index 56% rename from docs/man/man7/cdist-explorer.text rename to docs/man/man7/cdist-explorer.rst index 2c25d845..1bbd7e75 100644 --- a/docs/man/man7/cdist-explorer.text +++ b/docs/man/man7/cdist-explorer.rst @@ -1,13 +1,10 @@ cdist-explorer(7) ================= +Explore the target systems + Nico Schottelius -NAME ----- -cdist-explorer - Explore the target systems - - DESCRIPTION ----------- Explorer are small shell scripts, which will be executed on the target @@ -21,9 +18,17 @@ type explorers. Both work almost exactly the same way, with the difference that the values of the general explorers are stored in a general location and the type specific below the object. -Explorers can reuse other explorers on the target system by calling -$__explorer/ (general and type explorer) or -$__type_explorer/ (type explorer). +Explorers can reuse other explorers on the target system by calling + +:: + + $__explorer/ (general and type explorer) + +or + +:: + + $__type_explorer/ (type explorer). In case of significant errors, the explorer may exit non-zero and return an error message on stderr, which will cause cdist to abort. @@ -33,36 +38,34 @@ explorer. EXAMPLES -------- -A very simple explorer may look like this: +A very simple explorer may look like this:: --------------------------------------------------------------------------------- -hostname --------------------------------------------------------------------------------- + hostname -Which is in practise the ***hostname*** explorer. +Which is in practise the **hostname** explorer. A type explorer, which could check for the status of a package may look like this: --------------------------------------------------------------------------------- -if [ -f "$__object/parameter/name" ]; then - name="$(cat "$__object/parameter/name")" -else - name="$__object_id" -fi +.. code-block:: sh -# Except dpkg failing, if package is not known / installed -dpkg -s "$name" 2>/dev/null || exit 0 --------------------------------------------------------------------------------- + if [ -f "$__object/parameter/name" ]; then + name="$(cat "$__object/parameter/name")" + else + name="$__object_id" + fi + + # Expect dpkg failing, if package is not known / installed + dpkg -s "$name" 2>/dev/null || exit 0 SEE ALSO -------- -- cdist(1) -- cdist-reference(7) -- cdist-stages(7) +- `cdist(1) <../man1/cdist.html>`_ +- `cdist-reference(7) `_ +- `cdist-stages(7) `_ COPYING ------- -Copyright \(C) 2010-2012 Nico Schottelius. Free use of this software is +Copyright \(C) 2010-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/docs/man/man7/cdist-hacker.text b/docs/man/man7/cdist-hacker.rst similarity index 60% rename from docs/man/man7/cdist-hacker.text rename to docs/man/man7/cdist-hacker.rst index 2cbf5a8b..1d0e7f2e 100644 --- a/docs/man/man7/cdist-hacker.text +++ b/docs/man/man7/cdist-hacker.rst @@ -1,13 +1,10 @@ cdist-hacker(7) =============== +How to get (stuff) into cdist + Nico Schottelius -NAME ----- -cdist-hacker - How to get (stuff) into cdist - - WELCOME ------- Welcome dear hacker! I invite you to a tour of pointers to @@ -33,6 +30,7 @@ nearby, so grepping for FIXME gives all positions that need to be fixed. Indention is 4 spaces (welcome to the python world). + HOW TO SUBMIT STUFF FOR INCLUSION INTO UPSTREAM CDIST ----------------------------------------------------- If you did some cool changes to cdist, which you value as a benefit for @@ -46,7 +44,9 @@ work nor kill the authors brain: - Do not add cdist/conf/manifest/init - This file should only be touched in your private branch! - Code to be included should be branched of the upstream "master" branch + - Exception: Bugfixes to a version branch + - On a merge request, always name the branch I should pull from - Always ensure **all** manpages build. Use **./build man** to test. - If you developed more than **one** feature, consider submitting them in @@ -69,82 +69,76 @@ AND asciidoc is able to compile it (i.e. do NOT have to many "=" in the second line). Warning: Submitting "exec" or "run" types that simply echo their parameter in -gencode* will not be accepted, because they are of no use. Every type can output +**gencode** will not be accepted, because they are of no use. Every type can output code and thus such a type introduces redundant functionality that is given by core cdist already. EXAMPLE GIT WORKFLOW --------------------- -The following workflow works fine for most developers: +The following workflow works fine for most developers:: --------------------------------------------------------------------------------- -# get latest upstream master branch -git clone https://github.com/telmich/cdist.git + # get latest upstream master branch + git clone https://github.com/telmich/cdist.git -# update if already existing -cd cdist; git fetch -v; git merge origin/master + # update if already existing + cd cdist; git fetch -v; git merge origin/master -# create a new branch for your feature/bugfix -cd cdist # if you haven't done before -git checkout -b documentation_cleanup + # create a new branch for your feature/bugfix + cd cdist # if you haven't done before + git checkout -b documentation_cleanup -# *hack* -*hack* + # *hack* + *hack* -# clone the cdist repository on github if you haven't done so + # clone the cdist repository on github if you haven't done so -# configure your repo to know about your clone (only once) -git remote add github git@github.com:YOURUSERNAME/cdist.git + # configure your repo to know about your clone (only once) + git remote add github git@github.com:YOURUSERNAME/cdist.git -# push the new branch to github -git push github documentation_cleanup + # push the new branch to github + git push github documentation_cleanup -# (or everything) -git push --mirror github + # (or everything) + git push --mirror github -# create a pull request at github (use a browser) -# *fixthingsbecausequalityassurancefoundissuesinourpatch* -*hack* + # create a pull request at github (use a browser) + # *fixthingsbecausequalityassurancefoundissuesinourpatch* + *hack* -# push code to github again -git push ... # like above + # push code to github again + git push ... # like above -# add comment that everything should be green now (use a browser) + # add comment that everything should be green now (use a browser) -# go back to master branch -git checkout master + # go back to master branch + git checkout master -# update master branch that includes your changes now -git fetch -v origin -git diff master..origin/master -git merge origin/master --------------------------------------------------------------------------------- + # update master branch that includes your changes now + git fetch -v origin + git diff master..origin/master + git merge origin/master If at any point you want to go back to the original master branch, you can -use **git stash** to stash your changes away: +use **git stash** to stash your changes away:: --------------------------------------------------------------------------------- -# assume you are on documentation_cleanup -git stash + # assume you are on documentation_cleanup + git stash -# change to master and update to most recent upstream version -git checkout master -git fetch -v origin -git merge origin/master --------------------------------------------------------------------------------- + # change to master and update to most recent upstream version + git checkout master + git fetch -v origin + git merge origin/master Similar when you want to develop another new feature, you go back -to the master branch and create another branch based on it: +to the master branch and create another branch based on it:: --------------------------------------------------------------------------------- -# change to master and update to most recent upstream version -git checkout master -git fetch -v origin -git merge origin/master + # change to master and update to most recent upstream version + git checkout master + git fetch -v origin + git merge origin/master -git checkout -b another_feature --------------------------------------------------------------------------------- + git checkout -b another_feature (you can repeat the code above for as many features as you want to develop in parallel) @@ -152,7 +146,7 @@ in parallel) SEE ALSO -------- -- cdist(7) +- `cdist(1) <../man1/cdist.html>`_ - git(1) - git-checkout(1) - git-stash(1) diff --git a/docs/man/man7/cdist-manifest.rst b/docs/man/man7/cdist-manifest.rst new file mode 100644 index 00000000..c8984acf --- /dev/null +++ b/docs/man/man7/cdist-manifest.rst @@ -0,0 +1,271 @@ +cdist-manifest(7) +================= +(Re-)Use types + +Nico Schottelius + + +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 +object of the type **__file** with the name **etc/cdist-configured**. + +All available types can be found in the **cdist/conf/type/** directory, +use **ls cdist/conf/type** to get the list of available types. If you have +setup the MANPATH correctly, you can use **man cdist-reference** to access +the reference with pointers to the manpages. + + +Types in manifests are used like normal command line tools. Let's have a look +at an example:: + + # Create object of type __package with the parameter state = absent + __package apache2 --state absent + + # Same with the __directory type + __directory /tmp/cdist --state present + +These two lines create objects, which will later be used to realise the +configuration on the target host. + +Manifests are executed locally as a shell script using **/bin/sh -e**. +The resulting objects are stored in an internal database. + +The same object can be redefined in multiple different manifests as long as +the parameters are exactly the same. + +In general, manifests are used to define which types are used depending +on given conditions. + + +INITIAL AND TYPE MANIFESTS +-------------------------- +Cdist knows about two types of manifests: The initial manifest and type +manifests. The initial manifest is used to define, which configurations +to apply to which hosts. The type manifests are used to create objects +from types. More about manifests in types can be found in cdist-type(7). + + +DEFINE STATE IN THE INITIAL MANIFEST +------------------------------------ +The **initial manifest** is the entry point for cdist to find out, which +**objects** to configure on the selected host. +Cdist expects the initial manifest at **cdist/conf/manifest/init**. + +Within this initial manifest you define, which objects should be +created on which host. To distinguish between hosts, you can use the +environment variable **__target_host**. Let's have a look at a simple +example:: + + __cdistmarker + + case "$__target_host" in + localhost) + __directory /home/services/kvm-vm --parents yes + ;; + esac + +This manifest says: Independent of the host, always use the type +**__cdistmarker**, which creates the file **/etc/cdist-configured**, +with the timestamp as content. +The directory **/home/services/kvm-vm**, including all parent directories, +is only created on the host **localhost**. + +As you can see, there is no magic involved, the manifest is simple shell code that +utilises cdist types. Every available type can be executed like a normal +command. + + +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 +the directory containing the initial manifest (see cdist-reference(7)). + +The following example would include every file with a **.sh** suffix:: + + # Include *.sh + for manifest in $__manifest/*.sh; do + # And source scripts into our shell environment + . "$manifest" + done + + +DEPENDENCIES +------------ +If you want to describe that something requires something else, just +setup the variable "require" to contain the requirements. Multiple +requirements can be added white space separated. + +:: + + 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 always 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). + +If you really need to make all types depend on a common dependency, you can +export the "require" variable as well. But then, if you need to add extra +dependencies to a specific type, you have to make sure that you append these +to the globally already defined one. + +:: + + # First of all, update the package index + __package_update_index + # Upgrade all the installed packages afterwards + require="__package_update_index" __package_upgrade_all + # Create a common dependency for all the next types so that they get to + # be executed only after the package upgrade has finished + export require="__package_upgrade_all" + + # Ensure that lighttpd is installed after we have upgraded all the packages + __package lighttpd --state present + # Ensure that munin is installed after lighttpd is present and after all + # the packages are upgraded + require="$require __package/lighttpd" __package munin --state present + + +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 +in the manifest by setting up the variable CDIST_ORDER_DEPENDENCY. +When cdist sees that this variable is setup, the current created object +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). + + +OVERRIDES +--------- +In some special cases, you would like to create an already defined object +with different parameters. In normal situations this leads to an error in cdist. +If you wish, 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 encounters the affected objects, otherwise this results +in an undefined situation. + +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. + + +EXAMPLES +-------- +The initial manifest may for instance contain the following code: + +.. code-block:: sh + + # Always create this file, so other sysadmins know cdist is used. + __file /etc/cdist-configured + + case "$__target_host" in + my.server.name) + __directory /root/bin/ + __file /etc/issue.net --source "$__manifest/issue.net + ;; + esac + +The manifest of the type "nologin" may look like this: + +.. code-block:: sh + + __file /etc/nologin --source "$__type/files/default.nologin" + +This example makes use of dependencies: + +.. code-block:: sh + + # Ensure that lighttpd is installed + __package lighttpd --state present + # Ensure that munin makes use of lighttpd instead of the default webserver + # package as decided by the package manager + require="__package/lighttpd" __package munin --state present + +How to override objects: + +.. code-block:: sh + + # for example in the inital manifest + + # 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 ... + # somewhere in a conditionally sourced manifest + # (e.g. for example only sourced if a special application is on the target host) + + # this leads to an error ... + __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' + # 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: + +.. code-block:: sh + + # Tells cdist to execute all types in the order in which they are created ... + export CDIST_ORDER_DEPENDENCY=on + __sample_type 1 + require="__some_type_somewhere/id" __sample_type 2 + __example_type 23 + # Now this types are executed in the creation order until the variable is unset + unset CDIST_ORDER_DEPENDENCY + # all now following types cdist makes the order .. + __not_in_order_type 42 + + # how it works : + # this lines above are translated to: + __sample_type 1 + require="__some_type_somewhere/id __sample_type/1" __sample_type 2 + require="__sample_type/2" __example_type 23 + __not_in_order_type 42 + + +SEE ALSO +-------- +- `cdist-tutorial(7) `_ +- `cdist-type(7) `_ + + +COPYING +------- +Copyright \(C) 2010-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/docs/man/man7/cdist-manifest.text b/docs/man/man7/cdist-manifest.text deleted file mode 100644 index 057905ea..00000000 --- a/docs/man/man7/cdist-manifest.text +++ /dev/null @@ -1,251 +0,0 @@ -cdist-manifest(7) -================= -Nico Schottelius - - -NAME ----- -cdist-manifest - (Re-)Use types - - -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 -object of the type ***__file*** with the name ***etc/cdist-configured***. - -All available types can be found in the **cdist/conf/type/** directory, -use **ls cdist/conf/type** to get the list of available types. If you have -setup the MANPATH correctly, you can use **man cdist-reference** to access -the reference with pointers to the manpages. - - -Types in manifests are used like normal command line tools. Let's have a look -at an example: --------------------------------------------------------------------------------- -# Create object of type __package with the parameter state = absent -__package apache2 --state absent - -# Same with the __directory type - __directory /tmp/cdist --state present --------------------------------------------------------------------------------- - -These two lines create objects, which will later be used to realise the -configuration on the target host. - -Manifests are executed locally as a shell script using **/bin/sh -e**. -The resulting objects are stored in an internal database. - -The same object can be redefined in multiple different manifests as long as -the parameters are exactly the same. - -In general, manifests are used to define which types are used depending -on given conditions. - - -INITIAL AND TYPE MANIFESTS --------------------------- -Cdist knows about two types of manifests: The initial manifest and type -manifests. The initial manifest is used to define, which configurations -to apply to which hosts. The type manifests are used to create objects -from types. More about manifests in types can be found in cdist-type(7). - - -DEFINE STATE IN THE INITIAL MANIFEST ------------------------------------- -The **initial manifest** is the entry point for cdist to find out, which -**objects** to configure on the selected host. -Cdist expects the initial manifest at **cdist/conf/manifest/init**. - -Within this initial manifest you define, which objects should be -created on which host. To distinguish between hosts, you can use the -environment variable **__target_host**. Let's have a look at a simple -example: - --------------------------------------------------------------------------------- -__cdistmarker - -case "$__target_host" in - localhost) - __directory /home/services/kvm-vm --parents yes - ;; -esac --------------------------------------------------------------------------------- - -This manifest says: Independent of the host, always use the type -***__cdistmarker***, which creates the file **/etc/cdist-configured**, -with the timestamp as content. -The directory ***/home/services/kvm-vm***, including all parent directories, -is only created on the host ***localhost***. - -As you can see, there is no magic involved, the manifest is simple shell code that -utilises cdist types. Every available type can be executed like a normal -command. - - -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 -the directory containing the initial manifest (see cdist-reference(7)). - -The following example would include every file with a **.sh** suffix: - --------------------------------------------------------------------------------- -# Include *.sh -for manifest in $__manifest/*.sh; do - # And source scripts into our shell environment - . "$manifest" -done --------------------------------------------------------------------------------- - - -DEPENDENCIES ------------- -If you want to describe that something requires something else, just -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 - - --------------------------------------------------------------------------------- - -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. - -CREATE DEPENDENCIES FROM EXECUTION ORDER ------------------------------------------ -You can tell cdist to execute all types in the order in which they are created -in the manifest by setting up the variable CDIST_ORDER_DEPENDENCY. -When cdist sees that this variable is setup, the current created object -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 ---------- -In some special cases, you would like to create an already defined object -with different parameters. In normal situations this leads to an error in cdist. -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. - -If CDIST_OVERRIDE and CDIST_ORDER_DEPENDENCY is 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. - -THIS IS A BETA FEATURE AND MAY BE REMOVED OR CHANGED AT ANY TIME. - - - - -EXAMPLES --------- -The initial manifest may for instance contain the following code: - --------------------------------------------------------------------------------- -# Always create this file, so other sysadmins know cdist is used. -__file /etc/cdist-configured - -case "$__target_host" in - my.server.name) - __directory /root/bin/ - __file /etc/issue.net --source "$__manifest/issue.net - ;; -esac --------------------------------------------------------------------------------- - -The manifest of the type "nologin" may look like this: - --------------------------------------------------------------------------------- -__file /etc/nologin --source "$__type/files/default.nologin" --------------------------------------------------------------------------------- - -This example makes use of dependencies: - --------------------------------------------------------------------------------- -# Ensure that lighttpd is installed -__package lighttpd --state present -# Ensure that munin makes use of lighttpd instead of the default webserver -# package as decided by the package manager -require="__package/lighttpd" __package munin --state present --------------------------------------------------------------------------------- - -How to override objects: - --------------------------------------------------------------------------------- -# for example in the inital manifest - -# reate 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 ... -# somewhere in a conditionaly sourced manifest -# (e.g. for example only sourced if a special application is on the target host) - -# this leads to an error ... -__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 --------------------------------------------------------------------------------- - -Dependencies defined by execution order work as following: - --------------------------------------------------------------------------------- - -# Tells cdist to execute all types in the order in which they are created ... -export CDIST_ORDER_DEPENDENCY=on -__sample_type 1 -require="__some_type_somewhere/id" __sample_type 2 -__example_type 23 -# Now this types are executed in the creation order until the variable is unset -unset CDIST_ORDER_DEPENDENCY -# all now following types cdist makes the order .. -__not_in_order_type 42 - -# how it works : -# this lines above are translated to: -__sample_type 1 -require="__some_type_somewhere/id __sample_type/1" __sample_type 2 -require="__sample_type/2" __example_type 23 -__not_in_order_type 42 - --------------------------------------------------------------------------------- - - - -SEE ALSO --------- -- cdist-tutorial(7) -- cdist-type(7) - - -COPYING -------- -Copyright \(C) 2010-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/docs/man/man7/cdist-messaging.rst b/docs/man/man7/cdist-messaging.rst new file mode 100644 index 00000000..6f29a363 --- /dev/null +++ b/docs/man/man7/cdist-messaging.rst @@ -0,0 +1,111 @@ +cdist-messaging(7) +================== +How the initial manifest and types can communication + +Nico Schottelius + +DESCRIPTION +----------- +cdist has a simple but powerful way of allowing communication between +the initial manifest and types as well as types and types. + +Whenever execution is passed from cdist to one of the +scripts described below, cdist generate 2 new temporary files +and exports the environment variables **__messages_in** and +**__messages_out** to point to them. + +Before handing over the control, the content of the global message +file is copied into the file referenced by **$__messages_in**. + +After cdist gained control back, the content of the file referenced +by **$__messages_out** is appended to the global message file. + +This way overwriting any of the two files by accident does not +interfere with other types. + +The order of execution is not defined unless you create dependencies +between the different objects (see cdist-manifest(7)) and thus you +can only react reliably on messages by objects that you depend on. + + +AVAILABILITY +------------ +Messaging is possible between all **local** scripts: + +- initial manifest +- type/manifest +- type/gencode-local +- type/gencode-remote + + +EXAMPLES +-------- +When you want to emit a message use: + +.. code-block:: sh + + echo "something" >> "$__messages_out" + +When you want to react on a message use: + +.. code-block:: sh + + if grep -q "^__your_type/object/id:something" "$__messages_in"; then + echo "I do something else" + fi + +Some real life examples: + +.. code-block:: sh + + # Reacting on changes from block for keepalive + if grep -q "^__block/keepalive-vrrp" "$__messages_in"; then + echo /etc/init.d/keepalived restart + fi + + # Reacting on changes of configuration files + if grep -q "^__file/etc/one" $__messages_in; then + echo 'for init in /etc/init.d/opennebula*; do $init restart; done' + fi + +Restart sshd on changes + +.. code-block:: sh + + os="$(cat "$__global/explorer/os")" + + case "$os" in + centos|redhat|suse) + restart="/etc/init.d/sshd restart" + ;; + debian|ubuntu) + restart="/etc/init.d/ssh restart" + ;; + *) + cat << eof >&2 + Unsupported os $os. + If you would like to have this type running on $os, + you can either develop the changes and send a pull + request or ask for a quote at www.ungleich.ch + eof + exit 1 + ;; + esac + + if grep -q "^__key_value/PermitRootLogin" "$__messages_in"; then + echo $restart + fi + + +SEE ALSO +-------- +- `cdist(1) <../man1/cdist.html>`_ +- `cdist-manifest(7) `_ +- `cdist-reference(7) `_ +- `cdist-type(7) `_ + + +COPYING +------- +Copyright \(C) 2013 Nico Schottelius. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/docs/man/man7/cdist-messaging.text b/docs/man/man7/cdist-messaging.text deleted file mode 100644 index 0e53871e..00000000 --- a/docs/man/man7/cdist-messaging.text +++ /dev/null @@ -1,72 +0,0 @@ -cdist-messaging(7) -================== -Nico Schottelius - -NAME ----- -cdist-messaging - How the initial manifest and types can communication - - -DESCRIPTION ------------ -cdist has a simple but powerful way of allowing communication between -the initial manifest and types as well as types and types. - -Whenever execution is passed from cdist to one of the -scripts described below, cdist generate 2 new temporary files -and exports the environment variables __messages_in and -__messages_out to point to them. - -Before handing over the control, the content of the global message -file is copied into the file referenced by $__messages_in. - -After cdist gained control back, the content of the file referenced -by $__messages_out is appended to the global message file. - -This way overwriting any of the two files by accident does not -interfere with other types. - -The order of execution is not defined unless you create dependencies -between the different objects (see cdist-manifest(7)) and thus you -can only react reliably on messages by objects that you depend on. - - -AVAILABILITY ------------- -Messaging is possible between all **local** scripts: - -- initial manifest -- type/manifest -- type/gencode-local -- type/gencode-remote - - -EXAMPLES --------- -When you want to emit a message use: - --------------------------------------------------------------------------------- -echo "something" >> "$__messages_out" --------------------------------------------------------------------------------- - -When you want to react on a message use: - --------------------------------------------------------------------------------- -if grep -q "^__your_type/object/id:something" "$__messages_in"; then - echo "I do something else" -fi --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist(1) -- cdist-manifest(7) -- cdist-reference(7) -- cdist-type(7) - - -COPYING -------- -Copyright \(C) 2013 Nico Schottelius. Free use of this software is -granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/docs/man/man7/cdist-quickstart.text b/docs/man/man7/cdist-quickstart.rst similarity index 50% rename from docs/man/man7/cdist-quickstart.text rename to docs/man/man7/cdist-quickstart.rst index 8b754650..d1186ffe 100644 --- a/docs/man/man7/cdist-quickstart.text +++ b/docs/man/man7/cdist-quickstart.rst @@ -1,13 +1,10 @@ cdist-quickstart(7) =================== +Jump in and enjoy cdist + Nico Schottelius -NAME ----- -cdist-quickstart - jump in and enjoy cdist - - INTRODUCTION ------------ This tutorial is aimed at people learning cdist and shows @@ -31,62 +28,55 @@ and usually logs into the **target host** as the **root** user. So you need to configure the **ssh server** of the target host to allow root logins: Edit the file **/etc/ssh/sshd_config** and add one of the following -lines: +lines:: --------------------------------------------------------------------------------- -# Allow login only via public key -PermitRootLogin without-password + # Allow login only via public key + PermitRootLogin without-password -# Allow login via password and public key -PermitRootLogin yes --------------------------------------------------------------------------------- + # Allow login via password and public key + PermitRootLogin yes As cdist uses ssh intensively, it is recommended to setup authentication -with public keys: +with public keys:: --------------------------------------------------------------------------------- -# Generate pubkey pair as a normal user -ssh-keygen + # Generate pubkey pair as a normal user + ssh-keygen -# Copy pubkey over to target host -ssh-copy-id root@localhost --------------------------------------------------------------------------------- + # Copy pubkey over to target host + ssh-copy-id root@localhost Have a look at ssh-agent(1) and ssh-add(1) on how to cache the password for -your public key. Usually it looks like this: +your public key. Usually it looks like this:: --------------------------------------------------------------------------------- -# Start agent and export variables -eval `ssh-agent` + # Start agent and export variables + eval `ssh-agent` -# Add keys (requires password for every identity file) -ssh-add --------------------------------------------------------------------------------- + # Add keys (requires password for every identity file) + ssh-add -At this point you should be able to ***ssh root@localhost*** without +At this point you should be able to **ssh root@localhost** without re-entering the password. If something failed until here, ensure that all steps went successfully and you have read and understood the documentation. As soon as you are able to login without password to localhost, we can use cdist to configure it. You can copy and paste the following -code into your shell to get started and configure localhost: --------------------------------------------------------------------------------- -# Get cdist -# Mirrors can be found on -# http://www.nico.schottelius.org/software/cdist/install/#index2h4 -git clone git://git.schottelius.org/cdist +code into your shell to get started and configure localhost:: -# Create manifest (maps configuration to host(s) -cd cdist -echo '__file /etc/cdist-configured' > cdist/conf/manifest/init + # Get cdist + # Mirrors can be found on + # http://www.nico.schottelius.org/software/cdist/install/#index2h4 + git clone git://git.schottelius.org/cdist -# Configure localhost in verbose mode -./bin/cdist config -v localhost + # Create manifest (maps configuration to host(s) + cd cdist + echo '__file /etc/cdist-configured' > cdist/conf/manifest/init -# Find out that cdist created /etc/cdist-configured -ls -l /etc/cdist-configured --------------------------------------------------------------------------------- + # Configure localhost in verbose mode + ./bin/cdist config -v localhost + + # Find out that cdist created /etc/cdist-configured + ls -l /etc/cdist-configured That's it, you've successfully used cdist to configure your first host! Continue reading the next sections, to understand what you did and how @@ -95,8 +85,8 @@ to create a more sophisticated configuration. SEE ALSO -------- -- cdist(1) -- cdist-tutorial(7) +- `cdist(1) <../man1/cdist.html>`_ +- `cdist-tutorial(7) `_ COPYING diff --git a/docs/man/man7/cdist-remote-exec-copy.text b/docs/man/man7/cdist-remote-exec-copy.rst similarity index 84% rename from docs/man/man7/cdist-remote-exec-copy.text rename to docs/man/man7/cdist-remote-exec-copy.rst index 298891d6..27b78d42 100644 --- a/docs/man/man7/cdist-remote-exec-copy.text +++ b/docs/man/man7/cdist-remote-exec-copy.rst @@ -1,23 +1,22 @@ cdist-remote-exec-copy(7) ========================= +How to use remote exec and copy + Nico Schottelius -NAME ----- -cdist-remote-exec-copy - How to use remote exec and copy - - INTRO ----- Cdist interacts with the target host in two ways: + - it executes code (__remote_exec) - and it copies files (__remote_copy) By default this is accomplished with ssh and scp respectively. -The default implementations used by cdist are: -__remote_exec: ssh -o User=root -q -__remote_copy: scp -o User=root -q +The default implementations used by cdist are:: + + __remote_exec: ssh -o User=root -q + __remote_copy: scp -o User=root -q The user can override these defaults by providing custom implementations and passing them to cdist with the --remote-exec and/or --remote-copy arguments. @@ -37,7 +36,7 @@ See cdist/other/examples/remote/ for some example implementations. SEE ALSO -------- -- cdist(7) +- `cdist(1) <../man1/cdist.html>`_ COPYING diff --git a/docs/man/man7/cdist-stages.text b/docs/man/man7/cdist-stages.rst similarity index 95% rename from docs/man/man7/cdist-stages.text rename to docs/man/man7/cdist-stages.rst index 5f2d2e4c..4b29585d 100644 --- a/docs/man/man7/cdist-stages.text +++ b/docs/man/man7/cdist-stages.rst @@ -1,12 +1,9 @@ cdist-stages(7) =============== +Stages used during configuration deployment + Nico Schottelius -NAME ----- -cdist-stages - Stages used during configuration deployment - - DESCRIPTION ----------- Starting the execution of deployment with cdist, cdist passes @@ -79,8 +76,8 @@ will be applied to the target. SEE ALSO -------- -- cdist(1) -- cdist-reference(7) +- `cdist(1) <../man1/cdist.html>`_ +- `cdist-reference(7) `_ COPYING diff --git a/docs/man/man7/cdist-troubleshooting.text b/docs/man/man7/cdist-troubleshooting.rst similarity index 52% rename from docs/man/man7/cdist-troubleshooting.text rename to docs/man/man7/cdist-troubleshooting.rst index 7c5e7612..075c3480 100644 --- a/docs/man/man7/cdist-troubleshooting.text +++ b/docs/man/man7/cdist-troubleshooting.rst @@ -1,28 +1,25 @@ cdist-troubleshooting(7) ======================== +Common problems and their solutions + Nico Schottelius -NAME ----- -cdist-troubleshooting - common problems and their solutions - - ERROR IN MANIFEST IS NOT CONSIDERED AN ERROR BY CDIST ----------------------------------------------------- Situation: You are executing other scripts from a manifest. This script fails, but cdist does not recognise the error. An example script would be something like this: --------------------------------------------------------------------------------- -% cat ~/.cdist/manifest/init -"$__manifest/special" -% cat ~/.cdist/manifest/special -#!/bin/sh -echo "Here is an unclean exiting script" -somecommandthatdoesnotexist -echo "I continue here although previous command failed" --------------------------------------------------------------------------------- +.. code-block:: sh + + % cat ~/.cdist/manifest/init + "$__manifest/special" + % cat ~/.cdist/manifest/special + #!/bin/sh + echo "Here is an unclean exiting script" + somecommandthatdoesnotexist + echo "I continue here although previous command failed" We can clearly see that **somecommandthatdoesnotexist** will fail in ~/.cdist/manifest/special. But as the custom @@ -33,28 +30,29 @@ code of the last echo line instead of the failing command. All scripts executed by cdist carry the -e flag. To prevent the above from happening, there are three solutions available, two of which can be used in the calling script: --------------------------------------------------------------------------------- -# Execute as before, but abort on failure -sh -e "$__manifest/special" -# Source the script in our namespace, runs in a set -e environment: -. "$__manifest/special" --------------------------------------------------------------------------------- +.. code-block:: sh + + # Execute as before, but abort on failure + sh -e "$__manifest/special" + + # Source the script in our namespace, runs in a set -e environment: + . "$__manifest/special" The third solution is to include a shebang header in every script you write to use the -e flag: --------------------------------------------------------------------------------- -% cat ~/.cdist/manifest/special -#!/bin/sh -e -... --------------------------------------------------------------------------------- +.. code-block:: sh + + % cat ~/.cdist/manifest/special + #!/bin/sh -e + ... SEE ALSO -------- -- cdist(1) -- cdist-tutorial(7) +- `cdist(1) <../man1/cdist.html>`_ +- `cdist-tutorial(7) `_ COPYING diff --git a/docs/man/man7/cdist-tutorial.text b/docs/man/man7/cdist-tutorial.rst similarity index 78% rename from docs/man/man7/cdist-tutorial.text rename to docs/man/man7/cdist-tutorial.rst index 85419025..4899dcb0 100644 --- a/docs/man/man7/cdist-tutorial.text +++ b/docs/man/man7/cdist-tutorial.rst @@ -1,13 +1,10 @@ cdist-tutorial(7) ================= +A guided introduction into cdist + Nico Schottelius -NAME ----- -cdist-tutorial - a guided introduction into cdist - - INTRODUCTION ------------ This document gives you a pointer on what to read in @@ -16,40 +13,40 @@ So in case you are just starting, just "begin at the beginning" (Brave New World). You can see the target audience in [] brackets after the description. -cdist-quickstart:: +cdist-quickstart New to cdist? Want to get your hands dirty? Read this. [beginner] -cdist-bootstrap:: +cdist-bootstrap The comprehensive guide to your first cdist installation [beginner] -cdist-manifest:: +cdist-manifest Learn how to define which hosts get which configurations [beginner] -cdist-type:: +cdist-type Understand how types are working and created [intermediate] -cdist-best-practice:: +cdist-best-practice Hints from real life experience to help you to organise cdist [intermediate] -cdist-reference:: +cdist-reference The type, explorers and environment variables reference [intermediate] -cdist-explorer:: +cdist-explorer Interested in getting more information about the target system? [intermediate] -cdist-stages:: +cdist-stages Understand the internal workflow of cdist. [advanced] -cdist-hacker:: +cdist-hacker README, if you want to extend or modify cdist. [hacker] SEE ALSO -------- -- cdist(1) -- cdist-type(7) -- cdist-best-practice(7) -- cdist-stages(7) +- `cdist(1) <../man1/cdist.html>`_ +- `cdist-type(7) `_ +- `cdist-best-practice(7) `_ +- `cdist-stages(7) `_ - Brave New World by Aldous Huxley COPYING diff --git a/docs/man/man7/cdist-type.text b/docs/man/man7/cdist-type.rst similarity index 53% rename from docs/man/man7/cdist-type.text rename to docs/man/man7/cdist-type.rst index 06026542..cfd331e1 100644 --- a/docs/man/man7/cdist-type.text +++ b/docs/man/man7/cdist-type.rst @@ -1,18 +1,17 @@ cdist-type(7) ============= +Functionality bundled + Nico Schottelius -NAME ----- -cdist-type - Functionality bundled - - SYNOPSIS -------- -__TYPE ID --parameter value [--parameter value ...] -__TYPE --parameter value [--parameter value ...] (for singletons) +:: + + __TYPE ID --parameter value [--parameter value ...] + __TYPE --parameter value [--parameter value ...] (for singletons) DESCRIPTION @@ -25,15 +24,15 @@ 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 -__file /etc/cdist-configured --type file +.. code-block:: sh -# Ensure tree is installed -__package tree --state installed --------------------------------------------------------------------------------- + # Creates empty file /etc/cdist-configured + __file /etc/cdist-configured --type file + + # Ensure tree is installed + __package tree --state installed A list of supported types can be found in the cdist-reference(7) manpage. @@ -44,14 +43,16 @@ If a type is flagged as a singleton, it may be used only once per host. This is useful for types which can be used only once on a system. Singleton types do not take an object name as argument. -Example: --------------------------------------------------------------------------------- -# __issue type manages /etc/issue -__issue -# Probably your own type - singletons may use parameters -__myfancysingleton --colour green --------------------------------------------------------------------------------- +Example: + +.. code-block:: sh + + # __issue type manages /etc/issue + __issue + + # Probably your own type - singletons may use parameters + __myfancysingleton --colour green HOW TO WRITE A NEW TYPE @@ -73,9 +74,9 @@ To implement a new type, create the directory **cdist/conf/type/__NAME**. DEFINING PARAMETERS ------------------- Every type consists of required, optional and boolean parameters, which must -each be declared in a newline separated file in ***parameter/required***, -***parameter/required_multiple***, ***parameter/optional***, -***parameter/optional_multiple*** and ***parameter/boolean***. +each be declared in a newline separated file in **parameter/required**, +**parameter/required_multiple**, **parameter/optional**, +**parameter/optional_multiple** and **parameter/boolean**. Parameters which are allowed multiple times should be listed in required_multiple or optional_multiple respectively. All other parameters follow the standard unix behaviour "the last given wins". @@ -83,82 +84,85 @@ If either is missing, the type will have no required, no optional, no boolean or no parameters at all. Default values for optional parameters can be predefined in -***parameter/default/***. +**parameter/default/**. Example: --------------------------------------------------------------------------------- -echo servername >> cdist/conf/type/__nginx_vhost/parameter/required -echo logdirectory >> cdist/conf/type/__nginx_vhost/parameter/optional -echo loglevel >> cdist/conf/type/__nginx_vhost/parameter/optional -mkdir cdist/conf/type/__nginx_vhost/parameter/default -echo warning > cdist/conf/type/__nginx_vhost/parameter/default/loglevel -echo server_alias >> cdist/conf/type/__nginx_vhost/parameter/optional_multiple -echo use_ssl >> cdist/conf/type/__nginx_vhost/parameter/boolean --------------------------------------------------------------------------------- + +.. code-block:: sh + + echo servername >> cdist/conf/type/__nginx_vhost/parameter/required + echo logdirectory >> cdist/conf/type/__nginx_vhost/parameter/optional + echo loglevel >> cdist/conf/type/__nginx_vhost/parameter/optional + mkdir cdist/conf/type/__nginx_vhost/parameter/default + echo warning > cdist/conf/type/__nginx_vhost/parameter/default/loglevel + echo server_alias >> cdist/conf/type/__nginx_vhost/parameter/optional_multiple + echo use_ssl >> cdist/conf/type/__nginx_vhost/parameter/boolean USING PARAMETERS ---------------- The parameters given to a type can be accessed and used in all type scripts -(e.g manifest, gencode-*, explorer/*). Note that boolean parameters are +(e.g manifest, gencode, explorer). Note that boolean parameters are represented by file existence. File exists -> True, file does not exist -> False Example: (e.g. in cdist/conf/type/__nginx_vhost/manifest) --------------------------------------------------------------------------------- -# required parameter -servername="$(cat "$__object/parameter/servername")" -# optional parameter -if [ -f "$__object/parameter/logdirectory" ]; then - logdirectory="$(cat "$__object/parameter/logdirectory")" -fi +.. code-block:: sh -# optional parameter with predefined default -loglevel="$(cat "$__object/parameter/loglevel")" + # required parameter + servername="$(cat "$__object/parameter/servername")" -# boolean parameter -if [ -f "$__object/parameter/use_ssl" ]; then - # file exists -> True - # do some fancy ssl stuff -fi + # optional parameter + if [ -f "$__object/parameter/logdirectory" ]; then + logdirectory="$(cat "$__object/parameter/logdirectory")" + fi -# parameter with multiple values -if [ -f "$__object/parameter/server_alias" ]; then - for alias in $(cat "$__object/parameter/server_alias"); do - echo $alias > /some/where/usefull - done -fi + # optional parameter with predefined default + loglevel="$(cat "$__object/parameter/loglevel")" --------------------------------------------------------------------------------- + # boolean parameter + if [ -f "$__object/parameter/use_ssl" ]; then + # file exists -> True + # do some fancy ssl stuff + fi + + # parameter with multiple values + if [ -f "$__object/parameter/server_alias" ]; then + for alias in $(cat "$__object/parameter/server_alias"); do + echo $alias > /some/where/usefull + done + fi INPUT FROM STDIN ---------------- Every type can access what has been written on stdin when it has been called. -The result is saved into the ***stdin*** file in the object directory. +The result is saved into the **stdin** file in the object directory. Example use of a type: (e.g. in cdist/conf/type/__archlinux_hostname) --------------------------------------------------------------------------------- -__file /etc/rc.conf --source - << eof -... -HOSTNAME="$__target_host" -... -eof --------------------------------------------------------------------------------- + +.. code-block:: sh + + __file /etc/rc.conf --source - << eof + ... + HOSTNAME="$__target_host" + ... + eof + If you have not seen this syntax (<< eof) before, it may help you to read about "here documents". In the __file type, stdin is used as source for the file, if - is used for source: --------------------------------------------------------------------------------- +.. code-block:: sh + if [ -f "$__object/parameter/source" ]; then source="$(cat "$__object/parameter/source")" if [ "$source" = "-" ]; then source="$__object/stdin" fi .... --------------------------------------------------------------------------------- WRITING THE MANIFEST @@ -167,20 +171,20 @@ In the manifest of a type you can use other types, so your type extends their functionality. A good example is the __package type, which in a shortened version looks like this: --------------------------------------------------------------------------------- -os="$(cat "$__global/explorer/os")" -case "$os" in - archlinux) type="pacman" ;; - debian|ubuntu) type="apt" ;; - gentoo) type="emerge" ;; - *) - echo "Don't know how to manage packages on: $os" >&2 - exit 1 - ;; -esac +.. code-block:: sh -__package_$type "$@" --------------------------------------------------------------------------------- + os="$(cat "$__global/explorer/os")" + case "$os" in + archlinux) type="pacman" ;; + debian|ubuntu) type="apt" ;; + gentoo) type="emerge" ;; + *) + echo "Don't know how to manage packages on: $os" >&2 + exit 1 + ;; + esac + + __package_$type "$@" As you can see, the type can reference different environment variables, which are documented in cdist-reference(7). @@ -195,15 +199,15 @@ If you want to ensure that a type can only be used once per target, you can mark it as a singleton: Just create the (empty) file "singleton" in your type directory: --------------------------------------------------------------------------------- -touch cdist/conf/type/__NAME/singleton --------------------------------------------------------------------------------- +.. code-block:: sh + + touch cdist/conf/type/__NAME/singleton This will also change the way your type must be called: --------------------------------------------------------------------------------- -__YOURTYPE --parameter value --------------------------------------------------------------------------------- +.. code-block:: sh + + __YOURTYPE --parameter value As you can see, the object ID is omitted, because it does not make any sense, if your type can be used only once. @@ -218,22 +222,22 @@ The explorers are stored under the "explorer" directory below the type. It could for instance contain code to check the md5sum of a file on the client, like this (shortened version from the type __file): --------------------------------------------------------------------------------- -if [ -f "$__object/parameter/destination" ]; then - destination="$(cat "$__object/parameter/destination")" -else - destination="/$__object_id" -fi +.. code-block:: sh -if [ -e "$destination" ]; then - md5sum < "$destination" -fi --------------------------------------------------------------------------------- + if [ -f "$__object/parameter/destination" ]; then + destination="$(cat "$__object/parameter/destination")" + else + destination="/$__object_id" + fi + + if [ -e "$destination" ]; then + md5sum < "$destination" + fi WRITING THE GENCODE SCRIPT -------------------------- -There are two gencode scripts: ***gencode-local*** and ***gencode-remote***. +There are two gencode scripts: **gencode-local** and **gencode-remote**. The output of gencode-local is executed locally, whereas the output of gencode-remote is executed on the target. The gencode scripts can make use of the parameters, the global explorers @@ -243,13 +247,13 @@ If the gencode scripts encounters an error, it should print diagnostic messages to stderr and exit non-zero. If you need to debug the gencode script, you can write to stderr: --------------------------------------------------------------------------------- -# Debug output to stderr -echo "My fancy debug line" >&2 +.. code-block:: sh -# Output to be saved by cdist for execution on the target -echo "touch /etc/cdist-configured" --------------------------------------------------------------------------------- + # Debug output to stderr + echo "My fancy debug line" >&2 + + # Output to be saved by cdist for execution on the target + echo "touch /etc/cdist-configured" VARIABLE ACCESS FROM THE GENERATED SCRIPTS @@ -264,13 +268,13 @@ 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 --------------------------------------------------------------------------------- +.. code-block:: sh + + if [ -f "$__object/parameter/name" ]; then + name="$(cat "$__object/parameter/name")" + else + name="$__object_id" + fi HINTS FOR TYPEWRITERS @@ -281,7 +285,7 @@ on the target, there must be another type that provides this tool and the first type should create an object of the specific type. If your type wants to save temporary data, that may be used by other types -later on (for instance __file), you can save them in the subdirectory +later on (for instance \__file), you can save them in the subdirectory "files" below $__object (but you must create it yourself). cdist will not touch this directory. @@ -298,10 +302,10 @@ how to submit it. SEE ALSO -------- -- cdist-explorer(7) -- cdist-hacker(7) -- cdist-stages(7) -- cdist-tutorial(7) +- `cdist-explorer(7) `_ +- `cdist-hacker(7) `_ +- `cdist-stages(7) `_ +- `cdist-tutorial(7) `_ COPYING 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..38063332 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..a09db845 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/speeches/2014-06-10_openclouddays.odp b/docs/speeches/2014-06-10_openclouddays.odp new file mode 100644 index 00000000..e85451c8 Binary files /dev/null and b/docs/speeches/2014-06-10_openclouddays.odp differ diff --git a/docs/speeches/2014-06-10_openclouddays_teaser.odp b/docs/speeches/2014-06-10_openclouddays_teaser.odp new file mode 100644 index 00000000..16ec8e95 Binary files /dev/null and b/docs/speeches/2014-06-10_openclouddays_teaser.odp differ diff --git a/docs/speeches/2014-06-10_openclouddays_teaser.pdf b/docs/speeches/2014-06-10_openclouddays_teaser.pdf new file mode 100644 index 00000000..c5a052b8 Binary files /dev/null and b/docs/speeches/2014-06-10_openclouddays_teaser.pdf differ diff --git a/docs/speeches/2014-06-19_ucms14_cdi.st.odp b/docs/speeches/2014-06-19_ucms14_cdi.st.odp new file mode 100644 index 00000000..9338abe4 Binary files /dev/null and b/docs/speeches/2014-06-19_ucms14_cdi.st.odp differ diff --git a/docs/speeches/2014-06-19_ucms14_cdist_cinv_bof.odp b/docs/speeches/2014-06-19_ucms14_cdist_cinv_bof.odp new file mode 100644 index 00000000..21f59ee8 Binary files /dev/null and b/docs/speeches/2014-06-19_ucms14_cdist_cinv_bof.odp differ diff --git a/docs/speeches/2014-11-07_sfs_linux_erfa_cdist4.odp b/docs/speeches/2014-11-07_sfs_linux_erfa_cdist4.odp new file mode 100644 index 00000000..29ada1b0 Binary files /dev/null and b/docs/speeches/2014-11-07_sfs_linux_erfa_cdist4.odp differ diff --git a/docs/speeches/2014-11-07_sfs_linux_erfa_cdist4.pdf b/docs/speeches/2014-11-07_sfs_linux_erfa_cdist4.pdf new file mode 100644 index 00000000..718d3997 Binary files /dev/null and b/docs/speeches/2014-11-07_sfs_linux_erfa_cdist4.pdf differ diff --git a/docs/speeches/2014-11-07_sfs_linux_erfa_cdist_web_prototype.odp b/docs/speeches/2014-11-07_sfs_linux_erfa_cdist_web_prototype.odp new file mode 100644 index 00000000..47c858d4 Binary files /dev/null and b/docs/speeches/2014-11-07_sfs_linux_erfa_cdist_web_prototype.odp differ diff --git a/docs/speeches/2014-11-07_sfs_linux_erfa_cdist_web_prototype.pdf b/docs/speeches/2014-11-07_sfs_linux_erfa_cdist_web_prototype.pdf new file mode 100644 index 00000000..ae0a3bef Binary files /dev/null and b/docs/speeches/2014-11-07_sfs_linux_erfa_cdist_web_prototype.pdf differ diff --git a/docs/web/cdist/install.mdwn b/docs/web/cdist/install.mdwn index c81354f0..ce6ca877 100644 --- a/docs/web/cdist/install.mdwn +++ b/docs/web/cdist/install.mdwn @@ -137,7 +137,7 @@ immediately. To install cdist, execute the following commands: - git clone git://git.schottelius.org/cdist + git clone https://github.com/telmich/cdist.git cd cdist export PATH=$PATH:$(pwd -P)/bin diff --git a/other/archived_types/.README.unmaintained b/other/archived_types/.README.unmaintained index e9795911..513f3b78 100644 --- a/other/archived_types/.README.unmaintained +++ b/other/archived_types/.README.unmaintained @@ -1 +1 @@ -This type is not maintained by anymore and has thus been removed from cdist. +This type is not maintained anymore and has thus been removed from cdist. diff --git a/other/archived_types/__autofs/man.text b/other/archived_types/__autofs/man.rst similarity index 65% rename from other/archived_types/__autofs/man.text rename to other/archived_types/__autofs/man.rst index 9b343309..4f02720e 100644 --- a/other/archived_types/__autofs/man.text +++ b/other/archived_types/__autofs/man.rst @@ -1,13 +1,10 @@ cdist-type__autofs(7) ===================== +Install and start autofs + Steven Armstrong -NAME ----- -cdist-type__autofs - install and start autofs - - DESCRIPTION ----------- This space intentionally left blank. @@ -26,14 +23,14 @@ None. EXAMPLES -------- --------------------------------------------------------------------------------- -__autofs --------------------------------------------------------------------------------- +.. code-block:: sh + + __autofs SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/other/archived_types/__autofs/manifest b/other/archived_types/__autofs/manifest index 4a726c0a..ed6e87ee 100755 --- a/other/archived_types/__autofs/manifest +++ b/other/archived_types/__autofs/manifest @@ -23,7 +23,7 @@ os=$(cat "$__global/explorer/os") case "$os" in - ubuntu|debian|archlinux) + ubuntu|debian|archlinux|devuan) __package autofs --state present __start_on_boot autofs --state present ;; diff --git a/other/archived_types/__autofs_map/man.text b/other/archived_types/__autofs_map/man.rst similarity index 62% rename from other/archived_types/__autofs_map/man.text rename to other/archived_types/__autofs_map/man.rst index 50ce2fa8..dfb79a27 100644 --- a/other/archived_types/__autofs_map/man.text +++ b/other/archived_types/__autofs_map/man.rst @@ -1,13 +1,10 @@ cdist-type__autofs_map(7) ========================= +Manage autofs maps + Steven Armstrong -NAME ----- -cdist-type__autofs_map - Manage autofs maps - - DESCRIPTION ----------- This cdist type allows you to define maps for autofs. @@ -20,48 +17,50 @@ The object_id is used as the mount-point as described in auto.master(5). REQUIRED PARAMETERS ------------------- -map:: +map Name of the map to use. See auto.master(5). OPTIONAL PARAMETERS ------------------- -type:: +type Type of map used for this mount point. Defaults to 'file'. See map-type in auto.master(5) for possible values. -options:: + +options See auto.master(5). -comment:: + +comment A comment describing this map. Is added to the generated entry in auto.master. BOOLEAN PARAMETERS ------------------ -noreload:: +noreload don't reload autofs after the entry has been changed EXAMPLES -------- --------------------------------------------------------------------------------- -# Add auto mounter at /net and reload -__autofs_map /net --map /etc/auto.net --type program +.. code-block:: sh -# Add auto mounter at /pub and don't reload -__autofs_map /pub \ - --map /etc/auto.pub \ - --type file \ - --options "nosuid,rw,bg,hard,intr --ghost" \ - --noreload --------------------------------------------------------------------------------- + # Add auto mounter at /net and reload + __autofs_map /net --map /etc/auto.net --type program + + # Add auto mounter at /pub and don't reload + __autofs_map /pub \ + --map /etc/auto.pub \ + --type file \ + --options "nosuid,rw,bg,hard,intr --ghost" \ + --noreload SEE ALSO -------- -- cdist-type(7) -- cdist-type__autofs_reload(7) +- `cdist-type(7) `_ +- `cdist-type__autofs_reload(7) `_ COPYING diff --git a/other/archived_types/__autofs_reload/gencode-remote b/other/archived_types/__autofs_reload/gencode-remote index 883602e2..913d3f24 100755 --- a/other/archived_types/__autofs_reload/gencode-remote +++ b/other/archived_types/__autofs_reload/gencode-remote @@ -28,7 +28,7 @@ not_supported() { } case "$os" in - ubuntu|debian|archlinux) + ubuntu|debian|archlinux|devuan) echo "pkill -HUP automount" ;; *) diff --git a/other/archived_types/__autofs_reload/man.text b/other/archived_types/__autofs_reload/man.rst similarity index 63% rename from other/archived_types/__autofs_reload/man.text rename to other/archived_types/__autofs_reload/man.rst index d2085a98..101e9965 100644 --- a/other/archived_types/__autofs_reload/man.text +++ b/other/archived_types/__autofs_reload/man.rst @@ -1,13 +1,10 @@ cdist-type__autofs_reload(7) ============================ +Tell automounter to reload config file + Steven Armstrong -NAME ----- -cdist-type__autofs_reload - tell automounter to reload config file - - DESCRIPTION ----------- This space intentionally left blank. @@ -26,14 +23,14 @@ None. EXAMPLES -------- --------------------------------------------------------------------------------- -__autofs_reload --------------------------------------------------------------------------------- +.. code-block:: sh + + __autofs_reload SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/other/types_submitted_for_inclusion/__init_script/man.text b/other/types_submitted_for_inclusion/__init_script/man.rst similarity index 63% rename from other/types_submitted_for_inclusion/__init_script/man.text rename to other/types_submitted_for_inclusion/__init_script/man.rst index c33ff7b7..9d9220d4 100644 --- a/other/types_submitted_for_inclusion/__init_script/man.text +++ b/other/types_submitted_for_inclusion/__init_script/man.rst @@ -1,13 +1,10 @@ cdist-type__init_script(7) ========================== +Use the init scripts + Daniel Roth -NAME ----- -cdist-type__init_script - Use the init scripts - - DESCRIPTION ----------- This type can be used to control your init scripts. @@ -15,34 +12,35 @@ This type can be used to control your init scripts. REQUIRED PARAMETERS ------------------- -mode:: +mode Specifies what shall be done with the init script (usually one of 'start'|'stop'|'restart'|'reload' or 'force-reload') OPTIONAL PARAMETERS ------------------- -script:: +script If supplied, use this as the init-script. Otherwise the object_id is used. -base_dir:: +base_dir If supplied, this type uses this directory instead of '/etc/init.d'. The parameter will not need an ending slash. + EXAMPLES -------- --------------------------------------------------------------------------------- -# Reloads the configuration for lighttpd -__init_script lighttpd --mode force-reload +.. code-block:: sh -# Reloads the configuration for lighttpd -__init_script lighty --script lighttpd --mode force-reload --------------------------------------------------------------------------------- + # Reloads the configuration for lighttpd + __init_script lighttpd --mode force-reload + + # Reloads the configuration for lighttpd + __init_script lighty --script lighttpd --mode force-reload SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/other/types_submitted_for_inclusion/__mysql_server/man.text b/other/types_submitted_for_inclusion/__mysql_server/man.rst similarity index 58% rename from other/types_submitted_for_inclusion/__mysql_server/man.text rename to other/types_submitted_for_inclusion/__mysql_server/man.rst index f8573051..c561117c 100644 --- a/other/types_submitted_for_inclusion/__mysql_server/man.text +++ b/other/types_submitted_for_inclusion/__mysql_server/man.rst @@ -1,13 +1,10 @@ cdist-type__mysql_server(7) =========================== +Manage a MySQL server + Benedikt Koeppel -NAME ----- -cdist-type__mysql_server - Manage a MySQL server - - DESCRIPTION ----------- This cdist type allows you to install a MySQL database server. The @@ -18,13 +15,13 @@ with MySQL. REQUIRED PARAMETERS ------------------- -password:: +password The root password to set. OPTIONAL PARAMETERS ------------------- -no_my_cnf:: +no_my_cnf The /root/.my.cnf file is used to temporary store the root password when doing the mysql_secure_installation. If you want to have your own .my.cnf file, then specify --no_my_cnf "true". @@ -34,24 +31,24 @@ no_my_cnf:: EXAMPLES -------- --------------------------------------------------------------------------------- -# to install a MySQL server -__mysql_server +.. code-block:: sh -# to install a MySQL server, remove remote access, remove test databases -# similar to mysql_secure_installation, specify the root password -__mysql_server --password "Uu9jooKe" -# this will also write a /root/.my.cnf file + # to install a MySQL server + __mysql_server -# if you don't want cdist to write a /root/.my.cnf file permanently, specify -# the --no_my_cnf option -__mysql_server --password "Uu9jooKe" --no_my_cnf --------------------------------------------------------------------------------- + # to install a MySQL server, remove remote access, remove test databases + # similar to mysql_secure_installation, specify the root password + __mysql_server --password "Uu9jooKe" + # this will also write a /root/.my.cnf file + + # if you don't want cdist to write a /root/.my.cnf file permanently, specify + # the --no_my_cnf option + __mysql_server --password "Uu9jooKe" --no_my_cnf SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/other/types_submitted_for_inclusion/__nfs_client/man.text b/other/types_submitted_for_inclusion/__nfs_client/man.rst similarity index 67% rename from other/types_submitted_for_inclusion/__nfs_client/man.text rename to other/types_submitted_for_inclusion/__nfs_client/man.rst index 3f0808a7..3c582958 100644 --- a/other/types_submitted_for_inclusion/__nfs_client/man.text +++ b/other/types_submitted_for_inclusion/__nfs_client/man.rst @@ -1,13 +1,10 @@ cdist-type__nfs_client(7) ========================= +nfs client + Steven Armstrong -NAME ----- -cdist-type__nfs_client - nfs client - - DESCRIPTION ----------- Install, start, do whatever is necessary to have a working nfs client. @@ -26,14 +23,14 @@ None. EXAMPLES -------- --------------------------------------------------------------------------------- -__nfs_client --------------------------------------------------------------------------------- +.. code-block:: sh + + __nfs_client SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/other/types_submitted_for_inclusion/__nfs_export/man.text b/other/types_submitted_for_inclusion/__nfs_export/man.rst similarity index 67% rename from other/types_submitted_for_inclusion/__nfs_export/man.text rename to other/types_submitted_for_inclusion/__nfs_export/man.rst index 41ff64e8..4dd164ec 100644 --- a/other/types_submitted_for_inclusion/__nfs_export/man.text +++ b/other/types_submitted_for_inclusion/__nfs_export/man.rst @@ -1,13 +1,10 @@ cdist-type__nfs_export(7) ========================= +Manage nfs exports + Steven Armstrong -NAME ----- -cdist-type__nfs_export - manage nfs exports - - DESCRIPTION ----------- This cdist type allows you to manage entries in /etc/exports.d. @@ -17,35 +14,35 @@ For older distributions (currently ubuntu lucid) that don't support REQUIRED PARAMETERS ------------------- -client:: +client space delimited list of client ip/networks for use in /etc/exports. See exports(5) OPTIONAL PARAMETERS ------------------- -options:: +options export options for use in /etc/exports. See exports(5) -export:: +export the directory to export. Defaults to object_id -state:: +state Either present or absent. Defaults to present. EXAMPLES -------- --------------------------------------------------------------------------------- -__nfs_export /local/chroot/lucid-amd64 \ - --client "192.168.0.1/24 10.0.0.1/16" \ - --options "ro,async,no_all_squash,no_root_squash,subtree_check" --------------------------------------------------------------------------------- +.. code-block:: sh + + __nfs_export /local/chroot/lucid-amd64 \ + --client "192.168.0.1/24 10.0.0.1/16" \ + --options "ro,async,no_all_squash,no_root_squash,subtree_check" SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ - exports(5) diff --git a/other/types_submitted_for_inclusion/__nfs_server/man.text b/other/types_submitted_for_inclusion/__nfs_server/man.rst similarity index 67% rename from other/types_submitted_for_inclusion/__nfs_server/man.text rename to other/types_submitted_for_inclusion/__nfs_server/man.rst index 41fc1d75..1f9aad76 100644 --- a/other/types_submitted_for_inclusion/__nfs_server/man.text +++ b/other/types_submitted_for_inclusion/__nfs_server/man.rst @@ -1,13 +1,10 @@ cdist-type__nfs_server(7) ========================= +nfs server + Steven Armstrong -NAME ----- -cdist-type__nfs_server - nfs server - - DESCRIPTION ----------- Install, start, do whatever is necessary to have a working nfs server. @@ -26,14 +23,14 @@ None. EXAMPLES -------- --------------------------------------------------------------------------------- -__nfs_server --------------------------------------------------------------------------------- +.. code-block:: sh + + __nfs_server SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/other/types_submitted_for_inclusion/__rsyncer/man.text b/other/types_submitted_for_inclusion/__rsyncer/man.rst similarity index 72% rename from other/types_submitted_for_inclusion/__rsyncer/man.text rename to other/types_submitted_for_inclusion/__rsyncer/man.rst index 6fab9fd3..a09bfea5 100644 --- a/other/types_submitted_for_inclusion/__rsyncer/man.text +++ b/other/types_submitted_for_inclusion/__rsyncer/man.rst @@ -1,13 +1,10 @@ cdist-type__rsyncer(7) ====================== +Use rsync to copy files. + Daniel Maher -NAME ----- -cdist-type__rsyncer - Use rsync to copy files. - - DESCRIPTION ----------- This type is used to trigger rsync to copy files from the machine running cdist @@ -19,41 +16,41 @@ from the destination which are not present on the source. REQUIRED PARAMETERS ------------------- -source:: +source The full path of the source from which to copy. This is passed directly to rsync. OPTIONAL PARAMETERS ------------------- -destination:: +destination The full path of the destination. This is passed directly to rsync. Default: object_id -delete:: +delete If true, remove files from destination which are not in source. This is effectively the --delete argument of rsync. Default: false -rsyncbin:: +rsyncbin Specify the full path to the rsync binary. Default: `which rsync` EXAMPLES -------- --------------------------------------------------------------------------------- -# Basic example -__rsyncer '/home/foo' --source '/opt/dist/foo' +.. code-block:: sh -# Fancier example -__rsyncer FOO --source '/opt/dist/foo' --destination '/home/foo/' --delete true --------------------------------------------------------------------------------- + # Basic example + __rsyncer '/home/foo' --source '/opt/dist/foo' + + # Fancier example + __rsyncer FOO --source '/opt/dist/foo' --destination '/home/foo/' --delete true SEE ALSO -------- -- cdist-type(7) +- `cdist-type(7) `_ COPYING diff --git a/other/types_submitted_for_inclusion/__run_command/man.rst b/other/types_submitted_for_inclusion/__run_command/man.rst new file mode 100644 index 00000000..f4426043 --- /dev/null +++ b/other/types_submitted_for_inclusion/__run_command/man.rst @@ -0,0 +1,66 @@ +cdist-type__run_command(7) +========================== +Run a command + +Benedikt Koeppel + + +DESCRIPTION +----------- +This cdist type allows you to run a specific command once at installation time. + + +REQUIRED PARAMETERS +------------------- + + +OPTIONAL PARAMETERS +------------------- +command + Command (with arguments) to run. + + If no command is give, then the object_id is executed. + + + +EXAMPLES +-------- + +.. code-block:: sh + + # Run a command + __run_command "/etc/init.d/mysql restart" + # runs `/etc/init.d/mysql restart` (the "object_id") + + # Run the same command: + __run_command restart-mysql --command "/etc/init.d/mysql restart" + # runs `/etc/init.d/mysql restart` (the --command argument) + # additionally, it can easily be referenced (for example in a require="..." + #as __run_command/restart-mysql + + # Run a script: + __run_command install-pear --command "$(cat <<-EOF + /usr/bin/pear install --force Auth + /usr/bin/pear install --force HTML_Template_IT-1.2.1 + /usr/bin/pear install --force MDB2 + /usr/bin/pear install --force MDB2#mysql + /usr/bin/pear config-set preferred_state beta; + /usr/bin/pear install --force --alldeps Spreadsheet_Excel_Writer; + /usr/bin/pear config-set preferred_state stable + /usr/bin/pear install --force HTTP_Request + /usr/bin/pear install --force Mail + /usr/bin/pear install --force Auth_HTTP + /usr/bin/pear install --force XML_RPC + EOF + )" + + +SEE ALSO +-------- +- `cdist-type(7) `_ + + +COPYING +------- +Copyright \(C) 2012 Benedikt Koeppel. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/other/types_submitted_for_inclusion/__run_command/man.text b/other/types_submitted_for_inclusion/__run_command/man.text deleted file mode 100644 index 5ea553c3..00000000 --- a/other/types_submitted_for_inclusion/__run_command/man.text +++ /dev/null @@ -1,70 +0,0 @@ -cdist-type__run_command(7) -========================== -Benedikt Koeppel - - -NAME ----- -cdist-type__run_command - Run a command - - -DESCRIPTION ------------ -This cdist type allows you to run a specific command once at installation time. - - -REQUIRED PARAMETERS -------------------- - - -OPTIONAL PARAMETERS -------------------- -command:: - Command (with arguments) to run. - - If no command is give, then the object_id is executed. - - - -EXAMPLES --------- - --------------------------------------------------------------------------------- -# Run a command -__run_command "/etc/init.d/mysql restart" -# runs `/etc/init.d/mysql restart` (the "object_id") - -# Run the same command: -__run_command restart-mysql --command "/etc/init.d/mysql restart" -# runs `/etc/init.d/mysql restart` (the --command argument) -# additionally, it can easily be referenced (for example in a require="..." -#as __run_command/restart-mysql - -# Run a script: -__run_command install-pear --command "$(cat <<-EOF - /usr/bin/pear install --force Auth - /usr/bin/pear install --force HTML_Template_IT-1.2.1 - /usr/bin/pear install --force MDB2 - /usr/bin/pear install --force MDB2#mysql - /usr/bin/pear config-set preferred_state beta; - /usr/bin/pear install --force --alldeps Spreadsheet_Excel_Writer; - /usr/bin/pear config-set preferred_state stable - /usr/bin/pear install --force HTTP_Request - /usr/bin/pear install --force Mail - /usr/bin/pear install --force Auth_HTTP - /usr/bin/pear install --force XML_RPC -EOF -)" - --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) - - -COPYING -------- -Copyright \(C) 2012 Benedikt Koeppel. Free use of this software is -granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/scripts/cdist b/scripts/cdist index 39449666..6baa28f3 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- # # 2010-2013 Nico Schottelius (nico-cdist at schottelius.org) +# 2016 Darko Poljak (darko.poljak at gmail.com) # # This file is part of cdist. # @@ -20,6 +21,29 @@ # # +def inspect_ssh_mux_opts(control_path_dir="~/.ssh/"): + """Inspect whether or not ssh supports multiplexing options""" + import subprocess + import os + + control_path = os.path.join(control_path_dir, + "cdist.socket.master-%l-%r@%h:%p") + wanted_mux_opts = { + "ControlPath": control_path, + "ControlMaster": "auto", + "ControlPersist": "125", + } + mux_opts = " ".join([" -o {}={}".format(x, + wanted_mux_opts[x]) for x in wanted_mux_opts]) + try: + subprocess.check_output("ssh {}".format(mux_opts), + stderr=subprocess.STDOUT, shell=True) + except subprocess.CalledProcessError as e: + subproc_output = e.output.decode().lower() + if "bad configuration option" in subproc_output: + return "" + return mux_opts + def commandline(): """Parse command line""" import argparse @@ -27,6 +51,9 @@ def commandline(): import cdist.banner import cdist.config import cdist.shell + import tempfile + import shutil + import os # Construct parser others can reuse parser = {} @@ -40,12 +67,14 @@ def commandline(): action='store_true', default=False) # Main subcommand parser - parser['main'] = argparse.ArgumentParser(description='cdist ' + cdist.VERSION, + parser['main'] = argparse.ArgumentParser(description='cdist ' + + cdist.VERSION, parents=[parser['loglevel']]) parser['main'].add_argument('-V', '--version', help='Show version', action='version', version='%(prog)s ' + cdist.VERSION) - parser['sub'] = parser['main'].add_subparsers(title="Commands") + parser['sub'] = parser['main'].add_subparsers(title="Commands", + dest="command") # Banner parser['banner'] = parser['sub'].add_parser('banner', @@ -55,11 +84,17 @@ def commandline(): # Config parser['config'] = parser['sub'].add_parser('config', parents=[parser['loglevel']]) - parser['config'].add_argument('host', nargs='+', - help='one or more hosts to operate on') + parser['config'].add_argument('host', nargs='*', + help='host(s) to operate on') parser['config'].add_argument('-c', '--conf-dir', - help='Add configuration directory (can be repeated, last one wins)', - action='append') + help=('Add configuration directory (can be repeated, ' + 'last one wins)'), action='append') + parser['config'].add_argument('-f', '--file', + help=('Read additional hosts to operate on from specified file ' + 'or from stdin if \'-\' (each host on separate line). ' + 'If no host or host file is specified then, by default, ' + 'read hosts from stdin.'), + dest='hostfile', required=False) parser['config'].add_argument('-i', '--initial-manifest', help='Path to a cdist manifest or \'-\' to read from stdin.', dest='manifest', required=False) @@ -73,14 +108,18 @@ def commandline(): parser['config'].add_argument('-s', '--sequential', help='Operate on multiple hosts sequentially (default)', action='store_false', dest='parallel') + # remote-copy and remote-exec defaults are environment variables + # if set; if not then None - these will be futher handled after + # parsing to determine implementation default parser['config'].add_argument('--remote-copy', help='Command to use for remote copy (should behave like scp)', action='store', dest='remote_copy', - default=cdist.REMOTE_COPY) + default=os.environ.get('CDIST_REMOTE_COPY')) parser['config'].add_argument('--remote-exec', - help='Command to use for remote execution (should behave like ssh)', + help=('Command to use for remote execution ' + '(should behave like ssh)'), action='store', dest='remote_exec', - default=cdist.REMOTE_EXEC) + default=os.environ.get('CDIST_REMOTE_EXEC')) parser['config'].set_defaults(func=cdist.config.Config.commandline) # Shell @@ -101,6 +140,26 @@ def commandline(): logging.root.setLevel(logging.INFO) if args.debug: logging.root.setLevel(logging.DEBUG) + args_dict = vars(args) + # if command with remote_copy and remote_exec params + if 'remote_copy' in args_dict and 'remote_exec' in args_dict: + # if remote-exec and/or remote-copy args are None then user + # didn't specify command line options nor env vars: + # inspect multiplexing options for default cdist.REMOTE_COPY/EXEC + if args_dict['remote_copy'] is None or args_dict['remote_exec'] is None: + control_path_dir = tempfile.mkdtemp() + import atexit + atexit.register(lambda: shutil.rmtree(control_path_dir)) + mux_opts = inspect_ssh_mux_opts(control_path_dir) + if args_dict['remote_exec'] is None: + args.remote_exec = cdist.REMOTE_EXEC + mux_opts + if args_dict['remote_copy'] is None: + args.remote_copy = cdist.REMOTE_COPY + mux_opts + + if args.command == 'config': + if args.manifest == '-' and args.hostfile == '-': + print('cdist config: error: cannot read both, manifest and host file, from stdin') + sys.exit(1) log.debug(args) log.info("version %s" % cdist.VERSION)