Problem using hiera variable in templates

43 views
Skip to first unread message

Christian Charpentier

unread,
Jun 24, 2014, 5:53:37 AM6/24/14
to puppet...@googlegroups.com
Hi,

I'm trying to use variables stored in hiera files in module templates. I read it's better to avoid to use hiera function in templates so i tried to get the hiera value in the config.pp manifest with a local variable.
Then to use the local variable in the template, but it doesn't work.

common.yaml

---
apache_packages_list:
 - apr-1.4.8
 - apr-devel-1.4.8
 - apr-util-1.5.2
 - apr-util-devel-1.5.2
 - distcache-1.4.5
 - distcache-devel-1.4.5
 - httpd-2.4.6
 - httpd-tools-2.4.6
 - mod_ssl-2.4.6
 
accounts_conf_filename: accounts.victorbuckservices.com.conf
accounts_conf_balancer_filename: accounts.victorbuckservices.com.balancer.conf
certificate_filename: all.dev.victorbuckservices.com.crt
key_filename: all.dev.victorbuckservices.com.key

ServerName: accounts.dev.victorbuckservices.com
ServerAdmin: te...@victorbuckservices.com

SSLCertificateFile: /etc/pki/tls/certs/all.dev.victorbuckservices.com.crt
SSLCertificateKeyFile: /etc/pki/tls/private/all.dev.victorbuckservices.com.key
 

config.pp

class apache::config {
    $accounts_conf_filename                = hiera('accounts_conf_filename')
    $accounts_conf_balancer_filename  = hiera('accounts_conf_balancer_filename')
    $crt_filename                                 = hiera('certificate_filename')
    $key_filename                                = hiera('key_filename')
   
    $servername = hiera('ServerName')
    $serveradmin = hiera('ServerAdmin')

   
    file {"/etc/httpd/conf.d/$accounts_conf_filename":
        ensure   => file,
        content  => template("/etc/puppet/hieradata/$accounts_conf_filename.erb"),
    }
 
    file {"/etc/httpd/conf.d/$accounts_conf_balancer_filename":
        ensure   => file,
        content  => template("/etc/puppet/hieradata/$accounts_conf_balancer_filename"),
    }
   
    file {'/etc/pki/tls/certs/$crt_filename':
        ensure   => file,
        content  => template("/etc/puppet/hieradata/$crt_filename"),
    }

    file {'/etc/pki/tls/private/$key_filename':
        ensure   => file,
        content  => template("/etc/puppet/hieradata/$key_filename"),
    }

}

accounts.victorbuckservices.com.conf.erb

<VirtualHost accounts.dev.victorbuckservices.com:80>
   ServerName <% ServerName =  scope.lookupvar('apache::config::servername') %>
    ServerAdmin <% ServerAdmin = scope.lookupvar('apache::config::serveradmin') %>

I also tried syntax as follow:
ServerName <%= scope.function_hiera('ServerName') %>
ServerName <%= @servername %>

But i doesn't works neither.


Any idea or suggestion to make this right?

Cheers,
Christian

Christian Charpentier

unread,
Jun 30, 2014, 3:36:22 AM6/30/14
to puppet...@googlegroups.com
It was due to some kind of syntax error (= missing) :
<%=  scope.lookupvar('apache::config::servername') %>

Reply all
Reply to author
Forward
0 new messages