IF statement using custom fact does not work

145 views
Skip to first unread message

Pato Bongi

unread,
Jan 10, 2024, 10:35:09 AMJan 10
to Puppet Users
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": }type here
}
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".

Aaron Russo

unread,
Jan 10, 2024, 1:30:59 PMJan 10
to puppet...@googlegroups.com
If $facts['versionrepokubelocal'] is an integer I don't think your comparison will work. Try:

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

--

Aaron Russo (He/Him/His)
PIXAR | Lead Systems Engineer


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/bdb372fb-59ff-4dc6-a521-0ca7eef67b05n%40googlegroups.com.

Kenyon Ralph

unread,
Jan 11, 2024, 1:40:45 PMJan 11
to Puppet Users
Reply all
Reply to author
Forward
0 new messages