Puppet – IF statement using custom fact does not work

The if statement doesn’t work using a custom fact, i try this :

notify { "FACTER value= ${facts['versionrepokubelocal']}": }
if $facts['versionrepokubelocal'] !=  '2' {
  notify { "Upgrading repository version": }
}

I use notify before “if” for to check the value of the custom fact.
Trying with puppet apply (same with puppet agent -t on remote server) get the following output :

Notice: FACTER versionrepokubelocal value = 2
Notice: /Stage[main]/Kube::Config/Notify[FACTER versionrepokubelocal value = 2]/message: defined    'message' as 'FACTER versionrepokubelocal value = 2'
Debug: /Stage[main]/Kube::Config/Notify[FACTER versionrepokubelocal value = 2]: The container   Class[Kube::Config] will propagate my refresh event
Notice: Upgrading repository version
Notice: /Stage[main]/Kube::Config/Notify[Upgrading repository version]/message: defined 'message' as  'Upgrading repository version'

Before and after the execution I checked the value of the custom fact on the server and it is correctly valued as above :

[root@myserver manifests]$ facter versionrepokubelocal
2

I can’t understand why it doesn’t work correctly if the fact is correctly valued and the syntax of the statement is correct (tested with pdk validate and pdk test unit), it should not print “Upgrading repository version”.

The value of that facter looks like numeric so if it is numeric change your if condition with out quotes for value like below

if $facts['versionrepokubelocal'] !=  2 {   
  notify { "Upgrading repository version": } 
}

Leave a Comment