Paul
2009-May-31 21:45 UTC
[Puppet Users] No more than one "instances" of a type in define()?
Hi folks, when I try to do something like: define railsproject($name, $uid, $gid, $userpass, $sqlpass) { mysql_database { "$name_staging": ensure => present } mysql_database { "$name_production": ensure => present} ....more stuff... } I get: Puppet::Parser::AST::Resource failed with error ArgumentError: Duplicate definition: Mysql_database[] is already defined in file /etc/ puppet//modules/../manifests/definitions/railsproject.pp at line 26; cannot redefine at /etc/puppet//modules/../manifests/definitions/ railsproject.pp:27 on node dev.xxxx.net It seems I''m missing some important detail here. Why can''t types be used more than once? How do I create two databases? thanks Paul --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Matthew Hyclak
2009-Jun-01 01:59 UTC
[Puppet Users] Re: No more than one "instances" of a type in define()?
On Sun, May 31, 2009 at 5:45 PM, Paul <pkoelle@gmail.com> wrote:> > Hi folks, > > when I try to do something like: > > define railsproject($name, $uid, $gid, $userpass, $sqlpass) { > mysql_database { "$name_staging": ensure => present } > mysql_database { "$name_production": ensure => present} > > ....more stuff... > } > > I get: > > Puppet::Parser::AST::Resource failed with error ArgumentError: > Duplicate definition: Mysql_database[] is already defined in file /etc/ > puppet//modules/../manifests/definitions/railsproject.pp at line 26; > cannot redefine at /etc/puppet//modules/../manifests/definitions/ > railsproject.pp:27 on node dev.xxxx.net > > It seems I''m missing some important detail here. Why can''t types be > used more than once? How do I create two databases? >I would do define railsproject($name, $uid, $gid, $userpass, $sqlpass) { mysql_database { "$name_staging": ensure => present; "$name_production": ensure => present } ....more stuff... } 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 -~----------~----~----~----~------~----~------~--~---
Avi Miller
2009-Jun-01 02:03 UTC
[Puppet Users] Re: No more than one "instances" of a type in define()?
Paul wrote:> mysql_database { "$name_staging": ensure => present }Try: mysql_database { "${name}_staging": ensure => present } I ran into a similar problem with multiple yumrepo types in a single define. cYa, Avi --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
David Schmitt
2009-Jun-01 10:27 UTC
[Puppet Users] Re: No more than one "instances" of a type in define()?
Paul schrieb:> Hi folks, > > when I try to do something like: > > define railsproject($name, $uid, $gid, $userpass, $sqlpass) { > mysql_database { "$name_staging": ensure => present } > mysql_database { "$name_production": ensure => present} > > ....more stuff... > } > > I get: > > Puppet::Parser::AST::Resource failed with error ArgumentError: > Duplicate definition: Mysql_database[] is already defined in file /etc/ > puppet//modules/../manifests/definitions/railsproject.pp at line 26; > cannot redefine at /etc/puppet//modules/../manifests/definitions/ > railsproject.pp:27 on node dev.xxxx.net > > It seems I''m missing some important detail here. Why can''t types be > used more than once? How do I create two databases?$name_staging and $name_production are both empty, therefore "Mysql_database[]" (contrary to Mysql_database[something]) is defined twice. As Ari points out correctly, you should always use {} around variable names when interpolating a string: > define railsproject($name, $uid, $gid, $userpass, $sqlpass) { > mysql_database { "${name}_staging": ensure => present } > mysql_database { "${name}_production": ensure => present} > > ....more stuff... > } Regards, DavidS -- dasz.at OG Tel: +43 (0)664 2602670 Web: http://dasz.at Klosterneuburg UID: ATU64260999 FB-Nr.: FN 309285 g FB-Gericht: LG Korneuburg --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Paul
2009-Jun-01 11:00 UTC
[Puppet Users] Re: No more than one "instances" of a type in define()?
On 1 Jun., 12:27, David Schmitt <da...@dasz.at> wrote:> Paul schrieb: > > > > > Hi folks, > > > when I try to do something like: > > > define railsproject($name, $uid, $gid, $userpass, $sqlpass) { > > mysql_database { "$name_staging": ensure => present } > > mysql_database { "$name_production": ensure => present} > > > ....more stuff... > > } > > > I get: > > > Puppet::Parser::AST::Resource failed with error ArgumentError: > > Duplicate definition: Mysql_database[] is already defined in file /etc/ > > puppet//modules/../manifests/definitions/railsproject.pp at line 26; > > cannot redefine at /etc/puppet//modules/../manifests/definitions/ > > railsproject.pp:27 on node dev.xxxx.net > > > It seems I''m missing some important detail here. Why can''t types be > > used more than once? How do I create two databases? > > $name_staging and $name_production are both empty, therefore > "Mysql_database[]" (contrary to Mysql_database[something]) is defined > twice. As Ari points out correctly, you should always use {} around > variable names when interpolating a string: > > > define railsproject($name, $uid, $gid, $userpass, $sqlpass) { > > mysql_database { "${name}_staging": ensure => present } > > mysql_database { "${name}_production": ensure => present} > > > > ....more stuff... > > } >Thanks all, it works. Is this documented or have you figured this out by trial and error? I''m not trying to blame the docs, it''s just that I couldn''t find anything about the ${} rule. Apparently there seem to be more differences between classes and defines wrt. scope. When I use template("foo.erb") inside a define() I don''t have direct access to facts or other variables (fex. the $name). However scope.lookupvar(''name'') works. Is this expected behaviour? thanks again Paul> Regards, DavidS > > -- > dasz.at OG Tel: +43 (0)664 2602670 Web:http://dasz.at > Klosterneuburg UID: ATU64260999 > > FB-Nr.: FN 309285 g FB-Gericht: LG Korneuburg--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
David Schmitt
2009-Jun-01 11:18 UTC
[Puppet Users] Re: No more than one "instances" of a type in define()?
Paul schrieb:>> > define railsproject($name, $uid, $gid, $userpass, $sqlpass) { >> > mysql_database { "${name}_staging": ensure => present } >> > mysql_database { "${name}_production": ensure => present} >> > >> > ....more stuff... >> > } >> > Thanks all, it works. Is this documented or have you figured this out > by trial and error? I''m not trying to blame the docs, it''s just that I > couldn''t find anything about the ${} rule.See http://reductivelabs.com/trac/puppet/wiki/LanguageTutorial#quoting> Apparently there seem to be more differences between classes and > defines wrt. scope. When I use template("foo.erb") inside a define() I > don''t have direct access to facts or other variables (fex. the $name). > However scope.lookupvar(''name'') works. Is this expected behaviour?No. What version of puppet are you using? How did your ERB look like? Regards, DavidS -- dasz.at OG Tel: +43 (0)664 2602670 Web: http://dasz.at Klosterneuburg UID: ATU64260999 FB-Nr.: FN 309285 g FB-Gericht: LG Korneuburg --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Paul
2009-Jun-01 12:36 UTC
[Puppet Users] Re: No more than one "instances" of a type in define()?
On 1 Jun., 13:18, David Schmitt <da...@dasz.at> wrote:> Paul schrieb: > > >> > define railsproject($name, $uid, $gid, $userpass, $sqlpass) { > >> > mysql_database { "${name}_staging": ensure => present } > >> > mysql_database { "${name}_production": ensure => present} > > >> > ....more stuff... > >> > } > > > Thanks all, it works. Is this documented or have you figured this out > > by trial and error? I''m not trying to blame the docs, it''s just that I > > couldn''t find anything about the ${} rule. > > See http://reductivelabs.com/trac/puppet/wiki/LanguageTutorial#quotingIndeed, shame on me ;) But if you take that literally brackets shouldn''t be needed.> > > Apparently there seem to be more differences between classes and > > defines wrt. scope. When I use template("foo.erb") inside a define() I > > don''t have direct access to facts or other variables (fex. the $name). > > However scope.lookupvar(''name'') works. Is this expected behaviour? > > No. What version of puppet are you using? How did your ERB look like?Version is 0.24.8, I''m testing with: ------------------------- <% tags.each do |tag| -%> TAG: <%= tag %> <% end -%> SCOPE LOOKUP <%= scope.lookupvar(''name'') %> SCOPE LOOKUP <%= scope.lookupvar(''ipaddress_eth0'') %> <VirtualHost <%= $ipaddress_eth0 %>:80> ServerName www.<%= $name %>.xxx.net result: -------------------------- TAG: railsproject TAG: test TAG: class TAG: railsnode TAG: node TAG: dev TAG: main SCOPE LOOKUP test SCOPE LOOKUP 78.xx.xx.66 <VirtualHost :80> ServerName www..xxx.net The call to template() is inside the define railsproject(): define railsproject($name, $uid, $gid, $userpass, $sqlpass) { file { "/etc/apache2/sites-available/${name}-apache": owner => root, group => root, mode => 644, content => template("vhosts/apache-rails-template.erb"); } ....more stuff... } Hmm, just tested with a simple class templatetest { file { "foo": template("foo.erb") }}, same result. Something is messed up ;( thanks Paul> > Regards, DavidS > > -- > dasz.at OG Tel: +43 (0)664 2602670 Web:http://dasz.at > Klosterneuburg UID: ATU64260999 > > FB-Nr.: FN 309285 g FB-Gericht: LG Korneuburg--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter Meier
2009-Jun-01 15:01 UTC
[Puppet Users] Re: No more than one "instances" of a type in define()?
Hi>> Thanks all, it works. Is this documented or have you figured this out >> by trial and error? I''m not trying to blame the docs, it''s just that I >> couldn''t find anything about the ${} rule. > > See http://reductivelabs.com/trac/puppet/wiki/LanguageTutorial#quotingas well the error message is telling you that the variables are empty. cheers pete --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
David Schmitt
2009-Jun-01 18:40 UTC
[Puppet Users] Re: No more than one "instances" of a type in define()?
Paul wrote:>> See http://reductivelabs.com/trac/puppet/wiki/LanguageTutorial#quoting > Indeed, shame on me ;) But if you take that literally brackets > shouldn''t be needed.Except that the underscore is a valid part of a variable name and puppet does longest match on variable names, thus recognising $name_production, instead of the existing $name.>>> Apparently there seem to be more differences between classes and >>> defines wrt. scope. When I use template("foo.erb") inside a define() I >>> don''t have direct access to facts or other variables (fex. the $name). >>> However scope.lookupvar(''name'') works. Is this expected behaviour? >> No. What version of puppet are you using? How did your ERB look like? > Version is 0.24.8, I''m testing with: > ------------------------- > <% tags.each do |tag| -%> > TAG: <%= tag %> > <% end -%> > SCOPE LOOKUP <%= scope.lookupvar(''name'') %> > SCOPE LOOKUP <%= scope.lookupvar(''ipaddress_eth0'') %> > <VirtualHost <%= $ipaddress_eth0 %>:80>Stuff within <%%> is ruby. Ruby has no $ sigils. Use the variable instead without the dollar sign: > <VirtualHost <%= ipaddress_eth0 %>:80> Regards, DavidS --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Paul
2009-Jun-03 10:48 UTC
[Puppet Users] Re: No more than one "instances" of a type in define()?
On 1 Jun., 20:40, David Schmitt <da...@dasz.at> wrote:> Paul wrote: > >> Seehttp://reductivelabs.com/trac/puppet/wiki/LanguageTutorial#quoting > > Indeed, shame on me ;) But if you take that literally brackets > > shouldn''t be needed. > > Except that the underscore is a valid part of a variable name and puppet > does longest match on variable names, thus recognising $name_production, > instead of the existing $name. > > >>> Apparently there seem to be more differences between classes and > >>> defines wrt. scope. When I use template("foo.erb") inside a define() I > >>> don''t have direct access to facts or other variables (fex. the $name). > >>> However scope.lookupvar(''name'') works. Is this expected behaviour? > >> No. What version of puppet are you using? How did your ERB look like? > > Version is 0.24.8, I''m testing with: > > ------------------------- > > <% tags.each do |tag| -%> > > TAG: <%= tag %> > > <% end -%> > > SCOPE LOOKUP <%= scope.lookupvar(''name'') %> > > SCOPE LOOKUP <%= scope.lookupvar(''ipaddress_eth0'') %> > > <VirtualHost <%= $ipaddress_eth0 %>:80> > > Stuff within <%%> is ruby. Ruby has no $ sigils. Use the variable > instead without the dollar sign: > > > <VirtualHost <%= ipaddress_eth0 %>:80>Ops, another Doh! Thanks guys, it''s all working now. cheers Paul> > Regards, DavidS--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---