Ask Your Question
0

"file" resource with and arrays of default sources

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

trtrmitya gravatar image

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

GregLarkin gravatar image

Hello,

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

File {
    owner => 'root',
    source => [
      "puppet:///modules/mymodule/$title.$host",
      "puppet:///modules/mymodule/$title.$operatingsystem",
      "puppet:///modules/mymodule/$title"
    ]
}

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?

Thanks!

edit retag flag offensive close merge delete

Comments

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

Alex Harvey gravatar imageAlex Harvey ( 2015-12-31 00:24:37 -0500 )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 -0500 )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 -0500 )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 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

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

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

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

define my_file() {
  file { $name:
    ensure => file,
    owner  => 'root',
    source => [
      "puppet:///modules/mymodule/$name.${::host}",
      "puppet:///modules/mymodule/$name.${::operatingsystem}",
      "puppet:///modules/mymodule/$name",
    ],
  }
}

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

Comments

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 -0500 )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 -0500 )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

Stats

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

Seen: 327 times

Last updated: Dec 31 '15