Ask Your Question

"file" resource with and arrays of default sources

asked 2015-12-29 08:00:34 -0600

trtrmitya gravatar image

updated 2015-12-29 13:45:11 -0600

GregLarkin gravatar image


I want to define a number of file type resource with the same source:

File {
    owner => 'root',
    source => [

where $title is resource title of each file resource definition.

And then I want to use it as:

file { '/etc/file1' }
file { '/etc/file2' }

... And in each definition source should be selected with the above algorithm.

How is it possible to achieve this?


edit retag flag offensive close merge delete


Can you explain a bit more what you're really trying to do?

Alex Harvey gravatar imageAlex Harvey ( 2015-12-31 00:24:37 -0600 )edit

I want to define a number of "file" resources without specifying source search path every time.

trtrmitya gravatar imagetrtrmitya ( 2015-12-31 02:45:22 -0600 )edit

Do you mean that you want the source path to depend upon the value of facts, $host and $operatingsystem?

Alex Harvey gravatar imageAlex Harvey ( 2015-12-31 10:45:08 -0600 )edit

Ah, sorry. I think I see what you're trying to do now. Let me think for a bit.

Alex Harvey gravatar imageAlex Harvey ( 2015-12-31 10:46:21 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-12-31 10:53:03 -0600

updated 2015-12-31 23:57:45 -0600

If I've understood you, you would need to define a type, I think:

define my_file() {
  file { $name:
    ensure => file,
    owner  => 'root',
    source => [

my_file { '/etc/file1': }
my_file { '/etc/file2': }
edit flag offensive delete link more


Yes, this is an option, and yes, i meant exactly that. The drawback is that you can't override other parameters like owner, mode, etc. (You can make this as parameters of my_file, but you never know for advance which one you will want to customize)

trtrmitya gravatar imagetrtrmitya ( 2016-01-01 06:57:45 -0600 )edit

Yes, I can kind of see how your feature proposal would be useful. Although, frankly, it would be very confusing for the person trying to maintain it. I would suggest you do use parameters, as it will be far clearer.

Alex Harvey gravatar imageAlex Harvey ( 2016-01-01 08:55:00 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-12-29 08:00:34 -0600

Seen: 538 times

Last updated: Dec 31 '15