Check if Value is Present in Array in Puppet

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, February 05, 2015

Follow me on Twitter as @mattiasgeniar

I somehow keep having to google this, and the first hits are bugreports or old posts (pre 2010) that require inlined Ruby code for Puppet 2.7. There’s an easier way to check this.

To see if a variable value is present in an array, use the following.

if ! ($ensure in [ 'present', 'absent' ]) {
   ...
}

The above checks if the variable $ensure consists of either the value ‘present’ or ‘absent’.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.