"Future" parser and "return value" of resource definition

24 views
Skip to first unread message

Simon Marechal

unread,
May 25, 2013, 2:20:27 AM5/25/13
to puppet...@googlegroups.com
A simple example :

        file { '/tmp/out':
                content => [1,2,3,8].each |$v| {
                        file { "/tmp/$v": content => $v; }
                }
        }

Should it be valid to use "each" here ? If it is, what is the expected behavior (in my test the content of /tmp/out is '3') ?

Simon Marechal

unread,
May 25, 2013, 3:53:37 AM5/25/13
to puppet...@googlegroups.com
Also, this is accepted :

        collect([1,2,3]) |$x| {
                file { "/tmp/b$x":
                        content => collect([1,2,3]) |$y| { $y };
                }
        }

and this isn't :

        collect([1,2,3]) |$x| {
                file { "/tmp/b$x":
                        content => collect([1,2,3]) |$y| { $y + 0 };
                }
        }


Error: Failed to apply catalog: Parameter content failed on File[/tmp/b2]: Munging failed for value 1 in class content: can't convert Fixnum into String at /etc/puppet/manifests/site.pp:4

but this is :

        each([1,2,3]) |$x| {
                file { "/tmp/ab$x":
                        content => each([1,2,3]) |$y| { $y + 1 };
                }
        }

It also seems that "collect" isn't too useful compared to "each" :
* you can use collect everywhere you would use collect
* "each" seems to return the original collection unchanged


Simon Marechal

unread,
May 26, 2013, 12:04:10 PM5/26/13
to puppet...@googlegroups.com


On Saturday, May 25, 2013 9:53:37 AM UTC+2, Simon Marechal wrote:
It also seems that "collect" isn't too useful compared to "each" :
* you can use collect everywhere you would use collect
* "each" seems to return the original collection unchanged

Hum, that made no sense :)

In my mind, there are two kinds of puppet functions :
* functions at the statement level (realize, include, fail)
* functions at the "value" level (fqdn_rand, file, etc.) : those functions either transform or produce data

In the case of the "future" parser, it would be nice to either enforce this for each / collect (ie. use collect only in "value" context, and each in "statement" context), or to only have one function that does both.
Reply all
Reply to author
Forward
0 new messages