if you're using hiera, why not something like:
foo_data_webfarm_http_servers:
foo1.example.com: {
ip: '1.2.3.4',
port: '80',
}
foo2.example.com: {
ip: '2.3.4.5',
port: '80',
}
foo_data_webfarm_https_servers:
foo1.example.com: {
ip: '1.2.3.4',
port: '443',
}
foo2.example.com: {
ip: '2.3.4.5',
port: '443',
}
class foo::data {
include foo::params
file { 'foo.conf':
path => '/etc/foo.conf',
ensure => 'file',
content => template(foo_conf.erb),
mode => '0555',
}
class foo::params {
$webfarm_http_servers = hiera('foo_data_webfarm_http_servers', '')
$webfarm_https_servers = hiera('foo_data_webfarm_https_servers', '')
}
foo_conf.erb
<% http_servers = scope.lookupvar('foo::params::webfarm_http_servers')
https_servers = scope.lookupvar('foo::params::webfarm_https_servers')
-%>
#
# http servers
<% http_servers.each_pair do |key, hash| -%>
#<%=key%>
IPADDR= <%=hash['ip'] %>
PORT= <%=hash['port'] %>
<% end%>
#
# https servers
<% https_servers.each_pair do |key, hash| -%>
#<%=key%>
IPADDR= <%=hash['ip'] %>
PORT= <%=hash['port'] %>
<% end%>
<% end%>
On Aug 9, 2012, at 3:38 PM, Tim Mooney <[email protected]>
wrote:
>
> Environment: puppet 2.7.14 on both master and all clients. We're also
> using puppetlabs-stdlib and hiera, if that matters.
>
> I know this is really more of a ruby/erb question, but I've been searching
> for a couple hours and haven't turned up anything relatively close to what
> I'm trying to do, and I'm hoping someone here has had to do this and can
> provide a suggestion for how to proceed.
>
> I'm generating a configuration file from a template. The configuration
> file will need to have IP addresses in it, but I would like to be able to
> use either hostnames or IP adresses in the puppet config. This means
> that I need to be able to resolve the hostnames and turn them into IP
> addresses, probably in the template itself.
>
> Basically, given something like this in puppet:
>
> class foo::data {
>
> $webfarm = {
> http_servers => hiera('webfarm_http_servers', [
> {
> host => 'foo1.example.com',
> port => '80',
> },
> {
> host => 'foo2.example.com',
> port => '80',
> },
> {
> host => 'foo3.example.com',
> port => '80',
> },
> ]),
> https_servers => hiera('webfarm_https_servers', [
> {
> host => 'foo1.example.com',
> port => '443',
> },
> {
> host => 'foo22.example.com',
> port => '443',
> },
> {
> host => 'foo99.example.com',
> port => '443',
> },
> ]),
> }
> }
>
> I need my template to iterate over the http_servers and https_servers
> arrays and resolve the values for the host key for each element.
>
> Anyone have an example of how to do this in a template?
>
> Thanks,
>
> Tim
> --
> Tim Mooney [email protected]
> Enterprise Computing & Infrastructure 701-231-1076 (Voice)
> Room 242-J6, IACC Building 701-231-8541 (Fax)
> North Dakota State University, Fargo, ND 58105-5164
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/puppet-users?hl=en.
>
________________________________
This message may contain confidential or privileged information. If you are not
the intended recipient, please advise us immediately and delete this message.
See http://www.datapipe.com/legal/email_disclaimer/ for further information on
confidentiality and the risks of non-secure electronic communication. If you
cannot access these links, please notify us by reply message and we will send
the contents to you.
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.