From 2b22e5de242a23797b064b05d24385a6c0adfdeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Bondis?= Date: Mon, 12 Mar 2012 14:13:02 -0400 Subject: [PATCH 1/3] added informations for templating --- doc/man/man7/cdist-best-practice.text | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/doc/man/man7/cdist-best-practice.text b/doc/man/man7/cdist-best-practice.text index bbfd084a..2674bc06 100644 --- a/doc/man/man7/cdist-best-practice.text +++ b/doc/man/man7/cdist-best-practice.text @@ -153,6 +153,40 @@ implement this scenario with a gateway host and sudo: For more details consult sudoers(5) +TEMPLATING +---------- +* create directory templates/ in your type (convention) +* create the template as an executable file like templates/basic.conf.sh, it will output text using shell variables for the values + +-------------------------------------------------------------------------------------- +#!/bin/bash +# 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/templates/collectd.conf" > "$__object/files/collectd.conf" +# send the rendered template + __file /etc/collectd.conf --state present --source "$__object/files/collectd.conf" +-------------------------------------------------------------------------------------- + SEE ALSO -------- - cdist(1) From 1878c35ac4f30822e68f55e0573f8c1c8a00977b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Bondis?= Date: Mon, 12 Mar 2012 14:16:37 -0400 Subject: [PATCH 2/3] modify template name in example --- doc/man/man7/cdist-best-practice.text | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/man/man7/cdist-best-practice.text b/doc/man/man7/cdist-best-practice.text index 2674bc06..9e18bd2f 100644 --- a/doc/man/man7/cdist-best-practice.text +++ b/doc/man/man7/cdist-best-practice.text @@ -182,9 +182,9 @@ EOF export ROOT='/var/www/test' # render the template mkdir -p "$__object/files" - "$__type/templates/collectd.conf" > "$__object/files/collectd.conf" + "$__type/templates/basic.conf.sh" > "$__object/files/basic.conf" # send the rendered template - __file /etc/collectd.conf --state present --source "$__object/files/collectd.conf" + __file /etc/nginx/sites-available/test.conf --state present --source "$__object/files/basic.conf" -------------------------------------------------------------------------------------- SEE ALSO From 6b125d26ecd856ab4827c6ce89c2836176ff9623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Bondis?= Date: Mon, 12 Mar 2012 14:19:41 -0400 Subject: [PATCH 3/3] doc: template changed to /bin/sh --- doc/man/man7/cdist-best-practice.text | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/man/man7/cdist-best-practice.text b/doc/man/man7/cdist-best-practice.text index 9e18bd2f..a8851f7f 100644 --- a/doc/man/man7/cdist-best-practice.text +++ b/doc/man/man7/cdist-best-practice.text @@ -159,7 +159,7 @@ TEMPLATING * create the template as an executable file like templates/basic.conf.sh, it will output text using shell variables for the values -------------------------------------------------------------------------------------- -#!/bin/bash +#!/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