lists@truthisfreedom.org.uk
2011-Feb-11 14:42 UTC
[Puppet Users] Defines, Realization and Variables
Hi all, I''m running puppet 0.25.5 and I''m running into an issue with virtual defines for setting up my NGinx Vhosts. The define is as follows: class nginx{ ... # Setup a resource to create the configuration files define nginx_vhost($website_listen_port = "80",$ssl_enabled = "false"){ $website_hostname = $title # Setup the config file with the appropriate name from the template file{"/etc/nginx/conf.d/${title}.conf": ensure => file, content => template("nginx/nginx_vhost.conf.erb") } if $ssl_enabled != "false" { $website_listen_port = "443" file{"/etc/nginx/conf.d/${website_hostname}.ssl.conf": ensure => file, content => template("nginx/nginx_vhost.conf.erb") } } } ... } What I want to be able to do is the following in my classes: # Set the websites to be hosted on this server as an array $websites = [''testing.domain.com'',''test2.domain.com''] # realize the websites @nginx::nginx_vhost($websites:) realize(Nginx::Nginx_vhost[$websites]) The issue that I am running into is that I do not appear to be able to set the values for website_liste_port or ssl_enabled through using this methodology. Is the a way to pass the domain *and* the values for website_listen_port/ssl_enabled to the define at the point of realization? Thanks, Matt -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On 11.02.2011, at 15:42, lists@truthisfreedom.org.uk wrote:> Hi all, > > I''m running puppet 0.25.5 and I''m running into an issue with virtual defines for setting up my NGinx Vhosts. > > The define is as follows: > > class nginx{ > > ... > > > # Setup a resource to create the configuration files > define nginx_vhost($website_listen_port = "80",$ssl_enabled = "false"){ > $website_hostname = $title > # Setup the config file with the appropriate name from the template > file{"/etc/nginx/conf.d/${title}.conf": > ensure => file, > content => template("nginx/nginx_vhost.conf.erb") > } > if $ssl_enabled != "false" { > $website_listen_port = "443" > file{"/etc/nginx/conf.d/${website_hostname}.ssl.conf": > ensure => file, > content => template("nginx/nginx_vhost.conf.erb") > } > } > } > > ... > > } > > What I want to be able to do is the following in my classes: > > # Set the websites to be hosted on this server as an array > $websites = [''testing.domain.com'',''test2.domain.com''] > # realize the websites > @nginx::nginx_vhost($websites:) > realize(Nginx::Nginx_vhost[$websites]) > > > The issue that I am running into is that I do not appear to be able to set the values for website_liste_port or ssl_enabled through using this methodology. > > Is the a way to pass the domain *and* the values for website_listen_port/ssl_enabled to the define at the point of realization? > > Thanks, > > MattHi, I would use variables in resources namevar: define nginx_vhost($website_listen_port = "80",$ssl_enabled = "false"){ $website_hostname = $title # Setup the config file with the appropriate name from the template file{"nginx_${title}_${website_listen}": path => /etc/nginx/conf.d/${title}.conf": ensure => file, content => template("nginx/nginx_vhost.conf.erb") } (I can not verify atm.) hth, Martin -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On 02/11/2011 03:42 PM, lists@truthisfreedom.org.uk wrote:> Hi all, > > I''m running puppet 0.25.5 and I''m running into an issue with virtual > defines for setting up my NGinx Vhosts. > > The define is as follows: > > class nginx{ > > ... > > > # Setup a resource to create the configuration files > define nginx_vhost($website_listen_port = "80",$ssl_enabled = "false"){ > $website_hostname = $title > # Setup the config file with the appropriate name from the template > file{"/etc/nginx/conf.d/${title}.conf": > ensure => file, > content => template("nginx/nginx_vhost.conf.erb") > } > if $ssl_enabled != "false" { > $website_listen_port = "443" > file{"/etc/nginx/conf.d/${website_hostname}.ssl.conf": > ensure => file, > content => template("nginx/nginx_vhost.conf.erb") > } > } > } > > ... > > } > > What I want to be able to do is the following in my classes: > > # Set the websites to be hosted on this server as an array > $websites = [''testing.domain.com'',''test2.domain.com''] > # realize the websites > @nginx::nginx_vhost($websites:)This syntax looks awkward. You should declare each virtual resource on its own: @nginx::nginx_vhost { ''testing.domain.com'': ssl_enabled => true; ''test2.domain.com'': ; }> realize(Nginx::Nginx_vhost[$websites]) > > > The issue that I am running into is that I do not appear to be able to > set the values for website_liste_port or ssl_enabled through using this > methodology. > > Is the a way to pass the domain *and* the values for > website_listen_port/ssl_enabled to the define at the point of realization?Using the array for realization is fine, but I don''t recommend it for resource declaration. Yes, there is redundant data in your manifest now. The alternative probably is @nginx::nginx_vhost { $websites: } nginx::nginx_vhost <| title == ''testing.domain.com'' |> { ssl_enabled => false } nginx::nginx_vhost <| title == ''test2.domain.com'' |> But that''s redundant, too, *and* ugly on top of it ;-) HTH, Felix -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.