From 2ed762cd72d426ff0d25cf21ac7ddb48312297e8 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Thu, 28 Jul 2016 14:48:32 +0200 Subject: [PATCH 1/7] new type __filesystem, first version --- .../type/__filesystem/explorer/blkdev_devname | 38 ++++++++ .../type/__filesystem/explorer/blkdev_fstype | 38 ++++++++ .../type/__filesystem/explorer/blkdev_label | 38 ++++++++ .../__filesystem/explorer/blkdev_mountpoint | 38 ++++++++ cdist/conf/type/__filesystem/gencode-remote | 96 +++++++++++++++++++ cdist/conf/type/__filesystem/man.rst | 79 +++++++++++++++ .../conf/type/__filesystem/parameter/boolean | 1 + .../type/__filesystem/parameter/default/label | 0 .../parameter/default/mkfsoptions | 0 .../conf/type/__filesystem/parameter/optional | 2 + .../conf/type/__filesystem/parameter/required | 2 + docs/changelog | 2 + 12 files changed, 334 insertions(+) create mode 100644 cdist/conf/type/__filesystem/explorer/blkdev_devname create mode 100644 cdist/conf/type/__filesystem/explorer/blkdev_fstype create mode 100644 cdist/conf/type/__filesystem/explorer/blkdev_label create mode 100644 cdist/conf/type/__filesystem/explorer/blkdev_mountpoint create mode 100644 cdist/conf/type/__filesystem/gencode-remote create mode 100644 cdist/conf/type/__filesystem/man.rst create mode 100644 cdist/conf/type/__filesystem/parameter/boolean create mode 100644 cdist/conf/type/__filesystem/parameter/default/label create mode 100644 cdist/conf/type/__filesystem/parameter/default/mkfsoptions create mode 100644 cdist/conf/type/__filesystem/parameter/optional create mode 100644 cdist/conf/type/__filesystem/parameter/required diff --git a/cdist/conf/type/__filesystem/explorer/blkdev_devname b/cdist/conf/type/__filesystem/explorer/blkdev_devname new file mode 100644 index 00000000..30c8409a --- /dev/null +++ b/cdist/conf/type/__filesystem/explorer/blkdev_devname @@ -0,0 +1,38 @@ +#!/bin/sh +# +# 2016 - 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 . +# + +os=$("$__explorer/os") + +blkdev="$(cat "$__object/parameter/blkdev")" + +case "$os" in + centos|fedora|redhat|suse|gentoo) + if [ ! -x "$(command -v lsblk)" ]; then + echo "lsblk is required for __filesystem type" >&2 + exit 1 + else + echo -n $(lsblk -n -o NAME "$blkdev" 2>/dev/null) + fi + ;; + *) + echo "__filesystem type lacks implementation for os: $os" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__filesystem/explorer/blkdev_fstype b/cdist/conf/type/__filesystem/explorer/blkdev_fstype new file mode 100644 index 00000000..3f92142f --- /dev/null +++ b/cdist/conf/type/__filesystem/explorer/blkdev_fstype @@ -0,0 +1,38 @@ +#!/bin/sh +# +# 2016 - 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 . +# + +os=$("$__explorer/os") + +blkdev="$(cat "$__object/parameter/blkdev")" + +case "$os" in + centos|fedora|redhat|suse|gentoo) + if [ ! -x "$(command -v lsblk)" ]; then + echo "lsblk is required for __filesystem type" >&2 + exit 1 + else + echo -n $(lsblk -n -o FSTYPE "$blkdev" 2>/dev/null) + fi + ;; + *) + echo "__filesystem type lacks implementation for os: $os" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__filesystem/explorer/blkdev_label b/cdist/conf/type/__filesystem/explorer/blkdev_label new file mode 100644 index 00000000..aa227cab --- /dev/null +++ b/cdist/conf/type/__filesystem/explorer/blkdev_label @@ -0,0 +1,38 @@ +#!/bin/sh +# +# 2016 - 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 . +# + +os=$("$__explorer/os") + +blkdev="$(cat "$__object/parameter/blkdev")" + +case "$os" in + centos|fedora|redhat|suse|gentoo) + if [ ! -x "$(command -v lsblk)" ]; then + echo "lsblk is required for __filesystem type" >&2 + exit 1 + else + echo -n $(lsblk -n -o LABEL "$blkdev" 2>/dev/null) + fi + ;; + *) + echo "__filesystem type lacks implementation for os: $os" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__filesystem/explorer/blkdev_mountpoint b/cdist/conf/type/__filesystem/explorer/blkdev_mountpoint new file mode 100644 index 00000000..1cef068c --- /dev/null +++ b/cdist/conf/type/__filesystem/explorer/blkdev_mountpoint @@ -0,0 +1,38 @@ +#!/bin/sh +# +# 2016 - 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 . +# + +os=$("$__explorer/os") + +blkdev="$(cat "$__object/parameter/blkdev")" + +case "$os" in + centos|fedora|redhat|suse|gentoo) + if [ ! -x "$(command -v lsblk)" ]; then + echo "lsblk is required for __filesystem type" >&2 + exit 1 + else + echo -n $(lsblk -n -o MOUNTPOINT "$blkdev" 2>/dev/null) + fi + ;; + *) + echo "__filesystem type lacks implementation for os: $os" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__filesystem/gencode-remote b/cdist/conf/type/__filesystem/gencode-remote new file mode 100644 index 00000000..9d134dcc --- /dev/null +++ b/cdist/conf/type/__filesystem/gencode-remote @@ -0,0 +1,96 @@ +#!/bin/sh +# +# 2016 - 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 . +# + + +fstype="$(cat "$__object/parameter/fstype")" +mydev="$(cat "$__object/parameter/blkdev")" + +label="$(cat "$__object/parameter/label")" +mkfsoptions="$(cat "$__object/parameter/mkfsoptions")" + + +if [ -f "$__object/parameter/force" ]; then + # create filesystem even an other filesystem is on disk or the label is not correct, use with caution ! + forcefs="true" +else + forcefs="false" +fi + + +blkdev_devname="$(cat "$__object/explorer/blkdev_devname")" +blkdev_fstype="$(cat "$__object/explorer/blkdev_fstype")" +blkdev_label="$(cat "$__object/explorer/blkdev_label")" +blkdev_mountpoint="$(cat "$__object/explorer/blkdev_mountpoint")" + +if [ -z "$blkdev_devname" ]; then + echo "Specified device $mydev not found on target system" >&2 + exit 1 +fi + +[ "$blkdev_label" = "$label" ] && [ "$blkdev_fstype" = "$fstype" ] && exit 0 + +if [ -n "$blkdev_mountpoint" ]; then + echo "Specified device $mydev is mounted on $blkdev_mountpoint, __filesystem does NOTHING with mountd devices" >&2 + exit 0 +fi + +if [ -n "$blkdev_fstype" ] && [ "$forcefs" != "true" ]; then + if [ "$blkdev_label" != "$label" ]; then + echo "Specified device $mydev has not the spezified label: $blkdev_label, but __filesystem does NOTHING in this case without the --force option" >&2 + exit 0 + fi + if [ "$blkdev_fstype" != "$fstype" ]; then + echo "Specified device $mydev has not the spezified filesystem: $blkdev_fstype, but __filesystem does NOTHING in this case without the --force option" >&2 + exit 0 + fi +fi + + +# ok, all conditions checked, we need to format the device, lets go +opts="$mkfsoptions" +if [ -n "$label" ]; then + opts="$opts -L '$label'" +fi + +case "$fstype" in + ext2|ext3|ext4) + if [ "$forcefs" = "true" ]; then + opts="$opts -F" + fi + echo "mkfs.$fstype $opts /dev/$blkdev_devname" + ;; + btrfs) + if [ "$forcefs" = "true" ]; then + opts="$opts --force" + fi + echo "mkfs.btrfs $opts /dev/$blkdev_devname" + ;; + xfs) + if [ "$forcefs" = "true" ]; then + opts="$opts -f" + fi + echo "mkfs.xfs $opts /dev/$blkdev_devname" + ;; + *) + echo "__filesystem type lacks implementation for filesystem: $fstype" >&2 + exit 1 + ;; +esac +echo "filesystem $fstype on $mydev : /dev/$blkdev_devname created" >> "$__messages_out" diff --git a/cdist/conf/type/__filesystem/man.rst b/cdist/conf/type/__filesystem/man.rst new file mode 100644 index 00000000..c4787d53 --- /dev/null +++ b/cdist/conf/type/__filesystem/man.rst @@ -0,0 +1,79 @@ +cdist-type__filesystem(7) +========================= + +NAME +---- +cdist-type__filesystem - Create Filesystems. + + +DESCRIPTION +----------- +This cdist type allows you to create filesystems on devices. + +If the device is mounted on target, it refuses to do someting. + +If the device has a filesystem other as the specified and/or + the label is not correct, it only make a new filesystem + if you specified --force option + + +REQUIRED PARAMETERS +------------------- +fstype + Filesystem type, for example 'ext3', 'btrfs' or 'xfs' + +blkdev + Blockdevice for filesystem, + On linux, it can be any by lsblk accepted device notation + + for example + /dev/sdx + or /dev/disk/by-xxxx/xxx + or /dev/mapper/xxxx + + +OPTIONAL PARAMETERS +------------------- +label + Label which sould apply on the filesystem + +mkfsoptions + Additional options which are inserted to the mkfs.xxx call. + + +BOOLEAN PARAMETERS +------------------ +force + Normaly, this type does nothing if a filesystem is found + on the target device. If you specify force, its formated + if the filesystem type or label differs from parameters + Warning: This option can easy lead into data loss ! + +MESSAGES +-------- +filesystem on : created + Filesytem was created on + + +EXAMPLES +-------- + +.. code-block:: sh + + # Ensures that device /dev/sdb is formated with xfs + __filesystem dev_sdb --fstype xfs --blkdev /dev/sdb --label Testdisk1 + # The same thing with btrfs and disk spezified by pci path to disk 1:0 on vmware + __filesystem dev_sdb --fstype btrfs --blkdev /dev/disk/by-path/pci-0000:0b:00.0-scsi-0:0:0:0 --label Testdisk2 + # Make sure that a multipath san device has a filesystem ... + __filesystem dev_sdb --fstype xfs --blkdev /dev/mapper/360060e80432f560050202f22000023ff --label Testdisk3 + + +AUTHORS +------- +Daniel Heule + + +COPYING +------- +Copyright \(C) 2016 Daniel Heule. Free use of this software is +granted under the terms of the GNU General Public License version 3 or any later version (GPLv3+). diff --git a/cdist/conf/type/__filesystem/parameter/boolean b/cdist/conf/type/__filesystem/parameter/boolean new file mode 100644 index 00000000..14b33226 --- /dev/null +++ b/cdist/conf/type/__filesystem/parameter/boolean @@ -0,0 +1 @@ +force diff --git a/cdist/conf/type/__filesystem/parameter/default/label b/cdist/conf/type/__filesystem/parameter/default/label new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__filesystem/parameter/default/mkfsoptions b/cdist/conf/type/__filesystem/parameter/default/mkfsoptions new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__filesystem/parameter/optional b/cdist/conf/type/__filesystem/parameter/optional new file mode 100644 index 00000000..0f63435f --- /dev/null +++ b/cdist/conf/type/__filesystem/parameter/optional @@ -0,0 +1,2 @@ +label +mkfsoptions diff --git a/cdist/conf/type/__filesystem/parameter/required b/cdist/conf/type/__filesystem/parameter/required new file mode 100644 index 00000000..33a66684 --- /dev/null +++ b/cdist/conf/type/__filesystem/parameter/required @@ -0,0 +1,2 @@ +fstype +blkdev diff --git a/docs/changelog b/docs/changelog index f73ba776..ba8ee201 100644 --- a/docs/changelog +++ b/docs/changelog @@ -1,5 +1,7 @@ Changelog --------- +next: + * New type __filesystem: manage filesystems on devices ( Daniel Heule ) 4.2.2: 2016-07-26 * Core: Fix ssh ControlPath socket file error (Darko Poljak) From 36c20230b89e78780ae3ff6ca9dae52e3799f212 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Fri, 29 Jul 2016 15:27:13 +0200 Subject: [PATCH 2/7] optimize the usage of explorers for __filesystem --- .../type/__filesystem/explorer/blkdev_fstype | 38 ------------------- .../type/__filesystem/explorer/blkdev_label | 38 ------------------- .../__filesystem/explorer/blkdev_mountpoint | 38 ------------------- .../explorer/{blkdev_devname => lsblk} | 3 +- cdist/conf/type/__filesystem/gencode-remote | 9 +++-- 5 files changed, 7 insertions(+), 119 deletions(-) delete mode 100644 cdist/conf/type/__filesystem/explorer/blkdev_fstype delete mode 100644 cdist/conf/type/__filesystem/explorer/blkdev_label delete mode 100644 cdist/conf/type/__filesystem/explorer/blkdev_mountpoint rename cdist/conf/type/__filesystem/explorer/{blkdev_devname => lsblk} (86%) diff --git a/cdist/conf/type/__filesystem/explorer/blkdev_fstype b/cdist/conf/type/__filesystem/explorer/blkdev_fstype deleted file mode 100644 index 3f92142f..00000000 --- a/cdist/conf/type/__filesystem/explorer/blkdev_fstype +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -# -# 2016 - 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 . -# - -os=$("$__explorer/os") - -blkdev="$(cat "$__object/parameter/blkdev")" - -case "$os" in - centos|fedora|redhat|suse|gentoo) - if [ ! -x "$(command -v lsblk)" ]; then - echo "lsblk is required for __filesystem type" >&2 - exit 1 - else - echo -n $(lsblk -n -o FSTYPE "$blkdev" 2>/dev/null) - fi - ;; - *) - echo "__filesystem type lacks implementation for os: $os" >&2 - exit 1 - ;; -esac diff --git a/cdist/conf/type/__filesystem/explorer/blkdev_label b/cdist/conf/type/__filesystem/explorer/blkdev_label deleted file mode 100644 index aa227cab..00000000 --- a/cdist/conf/type/__filesystem/explorer/blkdev_label +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -# -# 2016 - 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 . -# - -os=$("$__explorer/os") - -blkdev="$(cat "$__object/parameter/blkdev")" - -case "$os" in - centos|fedora|redhat|suse|gentoo) - if [ ! -x "$(command -v lsblk)" ]; then - echo "lsblk is required for __filesystem type" >&2 - exit 1 - else - echo -n $(lsblk -n -o LABEL "$blkdev" 2>/dev/null) - fi - ;; - *) - echo "__filesystem type lacks implementation for os: $os" >&2 - exit 1 - ;; -esac diff --git a/cdist/conf/type/__filesystem/explorer/blkdev_mountpoint b/cdist/conf/type/__filesystem/explorer/blkdev_mountpoint deleted file mode 100644 index 1cef068c..00000000 --- a/cdist/conf/type/__filesystem/explorer/blkdev_mountpoint +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -# -# 2016 - 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 . -# - -os=$("$__explorer/os") - -blkdev="$(cat "$__object/parameter/blkdev")" - -case "$os" in - centos|fedora|redhat|suse|gentoo) - if [ ! -x "$(command -v lsblk)" ]; then - echo "lsblk is required for __filesystem type" >&2 - exit 1 - else - echo -n $(lsblk -n -o MOUNTPOINT "$blkdev" 2>/dev/null) - fi - ;; - *) - echo "__filesystem type lacks implementation for os: $os" >&2 - exit 1 - ;; -esac diff --git a/cdist/conf/type/__filesystem/explorer/blkdev_devname b/cdist/conf/type/__filesystem/explorer/lsblk similarity index 86% rename from cdist/conf/type/__filesystem/explorer/blkdev_devname rename to cdist/conf/type/__filesystem/explorer/lsblk index 30c8409a..87f95e90 100644 --- a/cdist/conf/type/__filesystem/explorer/blkdev_devname +++ b/cdist/conf/type/__filesystem/explorer/lsblk @@ -28,7 +28,8 @@ case "$os" in echo "lsblk is required for __filesystem type" >&2 exit 1 else - echo -n $(lsblk -n -o NAME "$blkdev" 2>/dev/null) + #echo -n $(lsblk -nd -P -o NAME,FSTYPE,LABEL,MOUNTPOINT "$blkdev" 2>/dev/null) + lsblk -nd -P -o NAME,FSTYPE,LABEL,MOUNTPOINT "$blkdev" 2>/dev/null fi ;; *) diff --git a/cdist/conf/type/__filesystem/gencode-remote b/cdist/conf/type/__filesystem/gencode-remote index 9d134dcc..feb7098d 100644 --- a/cdist/conf/type/__filesystem/gencode-remote +++ b/cdist/conf/type/__filesystem/gencode-remote @@ -34,10 +34,11 @@ else fi -blkdev_devname="$(cat "$__object/explorer/blkdev_devname")" -blkdev_fstype="$(cat "$__object/explorer/blkdev_fstype")" -blkdev_label="$(cat "$__object/explorer/blkdev_label")" -blkdev_mountpoint="$(cat "$__object/explorer/blkdev_mountpoint")" + +blkdev_devname="$(grep -P -o2 'NAME="\K[^"]*' "$__object/explorer/lsblk")" +blkdev_fstype="$(grep -P -o2 'FSTYPE="\K[^"]*' "$__object/explorer/lsblk")" +blkdev_label="$(grep -P -o2 'LABEL="\K[^"]*' "$__object/explorer/lsblk")" +blkdev_mountpoint="$(grep -P -o2 'MOUNTPOINT="\K[^"]*' "$__object/explorer/lsblk")" if [ -z "$blkdev_devname" ]; then echo "Specified device $mydev not found on target system" >&2 From a1ff7555768c74288475651a6e1ae51a17c3221b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 31 Jul 2016 23:50:37 +0200 Subject: [PATCH 3/7] Add type __sysctl - Migrated asciidoc to rst - Changed license to GPLv3+ --- cdist/conf/type/__sysctl/explorer/value | 22 ++++++++++++ cdist/conf/type/__sysctl/gencode-remote | 30 ++++++++++++++++ cdist/conf/type/__sysctl/man.rst | 38 ++++++++++++++++++++ cdist/conf/type/__sysctl/manifest | 39 +++++++++++++++++++++ cdist/conf/type/__sysctl/parameter/required | 1 + 5 files changed, 130 insertions(+) create mode 100755 cdist/conf/type/__sysctl/explorer/value create mode 100755 cdist/conf/type/__sysctl/gencode-remote create mode 100644 cdist/conf/type/__sysctl/man.rst create mode 100755 cdist/conf/type/__sysctl/manifest create mode 100644 cdist/conf/type/__sysctl/parameter/required diff --git a/cdist/conf/type/__sysctl/explorer/value b/cdist/conf/type/__sysctl/explorer/value new file mode 100755 index 00000000..fc85b3d8 --- /dev/null +++ b/cdist/conf/type/__sysctl/explorer/value @@ -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 . +# + +# get the current runtime value +sysctl -n "$__object_id" || true diff --git a/cdist/conf/type/__sysctl/gencode-remote b/cdist/conf/type/__sysctl/gencode-remote new file mode 100755 index 00000000..0f3b0b40 --- /dev/null +++ b/cdist/conf/type/__sysctl/gencode-remote @@ -0,0 +1,30 @@ +#!/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 . +# + +value_should="$(cat "$__object/parameter/value")" +value_is="$(cat "$__object/explorer/value")" + +if [ "$value_should" = "$value_is" ]; then + # Nothing to do + exit 0 +fi + +# set the current runtime value +printf 'sysctl -w %s="%s"\n' "$__object_id" "$value_should" diff --git a/cdist/conf/type/__sysctl/man.rst b/cdist/conf/type/__sysctl/man.rst new file mode 100644 index 00000000..e4d5c504 --- /dev/null +++ b/cdist/conf/type/__sysctl/man.rst @@ -0,0 +1,38 @@ +cdist-type__sysctl(7) +===================== + +NAME +---- +cdist-type__sysctl - manage sysctl settings + + +DESCRIPTION +----------- +Manages permanent as well as runtime sysctl settings. +Permament settings are set by managing entries in /etc/sysctl.conf. +Runtime settings are set by directly calling the sysctl executable. + + +REQUIRED PARAMETERS +------------------- +value:: + The value to set for the given key (object_id) + + +EXAMPLES +-------- + +.. code-block:: sh + + __sysctl net.ipv4.ip_forward --value 1 + + +AUTHORS +------- +Steven Armstrong + + +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/__sysctl/manifest b/cdist/conf/type/__sysctl/manifest new file mode 100755 index 00000000..dd317806 --- /dev/null +++ b/cdist/conf/type/__sysctl/manifest @@ -0,0 +1,39 @@ +#!/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") + +case "$os" in + redhat|centos|ubuntu|debian|archlinux) + : + ;; + *) + 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 + +__key_value "$__object_name" \ + --key "$__object_id" \ + --file /etc/sysctl.conf \ + --value "$(cat "$__object/parameter/value")" \ + --delimiter '=' diff --git a/cdist/conf/type/__sysctl/parameter/required b/cdist/conf/type/__sysctl/parameter/required new file mode 100644 index 00000000..6d4e1507 --- /dev/null +++ b/cdist/conf/type/__sysctl/parameter/required @@ -0,0 +1 @@ +value From ad5ceac5637d876d7420021f4c133ddc6828969a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 31 Jul 2016 23:54:13 +0200 Subject: [PATCH 4/7] Update changelog for new type __sysctl --- docs/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog b/docs/changelog index 47e6237c..755a5a44 100644 --- a/docs/changelog +++ b/docs/changelog @@ -1,8 +1,8 @@ Changelog --------- -next: * New type: __locale_system (Steven Armstrong, Carlos Ortigoza, Nico Schottelius) + * New type: __sysctl (Steven Armstrong) 4.2.2: 2016-07-26 * Core: Fix ssh ControlPath socket file error (Darko Poljak) From 6479ffc4990aaa404d53976d635a9d4e54670e0c Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 1 Aug 2016 00:04:02 +0200 Subject: [PATCH 5/7] Really fix the GPLv3+ text --- cdist/conf/type/__sysctl/man.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__sysctl/man.rst b/cdist/conf/type/__sysctl/man.rst index e4d5c504..d5c6495c 100644 --- a/cdist/conf/type/__sysctl/man.rst +++ b/cdist/conf/type/__sysctl/man.rst @@ -35,4 +35,5 @@ Steven Armstrong 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+). +granted under the terms of the GNU General Public License version 3 or +later (GPLv3+). From 13b2443d6b7d4e181fc6dac4b112dd43292ead4d Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Tue, 2 Aug 2016 10:07:27 +0200 Subject: [PATCH 6/7] last cleanups --- cdist/conf/type/__filesystem/explorer/lsblk | 2 +- cdist/conf/type/__filesystem/gencode-remote | 10 +++++----- cdist/conf/type/__filesystem/man.rst | 10 +++++----- cdist/conf/type/__filesystem/parameter/required | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cdist/conf/type/__filesystem/explorer/lsblk b/cdist/conf/type/__filesystem/explorer/lsblk index 87f95e90..a0a87a9d 100644 --- a/cdist/conf/type/__filesystem/explorer/lsblk +++ b/cdist/conf/type/__filesystem/explorer/lsblk @@ -20,7 +20,7 @@ os=$("$__explorer/os") -blkdev="$(cat "$__object/parameter/blkdev")" +blkdev="$(cat "$__object/parameter/device")" case "$os" in centos|fedora|redhat|suse|gentoo) diff --git a/cdist/conf/type/__filesystem/gencode-remote b/cdist/conf/type/__filesystem/gencode-remote index feb7098d..66c25ef0 100644 --- a/cdist/conf/type/__filesystem/gencode-remote +++ b/cdist/conf/type/__filesystem/gencode-remote @@ -20,7 +20,7 @@ fstype="$(cat "$__object/parameter/fstype")" -mydev="$(cat "$__object/parameter/blkdev")" +mydev="$(cat "$__object/parameter/device")" label="$(cat "$__object/parameter/label")" mkfsoptions="$(cat "$__object/parameter/mkfsoptions")" @@ -35,10 +35,10 @@ fi -blkdev_devname="$(grep -P -o2 'NAME="\K[^"]*' "$__object/explorer/lsblk")" -blkdev_fstype="$(grep -P -o2 'FSTYPE="\K[^"]*' "$__object/explorer/lsblk")" -blkdev_label="$(grep -P -o2 'LABEL="\K[^"]*' "$__object/explorer/lsblk")" -blkdev_mountpoint="$(grep -P -o2 'MOUNTPOINT="\K[^"]*' "$__object/explorer/lsblk")" +blkdev_devname="$(grep -P -o 'NAME="\K[^"]*' "$__object/explorer/lsblk")" +blkdev_fstype="$(grep -P -o 'FSTYPE="\K[^"]*' "$__object/explorer/lsblk")" +blkdev_label="$(grep -P -o 'LABEL="\K[^"]*' "$__object/explorer/lsblk")" +blkdev_mountpoint="$(grep -P -o 'MOUNTPOINT="\K[^"]*' "$__object/explorer/lsblk")" if [ -z "$blkdev_devname" ]; then echo "Specified device $mydev not found on target system" >&2 diff --git a/cdist/conf/type/__filesystem/man.rst b/cdist/conf/type/__filesystem/man.rst index c4787d53..25c2eeda 100644 --- a/cdist/conf/type/__filesystem/man.rst +++ b/cdist/conf/type/__filesystem/man.rst @@ -22,7 +22,7 @@ REQUIRED PARAMETERS fstype Filesystem type, for example 'ext3', 'btrfs' or 'xfs' -blkdev +device Blockdevice for filesystem, On linux, it can be any by lsblk accepted device notation @@ -51,7 +51,7 @@ force MESSAGES -------- -filesystem on : created +filesystem on : created Filesytem was created on @@ -61,11 +61,11 @@ EXAMPLES .. code-block:: sh # Ensures that device /dev/sdb is formated with xfs - __filesystem dev_sdb --fstype xfs --blkdev /dev/sdb --label Testdisk1 + __filesystem dev_sdb --fstype xfs --device /dev/sdb --label Testdisk1 # The same thing with btrfs and disk spezified by pci path to disk 1:0 on vmware - __filesystem dev_sdb --fstype btrfs --blkdev /dev/disk/by-path/pci-0000:0b:00.0-scsi-0:0:0:0 --label Testdisk2 + __filesystem dev_sdb --fstype btrfs --device /dev/disk/by-path/pci-0000:0b:00.0-scsi-0:0:0:0 --label Testdisk2 # Make sure that a multipath san device has a filesystem ... - __filesystem dev_sdb --fstype xfs --blkdev /dev/mapper/360060e80432f560050202f22000023ff --label Testdisk3 + __filesystem dev_sdb --fstype xfs --device /dev/mapper/360060e80432f560050202f22000023ff --label Testdisk3 AUTHORS diff --git a/cdist/conf/type/__filesystem/parameter/required b/cdist/conf/type/__filesystem/parameter/required index 33a66684..480e3669 100644 --- a/cdist/conf/type/__filesystem/parameter/required +++ b/cdist/conf/type/__filesystem/parameter/required @@ -1,2 +1,2 @@ fstype -blkdev +device From 8747474fd577eaa6d3ebdb117da02a21915ecf7b Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Tue, 2 Aug 2016 11:06:17 +0200 Subject: [PATCH 7/7] device now defaults to object_id --- cdist/conf/type/__filesystem/explorer/lsblk | 6 +++++- cdist/conf/type/__filesystem/gencode-remote | 7 ++++++- cdist/conf/type/__filesystem/man.rst | 11 ++++++----- cdist/conf/type/__filesystem/parameter/optional | 1 + cdist/conf/type/__filesystem/parameter/required | 1 - 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/cdist/conf/type/__filesystem/explorer/lsblk b/cdist/conf/type/__filesystem/explorer/lsblk index a0a87a9d..9ae544ac 100644 --- a/cdist/conf/type/__filesystem/explorer/lsblk +++ b/cdist/conf/type/__filesystem/explorer/lsblk @@ -20,7 +20,11 @@ os=$("$__explorer/os") -blkdev="$(cat "$__object/parameter/device")" +if [ -f "$__object/parameter/device" ]; then + blkdev="$(cat "$__object/parameter/device")" +else + blkdev="$__object_id" +fi case "$os" in centos|fedora|redhat|suse|gentoo) diff --git a/cdist/conf/type/__filesystem/gencode-remote b/cdist/conf/type/__filesystem/gencode-remote index 66c25ef0..3ca1c498 100644 --- a/cdist/conf/type/__filesystem/gencode-remote +++ b/cdist/conf/type/__filesystem/gencode-remote @@ -20,7 +20,12 @@ fstype="$(cat "$__object/parameter/fstype")" -mydev="$(cat "$__object/parameter/device")" + +if [ -f "$__object/parameter/device" ]; then + mydev="$(cat "$__object/parameter/device")" +else + mydev="$__object_id" +fi label="$(cat "$__object/parameter/label")" mkfsoptions="$(cat "$__object/parameter/mkfsoptions")" diff --git a/cdist/conf/type/__filesystem/man.rst b/cdist/conf/type/__filesystem/man.rst index 25c2eeda..c69cc839 100644 --- a/cdist/conf/type/__filesystem/man.rst +++ b/cdist/conf/type/__filesystem/man.rst @@ -22,8 +22,12 @@ REQUIRED PARAMETERS fstype Filesystem type, for example 'ext3', 'btrfs' or 'xfs' + + +OPTIONAL PARAMETERS +------------------- device - Blockdevice for filesystem, + Blockdevice for filesystem, Defaults to object_id. On linux, it can be any by lsblk accepted device notation for example @@ -31,9 +35,6 @@ device or /dev/disk/by-xxxx/xxx or /dev/mapper/xxxx - -OPTIONAL PARAMETERS -------------------- label Label which sould apply on the filesystem @@ -61,7 +62,7 @@ EXAMPLES .. code-block:: sh # Ensures that device /dev/sdb is formated with xfs - __filesystem dev_sdb --fstype xfs --device /dev/sdb --label Testdisk1 + __filesystem /dev/sdb --fstype xfs --label Testdisk1 # The same thing with btrfs and disk spezified by pci path to disk 1:0 on vmware __filesystem dev_sdb --fstype btrfs --device /dev/disk/by-path/pci-0000:0b:00.0-scsi-0:0:0:0 --label Testdisk2 # Make sure that a multipath san device has a filesystem ... diff --git a/cdist/conf/type/__filesystem/parameter/optional b/cdist/conf/type/__filesystem/parameter/optional index 0f63435f..79dddc21 100644 --- a/cdist/conf/type/__filesystem/parameter/optional +++ b/cdist/conf/type/__filesystem/parameter/optional @@ -1,2 +1,3 @@ +device label mkfsoptions diff --git a/cdist/conf/type/__filesystem/parameter/required b/cdist/conf/type/__filesystem/parameter/required index 480e3669..98f8b69f 100644 --- a/cdist/conf/type/__filesystem/parameter/required +++ b/cdist/conf/type/__filesystem/parameter/required @@ -1,2 +1 @@ fstype -device