In your place I would probably use a fact to get the names, see inline. Fair 
warning that I haven't tested any of this. It may even damage your server as 
written!

On Tue, Jul 07, 2015 at 03:22:44AM -0700, Andreas Dvorak wrote:
>    Hello,
> 
>    I have a module to copy files /etc/hostname.* in Solaris. But the
>    interface name can be any.
> 
>    e.g.
>    networking/file/vm6742/hostname.e1000g0
>    networking/file/vm6742/hostname.e1000g1

I am assuming that "vm6742" is the hostname. Also that you have the 
stringify_facts config option set to false. Also that you find it acceptable 
for an agent run to partially fail if the source file does not exist. If not, 
use a template, that way you will find out via catalog compilation failure.

https://docs.puppetlabs.com/puppet/latest/reference/lang_facts_and_builtin_vars.html#handling-boolean-facts-in-older-puppet-versions

A custom fact (pardon the cheap ruby, note how it's a hash of hashes since the 
define later needs hashes):

array = Dir.glob('/etc/hostname.*')
hash = {}
array.each do |item|
  hash[item] = {}
end
Facter.add('hostnamefiles') do
  setcode do
    hash
  end
end

https://docs.puppetlabs.com/facter/2.4/custom_facts.html

Then a define, wherein we extract the source based on the resource title and 
hostname fact and manage the file resource:

define networking::hnf {
  $sourcefile = inline_template('<%= File.basename(@title) %>')
  $source = "puppet:///modules/networking/${::hostname}/${sourcefile}"
  file { $title:
    source => $source,
  }
}

https://docs.puppetlabs.com/puppet/latest/reference/lang_defined_types.html

And in networking/manifests/init.pp something to create the resources (or using 
each iteration for puppet4):

create_resources('networking::hnf', $::hostnamefiles)

Two big caveats to this approach:

It's more difficult to troubleshoot create_resources than plain 
listed-in-manifests resources.

This is verging on an anti-pattern, managing based on what's on the host. 
Better to affirmatively control all aspects of your host. Know what interfaces 
they get before you install the OS.

Minor caveat:

You will need every single hostname.whatever file listed in your module for the 
approach above. If you needed the hostname.whatever file to only contain the 
hostname of the VM, without per-interface customization, you could just do that 
and skip maintaining all the files:

define networking::hnf {
  file { $title:
    content => "${::hostname}\n",
  }
}

(Not sure about that \n, don't have a Solaris host to check.)

>    I do not want to user file with recurse because the files in /etc have
>    different permissions.
> 
>    Is it possible to get a file list of the source to use that in the file
>    resource or is there an other solution?
> 
>    Best regards
>    Andreas
> 
>    --
>    You received this message because you are subscribed to the Google Groups
>    "Puppet Users" group.
>    To unsubscribe from this group and stop receiving emails from it, send an
>    email to [1]puppet-users+unsubscr...@googlegroups.com.
>    To view this discussion on the web visit
>    
> [2]https://groups.google.com/d/msgid/puppet-users/1b0199b1-7e9b-47ff-a08a-10ef8ae6c5bc%40googlegroups.com.
>    For more options, visit [3]https://groups.google.com/d/optout.
> 
> References
> 
>    Visible links
>    1. mailto:puppet-users+unsubscr...@googlegroups.com
>    2. 
> https://groups.google.com/d/msgid/puppet-users/1b0199b1-7e9b-47ff-a08a-10ef8ae6c5bc%40googlegroups.com?utm_medium=email&utm_source=footer
>    3. https://groups.google.com/d/optout

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/20150707135511.GA16364%40iniquitous.heresiarch.ca.
For more options, visit https://groups.google.com/d/optout.

Reply via email to