variable not replace when come from hiera

86 views
Skip to first unread message

fpommier

unread,
Nov 23, 2012, 11:03:20 PM11/23/12
to puppet...@googlegroups.com
Hi,
I use puppet 2.7.16
i try to use hiera to store file data
yaml file :
apt:
  '/etc/apt/preferences.d':
     ensure: directory
     recurse: true
     source: "puppet:///$environment/$module_name/preferences.d"

When i try to use it with create_resource , it fail because $environment and $module_name are not replace.
  $instance_apt = hiera("apt")
  $defauts = hiera("apt.defauts")
  create_resources(file,$instance_apt,$defauts)

-> 
err: /Stage[main]/Apt/File[/etc/apt/preferences.d]: Failed to generate additional resources using 'eval_generate: Error 400 on SERVER: Cannot find file: Invalid path '$environment'


When i do the same with a hash, it work :
  $defauts = hiera("apt.defauts")
  $instance_apt = {
     "/etc/apt/preferences.d" => {   
     ensure => directory,
     recurse => true,
     source => "puppet:///$environment/$module_name/preferences.d",
     }  
  }
  create_resources(file,$instance_apt,$defauts)

Is it a bug or a lack of functionality ?

Regards
Fred.




Craig Dunn

unread,
Nov 25, 2012, 10:45:14 AM11/25/12
to puppet...@googlegroups.com
On 23/11/2012 23:03, fpommier wrote:
Hi,
I use puppet 2.7.16
i try to use hiera to store file data
yaml file :
apt:
  '/etc/apt/preferences.d':
     ensure: directory
     recurse: true
     source: "puppet:///$environment/$module_name/preferences.d"


Try this with;

       source: "puppet:///%{environment}/%{module_name}/preferenced.d

Your source path confuses me a bit anyway, surely your environment dictates your modulepath and this should just be puppet:///modules/%{module_name}/preferences.d ?

Regards
Craig

-- 
Craig Dunn
Professional Services
Puppet Labs Inc.
http://www.puppetlabs.com

jcbollinger

unread,
Nov 26, 2012, 2:53:40 PM11/26/12
to puppet...@googlegroups.com


On Sunday, November 25, 2012 4:45:27 AM UTC-6, Craig Dunn wrote:
On 23/11/2012 23:03, fpommier wrote:
Hi,
I use puppet 2.7.16
i try to use hiera to store file data
yaml file :
apt:
  '/etc/apt/preferences.d':
     ensure: directory
     recurse: true
     source: "puppet:///$environment/$module_name/preferences.d"


Try this with;

       source: "puppet:///%{environment}/%{module_name}/preferenced.d

Your source path confuses me a bit anyway, surely your environment dictates your modulepath and this should just be puppet:///modules/%{module_name}/preferences.d ?


And, therefore, it's probably not useful to interpolate even the %{module_name}.  The datum is probably used only by one module, almost certainly having the same name in every environment, and that module knows its own name.  In fact, the whole thing probably ought to be written into the relevant class instead of being loaded indirectly via hiera.


John

fpommier

unread,
Nov 28, 2012, 9:05:22 PM11/28/12
to puppet...@googlegroups.com
Hi Craig,
Your solution solve my problem.
Thank a lot.
I use this path because i want to seperate statics files and data hiera from puppet module (for versionning and test).
And i want also have different data with each environment.
My fileserver.conf :
[developpement]
  path /etc/puppet/puppetData/developpement/fichiers
  allow *

[production]
  path /etc/puppet/puppetData/production/fichiers
  allow *

When i try this, it don't work
[fichiers]
  path /etc/puppet/puppetData/%{environment}/fichiers       (or  $environment)
  allow *

May be not the best solution but it work now.

Thank again.
Fred
Reply all
Reply to author
Forward
0 new messages