sourceselect & multiple sources not working

493 views
Skip to first unread message

Brett Cave

unread,
Apr 7, 2011, 8:44:19 AM4/7/11
to puppet...@googlegroups.com
Hi,

I am trying to configure a file resource with multiple sources, and browsing list archives and forums seems to indicate that sourceselect parameter with an array for the source param. But the final file gets created using the first matching parameter in the array.

    file { '/etc/sysconfig/myconfig':
        sourceselect    => all,
        source  => [
                     "puppet:///modules/app/$env/sysconfig.$hostname",
                     "puppet:///modules/app/sysconfig-base"
                   ],
        owner   => 'someuser',
        group   => 'somegroup',
        mode    => '0664',
        require => Package['app'],
    }

If i set source to either 1 or the other, instead of an array, it works as expected. by swapping the 2 array elements around, i get either the hostname version only, or the base version only, but the content is never merged (i get the content of the first element).

Is this the correct way to have multiple source files merged?
puppet / puppet-master version (RHEL rpm): 2.6.6-0.5

brett

Felix Frank

unread,
Apr 7, 2011, 9:04:44 AM4/7/11
to puppet...@googlegroups.com
Hi,

On 04/07/2011 02:44 PM, Brett Cave wrote:
> Hi,
>
> I am trying to configure a file resource with multiple sources, and
> browsing list archives and forums seems to indicate that sourceselect
> parameter with an array for the source param. But the final file gets
> created using the first matching parameter in the array.

note here http://docs.puppetlabs.com/references/stable/type.html#file
that sourceselect "is only used in recursive copies".

Single files cannot be merged. After all, how would you define the merge
of two files?

If you want to concatenate the files, you may want to abuse the
template() function for that. But please don't ;-)

Regards,
Felix

Brett Cave

unread,
Apr 7, 2011, 9:35:14 AM4/7/11
to puppet...@googlegroups.com
On Thu, Apr 7, 2011 at 3:04 PM, Felix Frank <felix...@alumni.tu-berlin.de> wrote:
note here http://docs.puppetlabs.com/references/stable/type.html#file
that sourceselect "is only used in recursive copies".
 
ah ok. thanks

Single files cannot be merged. After all, how would you define the merge
of two files?

concat :p - i.e. append file contents to each in the order they are listed
 
If you want to concatenate the files, you may want to abuse the
template() function for that. But please don't ;-)

I did come across this too - http://projects.puppetlabs.com/issues/5158, and implemented this:
custom function added:
module Puppet::Parser::Functions
newfunction(:cat, :type => :rvalue) do |args|
args.join("")
end
end

files then uses content:
content => cat(file("/etc/puppet/modules/app/files/sysconfig-base"), file("/etc/puppet/modules/app/files/$env/sysconfig.$hostname")),

Just need to add in some path detection or some variable so that I don't have to specify the path the files (is there a variable available that gives $module_path? )

brett


Regards,
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...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.



Bernardo Costa

unread,
Nov 12, 2012, 3:05:24 PM11/12/12
to puppet...@googlegroups.com, br...@jemstep.com
I also have a similar problem. I want to create/append a file (automount map) whose lines are independent. For me the best way to handle it would be splitting it into chunks and then decide based on the manifest file which chunk a group of hosts should get on the server. Is it possible ?
Reply all
Reply to author
Forward
0 new messages