On 1 Jun., 12:27, David Schmitt <[email protected]> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en
-~----------~----~----~----~------~----~------~--~---