There's a host type built into puppet. 

--
Brian Lalor
bla...@bravo5.org

On Aug 25, 2013, at 9:39 AM, Stefan Schmid <sc...@web.de> wrote:

> Hi
> 
> I am new to puppet and need to manage host entries in file /etc/hosts as 
> follows on node mail.example.com and db.example.com. I do not want to manage 
> the whole file /etc/hosts with puppet, only a few entries.
> 
> puppet version 3.2.1
> 
> node mail.example.com, file /etc/hosts:
> (..)
> 172.16.89.96    ldapmaster.example.com    ldapmaster ldap
> 172.16.89.85    sms.example.com    sms sms-gateway
> (..)
> 
> node db.example.com, file /etc/hosts:
> (..)
> 172.16.89.80    abc.example.com abc
> 172.16.89.81    xyz.example.com xyz bigben
> (..)
> 
> In general, a node may have 0 to n host entries. The number of host entries 
> on a node A may differ from the number host entries on a node B. A certain 
> host entry ( IP-Address  Full-Qualified-Hostname  Short-Hostname)
> may be in the file /etc/hosts on 0 to n nodes concurrently.
> 
> To manage the above host entries on node mail.example.com and db.example.com 
> I used Ruby DSL as follows, then I learnt that Ruby DSL is deprecated. What 
> is the alternative to Ruby DSL ? Any hint
> would be helpful.
> 
> A puppet module using Ruby DSL:
> 
> puppetmaster:/etc/puppet/modules/hosts/manifests # cat init.rb 
> 
> hostclass :hosts do
> 
>  entries = scope.lookupvar("hosts_entries")
> 
>  raise Puppet::ERROR,
>   "hosts_entries must be a Hash" unless entries.kind_of?(Hash)
> 
>  entries.each do |title, parameters|
> 
>  host( title,
>   :ensure       => parameters["ensure"],
>   :target       => parameters["target"],
>   :ip           => parameters["ip"],
>   :host_aliases => parameters["host_aliases"])
>  end
> end
>  
> puppetmaster:/etc/puppet/modules/hosts/manifests #
> 
> 
> Basic ENC script output for the Ruby DSL and node mail.example.com :
> (..)
> ---
> parameters:
>  hosts_entries:
>   sms.example.com:
>     ensure: present
>     target: /etc/hosts
>     ip: 172.16.89.85
>     host_aliases: 
>      - sms 
>      - sms-gateway
>   ldapmaster.example.com:
>     ensure: present
>     target: /etc/hosts
>     ip: 172.16.89.96
>     host_aliases: 
>      - ldapmaster 
>      - ldap
> classes:
>  - hosts
> (..)
> 
> 
> Basic ENC script output for the Ruby DSL and node db.example.com :
> (..)
> ---
> parameters:
>  hosts_entries:
>   abc.example.com:
>     ensure: present
>     target: /etc/hosts
>     ip: 172.16.89.80
>     host_aliases: abc
>   xyz.example.com:
>     ensure: present
>     target: /etc/hosts
>     ip: 172.16.89.81
>     host_aliases: 
>      - xyz 
>      - bigben
> classes:
>  - hosts
> (..)
> 
> 
> Thanks.
> 
> -- 
> 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 post to this group, send email to puppet-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/puppet-users.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
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 post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to