Puppet hiera variable

22 views
Skip to first unread message

Jagga Soorma

unread,
Apr 4, 2018, 1:13:20 AM4/4/18
to Puppet Users
Hi Guys,

I am using foreman and puppet to provision/manage systems.  I have a simple motd module that I was using for all my systems but now have a need to setup a different motd for a specific hostgroup/type of systems.  So, I though I would use the hostgroup hiera setup from foreman/puppet to decide which motd to use.  I wrote something quickly to test but have unexpected results and was hoping someone here can help me make sense of this:

--
my hostgroup for system 1 is CSOE73_Prod/hpc/misc and for system 2 is CSOE73_Prod/hpc/compute.  So I decided to write the code this way:

if [$hostgroup == 'CSOE73_Prod/hpc/misc'] {
  file { "/etc/motd":
    ensure => file,
    content => template('clientos/motd.erb')
     }

else {
  file { "/etc/motd":
    ensure => file,
    source => 'puppet:///modules/clientos/etc/motd',
    mode => 644,
    owner => 'root',
    group => 'root',
    }
}
--

However, for both systems the motd.erb template is being applied.  However, my expectation was that for system 2 it would just use the files/etc/motd file.  Is it maybe the backslash in CSOE73_Prod/hpc/misc that might be throwing it off?  Am I going about this totally the wrong way?  

Any help would be greatly appreciated!

Thanks,
-J

Peter Bukowinski

unread,
Apr 4, 2018, 1:50:08 AM4/4/18
to puppet...@googlegroups.com
Jagga,

It’s a simple error. You need to remove the square brackets from around your conditional test. Puppet is evaluating it as an array, and since puppet treats all non-boolean values (other than undef) as true, you will never get to the else block.

Peter

Jagga Soorma

unread,
Apr 4, 2018, 1:34:19 PM4/4/18
to Puppet Users
Thanks Peter :)  that fixed the issue.  Appreciate your help with this.

-J
Reply all
Reply to author
Forward
0 new messages