I was wondering if I'd need to create a define() but the language guide's
description seems misleading, at least to me. From the 6th paragraph of the
Resources section:

http://docs.puppetlabs.com/guides/language_guide.html#resources

The field before the colon is the resource’s *title,* which must be unique
and can be used to refer to the resource in other parts of the Puppet
configuration.



On Mon, Feb 13, 2012 at 3:32 PM, Nan Liu <[email protected]> wrote:

> On Mon, Feb 13, 2012 at 3:21 PM, Justin Lloyd <[email protected]> wrote:
> > I'm trying to use an array on a file resource to create symlinks. If I
> have
> > multiple elements in the array, I get a redefinition error showing it's
> > replacing $name or $title with the CLASS name rather than the RESOURCE
> name.
> > Here's a simplified example using one array element, where I'd expect to
> end
> > up with /tmp/link.a pointing to /etc/motd. Notice it says it created the
> > file with the element name but the filename actually contains the class
> > name:
> >
> > root@ops-puppet02:/tmp# cat test.pp
> > class foo {
> >     file { [ 'a' ]:
> >         ensure => link,
> >         path   => "/tmp/link.${name}",
> >         target => "/etc/motd",
> >     }
> > }
>
> $name is not the file resource title 'a'.
>
> > include foo
> >
> > root@ops-puppet02:/tmp# puppet apply test.pp
> > notice: /Stage[main]/Foo/File[a]/ensure: created
> > notice: Finished catalog run in 0.02 seconds
> >
> > root@ops-puppet02:/tmp# ls -l link*
> > lrwxrwxrwx 1 root root 9 2012-02-13 17:12 link.foo -> /etc/motd
> >
> > If I change the array from [ 'a' ] to [ 'a', 'b' ], then given the above
> > logic it will attempt to redefine, leading to this output:
> >
> > Cannot alias File[b] to ["/tmp/link.foo"] at /tmp/test.pp:6; resource
> > ["File", "/tmp/link.foo"] already defined at /tmp/test.pp:6
> >
> > Seems like a bug, but maybe I'm missing something. Suggestions?
>
> It's not a bug per se, but rather you need to create a define type.
>
> define my_symlink {
>  file { $name:
>    ensure => symlink,
>     path => "/tmp/link.${name}",
>    target => '/etc/motd',
>  }
> }
>
> and then
>
> my_symlink { ['a', 'b']: }
>
> HTH,
>
> Nan
>
> --
> 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.
>
>


-- 
“We don’t need to increase our goods nearly as much as we need to scale
down our wants. Not wanting something is as good as possessing it.” --
Donald Horban

-- 
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.

Reply via email to