[PRD-999] Add custom function and use Puppet Host
Add nodes_to_hosts converter function Rewrite manifest to use Puppet builtin Host type Trigger create_resources for Host generation
This commit is contained in:
parent
65dfb60325
commit
5d2260bb50
|
@ -0,0 +1,21 @@
|
|||
#
|
||||
# array_or_string_to_array.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:nodes_to_hosts, :type => :rvalue, :doc => <<-EOS
|
||||
convert nodes array passed from Astute into
|
||||
hash for puppet `host` create_resources call
|
||||
EOS
|
||||
) do |args|
|
||||
hosts=Hash.new
|
||||
nodes=args[0]
|
||||
nodes.each do |node|
|
||||
hosts[node['fqdn']]={:ip=>node['internal_address'],:host_aliases=>[node['name']]}
|
||||
notice("Generating host entry #{node['fqdn']} #{node['internal_address']} #{node['name']}")
|
||||
end
|
||||
return hosts
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
|
@ -2,26 +2,13 @@ class l23network::hosts_file ($hosts,$hosts_file="/etc/hosts") {
|
|||
|
||||
#Move original hosts file
|
||||
|
||||
exec {'copy hosts file':
|
||||
command => "cp ${hosts_file} /etc/hosts.header"
|
||||
}
|
||||
#
|
||||
concat{ $hosts_file:
|
||||
owner => root,
|
||||
group => root,
|
||||
mode => '0644'
|
||||
}
|
||||
|
||||
concat::fragment{"hosts_local":
|
||||
target => $hosts_file,
|
||||
ensure => "/etc/hosts.header",
|
||||
order => 01,
|
||||
}
|
||||
concat::fragment{"added_hosts":
|
||||
target => $hosts_file,
|
||||
content => template("l23network/hosts.erb"),
|
||||
order => 02
|
||||
$hosts=nodes_to_hosts($nodes)
|
||||
Host {
|
||||
ensure => present,
|
||||
target => $hosts_file
|
||||
}
|
||||
notify{"$hosts":}
|
||||
create_resources(host,$hosts)
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue