Hi Stefan,
I believe for the general case, the best practice is to encapsulate the
logic that can't
be expressed directly in the PuppetDSL in custom functions called from the
DSL.
Some of the features in the new experimental parser like iteration are
aimed at
reducing the need to write trivial, one-off functions.
In this particular case, you can easily re-write your RubyDSL class in the
PuppetDSL
using the standard create_resources() function:
class hosts {
create_resources('host', $::host_entries)
}
http://docs.puppetlabs.com/references/3.2.latest/function.html#createresources
If you haven't already, I'd definitely recommend adding the stdlib module,
as it
includes a ton of useful functions.
https://forge.puppetlabs.com/puppetlabs/stdlib
-Mike
On Sun, Aug 25, 2013 at 9:39 AM, Stefan Schmid <[email protected]> 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 [email protected].
> To post to this group, send email to [email protected].
> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.