From 0fe88a5ea9723303b2deb5a140745cb2559f77f6 Mon Sep 17 00:00:00 2001 From: Matteo Latini Date: Wed, 12 Oct 2011 12:16:31 +0300 Subject: [PATCH 1/3] having a file from which to source would be useful... --- manifests/init.pp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/manifests/init.pp b/manifests/init.pp index ca22a7c..aea581c 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -179,6 +179,17 @@ } } + 'source_file': { + file { "${apache_sites}-available/${name}": + source => [ "puppet:///files/apache2/${fqdn}/${name}", "puppet:///files/apache2/${name}" ], + mode => 644, + owner => root, + group => root, + ensure => present, + alias => "site-$name", + } + } + default: { file { "${apache_sites}-available/${name}": content => $content, From a5ffab914b185206ab41a58a5938d31d39c13d73 Mon Sep 17 00:00:00 2001 From: Matteo Latini Date: Wed, 12 Oct 2011 11:45:06 +0200 Subject: [PATCH 2/3] adds README changes --- README | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README b/README index 11d9314..8c87d39 100644 --- a/README +++ b/README @@ -77,7 +77,9 @@ remove the package, even if ensure is set to absent. before evaluating the rest of the site definition. It does not currently remove the package, even if ensure is set to absent. * `content`: set this to the text of the site definition -- eg, through -template(). If unset, the module will simply ensure that a file named +template(). If set to "source_file", the file's content will be sourced from +puppet master's puppet:///files/apache2/${fqdn}/${name} or puppet:///files/apache2/${name}, +whichever is available first. If unset, the module will simply ensure that a file named "/etc/apache2/sites-available/$name" exists ## Example ## From b7204d5cb49891ac79a9bf63a0f3d9fbf1d64f86 Mon Sep 17 00:00:00 2001 From: Matteo Latini Date: Wed, 12 Oct 2011 16:49:14 +0200 Subject: [PATCH 3/3] it should use source_file also for config classes --- README | 4 +++- manifests/init.pp | 52 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/README b/README index 8c87d39..8c55aea 100644 --- a/README +++ b/README @@ -44,7 +44,9 @@ definitions -- so simply including them in a node definition won't work... * `ensure`: typically set to "present" or "absent", but any value legal for a file resource can be used. Defaults to "present" * `content`: set this to the text of the snippet -- eg, through -template(). Defaults to `template("apache2/$name.conf.erb")`, which is +template(). If set to "source_file", the file's content will be sourced from +puppet master's puppet:///files/apache2/${fqdn}/${name}.conf or puppet:///files/apache2/${name}.conf, +whichever is available first. Defaults to `template("apache2/$name.conf.erb")`, which is unlikely to be what you want. * `order`: specifies the load order for this config snippet. the snippet will end up in `/etc/apache2/conf.d/$order-$name.conf`, and apache will load diff --git a/manifests/init.pp b/manifests/init.pp index aea581c..c27a63c 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -118,19 +118,45 @@ # Define an apache2 config snippet. Places all config snippets into # /etc/apache2/conf.d, where they will be automatically loaded define config ( $ensure = 'present', $content = '', $order="500") { - $real_content = $content ? { '' => template("apache2/${name}.conf.erb"), - default => $content, - } - - file { "${apache_conf}/${order}-${name}.conf": - ensure => $ensure, - content => $content, - mode => 644, - owner => root, - group => root, - # given the way File[$apache_conf] is defined, this might lead to - # multiple restarts. not sure. - notify => Exec["reload-apache2"], + case $content { + '': { + file { "${apache_conf}/${order}-${name}.conf": + ensure => $ensure, + content => template("apache2/${name}.conf.erb"), + mode => 644, + owner => root, + group => root, + # given the way File[$apache_conf] is defined, this might lead to + # multiple restarts. not sure. + notify => Exec["reload-apache2"], + } + } + + 'source_file': { + file { "${apache_conf}/${order}-${name}.conf": + source => [ "puppet:///files/apache2/${fqdn}/${name}.conf", "puppet:///files/apache2/${name}.conf" ], + ensure => $ensure, + mode => 644, + owner => root, + group => root, + # given the way File[$apache_conf] is defined, this might lead to + # multiple restarts. not sure. + notify => Exec["reload-apache2"], + } + } + + default: { + file { "${apache_conf}/${order}-${name}.conf": + ensure => $ensure, + content => template("apache2/${name}.conf.erb"), + mode => 644, + owner => root, + group => root, + # given the way File[$apache_conf] is defined, this might lead to + # multiple restarts. not sure. + notify => Exec["reload-apache2"], + } + } } }