From 8e42336df31724b49aa277565a2244de7bd0b3d1 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 17 Jun 2011 09:31:39 +0200 Subject: [PATCH 1/9] new type: __postgres_database Signed-off-by: Steven Armstrong --- conf/type/__postgres_database/explorer/state | 27 ++++++++++++ conf/type/__postgres_database/gencode-remote | 38 ++++++++++++++++ conf/type/__postgres_database/man.text | 44 +++++++++++++++++++ .../__postgres_database/parameter/optional | 1 + .../__postgres_database/parameter/required | 1 + 5 files changed, 111 insertions(+) create mode 100755 conf/type/__postgres_database/explorer/state create mode 100755 conf/type/__postgres_database/gencode-remote create mode 100644 conf/type/__postgres_database/man.text create mode 100644 conf/type/__postgres_database/parameter/optional create mode 100644 conf/type/__postgres_database/parameter/required diff --git a/conf/type/__postgres_database/explorer/state b/conf/type/__postgres_database/explorer/state new file mode 100755 index 00000000..565c8a63 --- /dev/null +++ b/conf/type/__postgres_database/explorer/state @@ -0,0 +1,27 @@ +#!/bin/sh +# +# 2011 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="$__object_id" + +if su - postgres -c "psql -l | grep -q '^ *$name'"; then + echo "present" +else + echo "absent" +fi diff --git a/conf/type/__postgres_database/gencode-remote b/conf/type/__postgres_database/gencode-remote new file mode 100755 index 00000000..4c3f5b0e --- /dev/null +++ b/conf/type/__postgres_database/gencode-remote @@ -0,0 +1,38 @@ +#!/bin/sh +# +# 2011 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="$__object_id" +state_should="$(cat "$__object/parameter/state")" +state_is="$(cat "$__object/explorer/state")" + +if [ "$state_should" != "$state_is" ]; then + case "$state_should" in + present) + owner="" + if [ -f "$__object/parameter/owner" ]; then + owner="-O '$(cat "$__object/parameter/owner")'" + fi + echo "su - postgres -c \"/usr/bin/createdb $owner '$name'\"" + ;; + absent) + echo "su - postgres -c \"/usr/bin/dropdb '$name'\"" + ;; + esac +fi diff --git a/conf/type/__postgres_database/man.text b/conf/type/__postgres_database/man.text new file mode 100644 index 00000000..06cb736f --- /dev/null +++ b/conf/type/__postgres_database/man.text @@ -0,0 +1,44 @@ +cdist-type__postgres_database(7) +================================ +Steven Armstrong + + +NAME +---- +cdist-type__postgres_database - create/drop postgres databases + + +DESCRIPTION +----------- +This cdist type allows you to create or drop postgres databases. + + +REQUIRED PARAMETERS +------------------- +state:: + either 'present' or 'absent' + + +OPTIONAL PARAMETERS +------------------- +owner:: + the role owning this database + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__postgres_database mydbname --state present --owner mydbusername +-------------------------------------------------------------------------------- + + +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/conf/type/__postgres_database/parameter/optional b/conf/type/__postgres_database/parameter/optional new file mode 100644 index 00000000..7ee3bde8 --- /dev/null +++ b/conf/type/__postgres_database/parameter/optional @@ -0,0 +1 @@ +owner diff --git a/conf/type/__postgres_database/parameter/required b/conf/type/__postgres_database/parameter/required new file mode 100644 index 00000000..ff72b5c7 --- /dev/null +++ b/conf/type/__postgres_database/parameter/required @@ -0,0 +1 @@ +state From 94cdf36439aaf708f7477fd1d967eb732434a361 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 17 Jun 2011 11:37:43 +0200 Subject: [PATCH 2/9] new type: __postgres_role Signed-off-by: Steven Armstrong --- conf/type/__postgres_role/explorer/state | 27 ++++++++++ conf/type/__postgres_role/gencode-remote | 54 ++++++++++++++++++++ conf/type/__postgres_role/man.text | 52 +++++++++++++++++++ conf/type/__postgres_role/parameter/optional | 6 +++ conf/type/__postgres_role/parameter/required | 1 + 5 files changed, 140 insertions(+) create mode 100755 conf/type/__postgres_role/explorer/state create mode 100755 conf/type/__postgres_role/gencode-remote create mode 100644 conf/type/__postgres_role/man.text create mode 100644 conf/type/__postgres_role/parameter/optional create mode 100644 conf/type/__postgres_role/parameter/required diff --git a/conf/type/__postgres_role/explorer/state b/conf/type/__postgres_role/explorer/state new file mode 100755 index 00000000..8c102df9 --- /dev/null +++ b/conf/type/__postgres_role/explorer/state @@ -0,0 +1,27 @@ +#!/bin/sh +# +# 2011 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="$__object_id" + +if su - postgres -c "psql -c '\du' | grep -q '^ *$name *|'"; then + echo "present" +else + echo "absent" +fi diff --git a/conf/type/__postgres_role/gencode-remote b/conf/type/__postgres_role/gencode-remote new file mode 100755 index 00000000..5f1401b1 --- /dev/null +++ b/conf/type/__postgres_role/gencode-remote @@ -0,0 +1,54 @@ +#!/bin/sh +# +# 2011 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="$__object_id" +state_is="$(cat "$__object/explorer/state")" +state_should="$(cat "$__object/parameter/state")" + +if [ "$state_is" != "$state_should" ]; then + case "$state_should" in + present) + optional="password + login + createdb + createrole + superuser" + for parameter in $optional; do + if [ -f "$__object/parameter/$parameter" ]; then + value="$(cat "$__object/parameter/$parameter")" + eval $parameter=$value + fi + done + + [ -n "$password" ] && password="PASSWORD '$password'" + [ "$login" = "true" ] && login="LOGIN" || login="NOLOGIN" + [ "$createdb" = "true" ] && createdb="CREATEDB" || createdb="NOCREATEDB" + [ "$createrole" = "true" ] && createrole="CREATEROLE" || createrole="NOCREATEROLE" + [ "$superuser" = "true" ] && superuser="SUPERUSER" || superuser="NOSUPERUSER" + [ "$inherit" = "true" ] && inherit="INHERIT" || inherit="NOINHERIT" + + cmd="CREATE ROLE $name WITH $password $login $createdb $createrole $superuser $inherit" + echo "su - postgres -c \"/usr/bin/psql -c \\\"$cmd\\\"\"" + ;; + absent) + echo "su - postgres -c \"/usr/bin/dropuser \\\"$name\\\"\"" + ;; + esac +fi diff --git a/conf/type/__postgres_role/man.text b/conf/type/__postgres_role/man.text new file mode 100644 index 00000000..415473d5 --- /dev/null +++ b/conf/type/__postgres_role/man.text @@ -0,0 +1,52 @@ +cdist-type__postgres_role(7) +============================ +Steven Armstrong + + +NAME +---- +cdist-type__postgres_role - manage postgres roles + + +DESCRIPTION +----------- +This cdist type allows you to create or drop postgres roles. + + +REQUIRED PARAMETERS +------------------- +state:: + either 'present' or 'absent' + + +OPTIONAL PARAMETERS +------------------- +All optional parameter map directly to the corresponding postgres createrole +parameters. + +password:: +login:: +createdb:: +createrole:: +superuser:: +inherit:: + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__postgres_role myrole --state present +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- http://www.postgresql.org/docs/current/static/sql-createrole.html + + +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/conf/type/__postgres_role/parameter/optional b/conf/type/__postgres_role/parameter/optional new file mode 100644 index 00000000..c5abb57f --- /dev/null +++ b/conf/type/__postgres_role/parameter/optional @@ -0,0 +1,6 @@ +password +login +createdb +createrole +superuser +inherit diff --git a/conf/type/__postgres_role/parameter/required b/conf/type/__postgres_role/parameter/required new file mode 100644 index 00000000..ff72b5c7 --- /dev/null +++ b/conf/type/__postgres_role/parameter/required @@ -0,0 +1 @@ +state From 2cf67e321e0322c6d2e85532fede9c328ae0d2b1 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 17 Jun 2011 13:14:57 +0200 Subject: [PATCH 3/9] in PATH we trust Signed-off-by: Steven Armstrong --- conf/type/__postgres_database/gencode-remote | 4 ++-- conf/type/__postgres_role/gencode-remote | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/conf/type/__postgres_database/gencode-remote b/conf/type/__postgres_database/gencode-remote index 4c3f5b0e..c097efce 100755 --- a/conf/type/__postgres_database/gencode-remote +++ b/conf/type/__postgres_database/gencode-remote @@ -29,10 +29,10 @@ if [ "$state_should" != "$state_is" ]; then if [ -f "$__object/parameter/owner" ]; then owner="-O '$(cat "$__object/parameter/owner")'" fi - echo "su - postgres -c \"/usr/bin/createdb $owner '$name'\"" + echo "su - postgres -c \"createdb $owner '$name'\"" ;; absent) - echo "su - postgres -c \"/usr/bin/dropdb '$name'\"" + echo "su - postgres -c \"dropdb '$name'\"" ;; esac fi diff --git a/conf/type/__postgres_role/gencode-remote b/conf/type/__postgres_role/gencode-remote index 5f1401b1..a3280c09 100755 --- a/conf/type/__postgres_role/gencode-remote +++ b/conf/type/__postgres_role/gencode-remote @@ -45,10 +45,10 @@ if [ "$state_is" != "$state_should" ]; then [ "$inherit" = "true" ] && inherit="INHERIT" || inherit="NOINHERIT" cmd="CREATE ROLE $name WITH $password $login $createdb $createrole $superuser $inherit" - echo "su - postgres -c \"/usr/bin/psql -c \\\"$cmd\\\"\"" + echo "su - postgres -c \"psql -c \\\"$cmd\\\"\"" ;; absent) - echo "su - postgres -c \"/usr/bin/dropuser \\\"$name\\\"\"" + echo "su - postgres -c \"dropuser \\\"$name\\\"\"" ;; esac fi From 2fcdf3825b78b13d114c9ad0282f3008e45c98fb Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 17 Jun 2011 13:19:46 +0200 Subject: [PATCH 4/9] safer way to check for database existence Signed-off-by: Steven Armstrong --- conf/type/__postgres_database/explorer/state | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/type/__postgres_database/explorer/state b/conf/type/__postgres_database/explorer/state index 565c8a63..dc9659e2 100755 --- a/conf/type/__postgres_database/explorer/state +++ b/conf/type/__postgres_database/explorer/state @@ -20,7 +20,7 @@ name="$__object_id" -if su - postgres -c "psql -l | grep -q '^ *$name'"; then +if su - postgres -c "echo '\q' | psql '$name'" 2>/dev/null; then echo "present" else echo "absent" From 13dfbaf451c5eb2ddf31af72224aaec7895f7dec Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 17 Jun 2011 13:53:55 +0200 Subject: [PATCH 5/9] remove legacy todo file Signed-off-by: Steven Armstrong --- doc/dev/todo/steven-from-nico | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 doc/dev/todo/steven-from-nico diff --git a/doc/dev/todo/steven-from-nico b/doc/dev/todo/steven-from-nico deleted file mode 100644 index 21c8fb52..00000000 --- a/doc/dev/todo/steven-from-nico +++ /dev/null @@ -1,5 +0,0 @@ -- align messages (already in todo for steven, but makes life much easier, thus repeated) - -> prefix all object stuff with $__self - -> __cdist_echo object string - -> $__cdist_object_self :-) - From 36b0cffeea38f8740b0c21953c054c8fd0cd2433 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 17 Jun 2011 13:54:51 +0200 Subject: [PATCH 6/9] --legacy todos Signed-off-by: Steven Armstrong --- doc/dev/todo/steven | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/doc/dev/todo/steven b/doc/dev/todo/steven index 5f91a198..e69de29b 100644 --- a/doc/dev/todo/steven +++ b/doc/dev/todo/steven @@ -1,16 +0,0 @@ -- document object_id=$1 for manifest + gencode :-) - -- update docs regarding flow in cdist-stages.text -- create man pages for new executables -- nuke legacy manpages - -- prettify output of cdist-deploy-to, e.g. - -Processing object __file/etc/cdist-configured - transfering type explorers ... - running type explorers ... - running manifest ... - running gencode ... - transfering object to target ... - running code ... - From ed07f630455e72e7693cd7f28d373e81584b718a Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 17 Jun 2011 13:59:53 +0200 Subject: [PATCH 7/9] +todo Signed-off-by: Steven Armstrong --- doc/dev/todo/TAKEME | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/dev/todo/TAKEME b/doc/dev/todo/TAKEME index d626493d..a3d74661 100644 --- a/doc/dev/todo/TAKEME +++ b/doc/dev/todo/TAKEME @@ -41,6 +41,14 @@ CORE and have it parsable by different (shinken) tool -> given after manifest run already! +- Allow types to have parameters without values (boolean flags). + e.g. __chair fancychair --pink --wood + would result in: + $__object/parameter/ + pink # empty file + wood # empty file + + TYPES ------ - __ssh-keys (host/user) From 5e1dccaf8e8e23d4f53466b761b1541c1ae1cd7f Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 17 Jun 2011 14:03:51 +0200 Subject: [PATCH 8/9] examples++ Signed-off-by: Steven Armstrong --- conf/type/__postgres_role/man.text | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/conf/type/__postgres_role/man.text b/conf/type/__postgres_role/man.text index 415473d5..fbf01227 100644 --- a/conf/type/__postgres_role/man.text +++ b/conf/type/__postgres_role/man.text @@ -37,6 +37,12 @@ EXAMPLES -------------------------------------------------------------------------------- __postgres_role myrole --state present + +__postgres_role myrole --state present --password 'secret' + +__postgres_role admin --state present --password 'very-secret' --superuser + +__postgres_role dbcustomer --state present --password 'bla' --createdb -------------------------------------------------------------------------------- From 509d0781132ce20eec23eeeff4a45d8156ab3afe Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 17 Jun 2011 16:28:53 +0200 Subject: [PATCH 9/9] me is ahead of myself Signed-off-by: Steven Armstrong --- conf/type/__postgres_role/man.text | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/type/__postgres_role/man.text b/conf/type/__postgres_role/man.text index fbf01227..a7264870 100644 --- a/conf/type/__postgres_role/man.text +++ b/conf/type/__postgres_role/man.text @@ -40,9 +40,9 @@ __postgres_role myrole --state present __postgres_role myrole --state present --password 'secret' -__postgres_role admin --state present --password 'very-secret' --superuser +__postgres_role admin --state present --password 'very-secret' --superuser true -__postgres_role dbcustomer --state present --password 'bla' --createdb +__postgres_role dbcustomer --state present --password 'bla' --createdb true --------------------------------------------------------------------------------