question: when declaring a `file` resource, is the...
# puppet
j
question: when declaring a
file
resource, is there a shortcut to include the name of the file being declared, as part of the
source
attribute's value? i'm thinking something like ...
Copy code
file { '/etc/xyz' :
    ensure => file ,
    source => "puppet:///modules/${module_name}${SOMETHING}" ,
  }
and obviously the module would have a
files/etc/xyz
file in it
b
$title
and
$name
probably refer to the class name where the resource lives, not the resource title, but worth a try
j
i tried that prolly 10 years ago, it didn't work, nothing like this slack existed back then (or if it did, i hadn't found it yet), and it wasn't worth opening a ticket with puppet about, so i stopped thinking about it ... now i'm writing net-new code for a change and the situation just arose again, i figured i'd ask - especially since there are people here who were involved in designing the puppet language, so if anybody knew ... 😁
also if i remember correctly,
$title
only exists within the scope of a defined type, not a class.
b
Raise a ticket for openvox and it can be implemented 🙂 maybe something like $self within the resource scope
v
Copy code
['/etc/xyz'].each | $f | {
    file { $f :
      ensure => file ,
      source => file("${module_name}${f}"),
  }
}
dead yes 1
b
haha
j
that would work ... but my use case was to have a single
source => ...
line that i could copy and paste all over the code base, without ever needing to manually adjust the path in the
source
attribute's value. it would cut down on human error (not least of which is my own)
v
you can make it part of a defined type?
j
i guess i could, but it would almost double the number of resources in the catalog and probably slow the agent down
b
or you build an rpm for the files you want to ship!
💯 2
v
I don't think defined type introduces an resource
only resources it defines
j
it does show up as a "node" in the catalog, even if it's not a "resource" that the agent has to actively do something with. i guess it wouldn't make it take any longer to apply the catalog, but it would slow down the process of resolving the dependency graph to figure out what order to do everything in
🤷‍♂️ 1
h
a possibility is to write a function that declares the resource given the name of the file. Or a function that returns a hash with the params to use for a file resource.