wso2apache-axispuppetwso2-as

Puppet fill template values using params.pp complex data structures


I have the following data structure in my params.pp file at /etc/puppet/modules/appserver/manifests

class appserver::params {
        $servers = {
                appserver-mgr => { axis2   => {subDomain => 'mgt',},
                                   carbon  => {subDomain => 'mgt',},
                                   serverOptions => '-Dsetup',  },
                appserver-wkr => { axis2   => {subDomain => 'worker',},
                                   carbon => {subDomain => 'worker',},
                                   serverOptions => '-DworkerNode=true',  },
        }

        $serversDefaults = {
                clustering => 'true',
        }
}

In my template file (axis2.xml.erb at /etc/puppet/modules/appserver/templates). I have to fill the following field.

<property name="subDomain" value="<%= @subDomain %>"/>

How can I fill this subDomain value using the above data structure in params.pp file?


Solution

  • The hash translates to Ruby quite literally.

    <property name="subDomain" value="<%= @servers['appserver-mgr']['carbon']['subDomain'] %>"/>
    

    This assumes that $servers has the value of appserver::params::server in the scope of the template expansion.