Puppet Tips&Tricks: checking if a value is present in an array

I tend to create fairly ubiquitous defines, which allow for a lot of functionality. For that, it would be nice if you could tell puppet “if value X is present in array Y, do this”. I made it a feature request for puppet (#3871), which was luckily accepted and will be implemented in the next version of puppet. However, for the time being I needed this fixed. So I spend some time creating an ugly solution for this in older versions of puppet. Hope it helps someone!

# Setup additional services for this vhost, if any are required.
# Start with a general check to prevent a lot of work when it's
# not needed.
if $allow != "" {
           # FIXME Ideally we want something that simply does
           #  for i in allow do include $http::allow_$i
           # but that doesn't work (yet?).
           # W00t! That's going to be added in 2.6! #3871
           if inline_template("<%= allow.include?('php5') %>") == "true" {
                     include allow_php5
           }
           if inline_template("<%= allow.include?('rewrite') %>") == "true" {
                     include allow_rewrite
           }
           if inline_template("<%= allow.include?('ruby') %>") == "true" {
                     include allow_ruby
           }
           if inline_template("<%= allow.include?('python') %>") == "true" {
                     include allow_python
           }
}

Tags: , , , , ,


Comments are closed.

Kumina designs, builds, operates and supports Kubernetes solutions that help companies thrive online. As Certified Kubernetes Service Partner, we know how to build real solutions.