Hi. I would like to setup my manifests, so that variable data is gathered from hiera, if it''s available there, and if not, then to fallback on some predefined value... Something like this: $my_var = hiera(''myvar'') || ''base_value'' So if there is no myvar in hiera data, that manifest falls back to base_value. Is that possible somehow? -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Wednesday, October 3, 2012 10:03:17 AM UTC-5, Jakov Sosic wrote:> > Hi. > > I would like to setup my manifests, so that variable data is gathered > from hiera, if it''s available there, and if not, then to fallback on > some predefined value... > > Something like this: > > $my_var = hiera(''myvar'') || ''base_value'' > > So if there is no myvar in hiera data, that manifest falls back to > base_value. Is that possible somehow? > >$my_var = hiera(''somevar'', ''some_default'') will do exactly that. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/5vVlXJWbRIUJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Wed, Oct 3, 2012 at 11:02 AM, Jakov Sosic <jsosic@srce.hr> wrote:> Hi. > > I would like to setup my manifests, so that variable data is gathered > from hiera, if it''s available there, and if not, then to fallback on > some predefined value...The "right" thing is to put that default somewhere in hiera. What we do is: cat /etc/puppet/hiera.yaml --- :hierarchy: - %{fqdn} - %{role} - %{group} - common :backends: - yaml - puppet :yaml: :datadir: /etc/puppet/environments/%{environment}/data :puppet: :datasource: data so there is both a common.yaml file in your data directory for local fall back, and an ultimate fallback to puppet variables defined in <class>::data, so we can manage defaults with in the module for example our local ntp module has them in modules/ntp/data.pp -Jon> Something like this: > > $my_var = hiera(''myvar'') || ''base_value'' > > So if there is no myvar in hiera data, that manifest falls back to > base_value. Is that possible somehow? > > > > -- > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Take a look at Example42''s Next Gen modules on github. They all do what you''re asking about and a bit more There is a routine defined within the puppi module, that the rest of the modules use to lookup variable values. Defaults are assigned in params.pp which the main class inherits and they are defined as parameters. So, the variable can be set via a default, parameter, or hiera. This makes it very flexible. Steven> Date: Wed, 3 Oct 2012 17:02:45 +0200 > From: jsosic@srce.hr > To: puppet-users@googlegroups.com > Subject: [Puppet Users] hiera and fallback to params? > > Hi. > > I would like to setup my manifests, so that variable data is gathered > from hiera, if it''s available there, and if not, then to fallback on > some predefined value... > > Something like this: > > $my_var = hiera(''myvar'') || ''base_value'' > > So if there is no myvar in hiera data, that manifest falls back to > base_value. Is that possible somehow? > > > > -- > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.