Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to implement puppet /etc/hosts handling using hiera as data source, but my current implementation requires data duplication because I could pass only array of strings as $name to host resource.

Is there any way to avoid such data duplication? Or maybe it is possible to use templates but keep ability to have local modifications to /etc/hosts file?

class hosts ($hosts = hiera("hosts"), $hostsdefs = hiera("hostsdefs"))  { 

  define hostentry( ) { 
    host{ $name: ip => $hostsdefs[$name][ipaddress], 
                 host_aliases => $hostsdefs[$name][host_aliases]  } 
  } 

  hostentry{ $hosts: } 
} 

YAML data for hiera:

---- 
hosts: 
  - host1.example.com 
  - host2.example.com 
hostsdefs: 
  host1.example.com: 
    ipaddress: 10.0.0.1 
    host_aliases: host1 
 host2.example.com: 
    ipaddress: 10.0.0.2 
    host_aliases: host2 
share|improve this question

1 Answer 1

up vote 1 down vote accepted

I was able to find following solution using create_resource function

class hosts ($hosts = hiera_hash("hosts"))  {
  create_resources( 'host', $hosts )
}

it needs slight modification to my original data (change hash key to ip to match resource parameter):

---- 
hosts: 
  host1.example.com: 
    ip: 10.0.0.1 
    host_aliases: host1 
 host2.example.com: 
    ip: 10.0.0.2 
    host_aliases: host2 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.