Using a fact in "onlyif"

706 views
Skip to first unread message

Mike Reed

unread,
Apr 22, 2014, 2:00:21 PM4/22/14
to puppet...@googlegroups.com
Hello all,

I've been stumped by this one and I was hoping for a little help.  I'd like the below snippet to run only if the operating system is a specific version.  Because facter already has the "operatingsystemrelease" variable, I figured I'd use that but haven't had any luck getting it actually work.  Does anybody know how I would add the "onlyif" in the below snippet using the "operatingsystemrelease" fact?

I also suspect this could be the wrong way to do this and any advice would be greatly appreciated.

file { "/var/lib/nfs/rpc_pipefs" :
                       ensure   => "link" ,
                       onlyif     => "${operatingsystemrelease}" == "10.04" ,
                       target    => "/run/rpc_pipefs" ,
                }

*note: this onlyif does not work...just added for clarity in terms of what I'm trying to achieve

Thanks in advance for the help.

Cheers,

Mike

estonfer

unread,
Apr 22, 2014, 2:09:34 PM4/22/14
to puppet...@googlegroups.com
Since this shells out you could do something like this


onlyif => "[ '${::operatingsystemrelease}' = '10.04' ]",


Thanks
Eric
> --
> 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/e27094d3-6774-4e21-bfe4-fe83895b84aa%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Peter Bukowinski

unread,
Apr 22, 2014, 2:23:44 PM4/22/14
to puppet...@googlegroups.com
'onlyif' is not a valid parameter for puppet 'file' type. Conditional logic is handled by one of puppet's conditional statements (http://docs.puppetlabs.com/puppet/latest/reference/lang_conditional.html).  In this case, wrapping your file resource in an 'if' statement will suffice, but I encourage you to read the linked document to see what else is possible.

if $::operatingsystemrelease == "10.04" {
    file { "/var/lib/nfs/rpc_pipefs" :
        ensure   => "link" ,
        target    => "/run/rpc_pipefs" ,
    }
}

--
Peter Bukowinski

estonfer

unread,
Apr 22, 2014, 2:25:53 PM4/22/14
to puppet...@googlegroups.com
Hah, I wasn't paying attention at all, I thought the resource was an exec.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/3E97F4C9-17B9-4F12-81A6-DB4C8922C435%40gmail.com.

Mike Reed

unread,
Apr 22, 2014, 2:36:35 PM4/22/14
to puppet...@googlegroups.com
Hey Eric,

Thanks very much for the reply and info.  I added that in and it now looks like:


file { "/var/lib/nfs/rpc_pipefs" :
                        ensure  => "link" ,
                        onlyif  => "['${::operatingsystemrelease}' = '12.04']" ,
                        target  => "/run/rpc_pipefs" ,
                }

Unfortunately, I'm getting this error:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Invalid parameter onlyif at /etc/puppet/modules/autofs/manifests/init.pp:17

I'm trying to do some reading about this now but just wanted to get this back because I very much appreciate the help.

Cheers,

Mike

Mike Reed

unread,
Apr 22, 2014, 2:40:35 PM4/22/14
to puppet...@googlegroups.com
Hey Peter,

Thank you for the info.  I'll read the attached link and get a better understanding of this one. 

As a note, the below if statement worked like a charm.

Thanks again for the help.

Cheers,

Mike
Reply all
Reply to author
Forward
0 new messages