Ask Your Question

If condition not working

asked 2017-11-27 03:05:09 -0600

keya gravatar image

updated 2017-11-27 03:05:50 -0600

I have written the script :

class test 
    if ($admin=='false')
        notice("Non Admin user")
    if ($admin=='true')
        notice("Admin User")

I am setting the value of 'admin' variable using Facter as "set Facter_ admin=true" or "set Facter_ admin=false". When I run this script, the message is not being displayed on the console; control it is not going inside the if condition. Any idea what I am doing wrong? I am calling this class from a manifest :

node default 
    include test
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-11-27 04:12:23 -0600

stivesso gravatar image

updated 2017-11-27 04:18:28 -0600

Hi Keya,

If you want to display the message on the console, use notify instead of notice (You can click on the link to see the difference, but basically, notice is a function that logs a message on the server at level notice while notify is a resource type that sends an arbitrary message to the agent run-time log...).

I also advise that you use export FACTER_admin=true
Find below the code with this small modification:

class test {

  if ($::admin=="false") {
    notify { "Non Admin user": }
  if ($::admin=="true") {
    notify { "Admin user": }

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-11-27 03:05:09 -0600

Seen: 50 times

Last updated: Nov 27 '17