Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make sensu::plugins do an array merge in hiera #387

Closed
devopsprosiva opened this issue Jul 22, 2015 · 2 comments
Closed

How to make sensu::plugins do an array merge in hiera #387

devopsprosiva opened this issue Jul 22, 2015 · 2 comments

Comments

@devopsprosiva
Copy link

Hi,

I use hiera for pushing plugins using sensu::plugins. However, since the parameter plugins is an array, hiera is not doing a merge of different sensu::plugins declarations at various hierarchy levels.

For example, in my global.yaml I have a common set of plugins defined which have to be pushed to all nodes. I also have some specific plugins that have to be pushed based on the role. With the current configuration hiera is picking up only the role specific plugins.

Is there anyway to write a wrapper class on top of the sensu class to make the plugins do an array merge across hierarchies?

Thanks,
Siva

@hurrycaine
Copy link
Contributor

Yes you can do it in a class that calls sensu.

Have you looked at
https://docs.puppetlabs.com/hiera/1/lookup_types.html#array-merge
and
https://docs.puppetlabs.com/hiera/1/puppet.html

In a nutshell if you do not use the function hiera_array (automatic parameter lookup) it will use the priority which is what you are seeing...

Priority Only

Automatic parameter lookup can only use the priority lookup method.

This means that, although it can receive any type of data from Hiera (strings, arrays, hashes), it cannot merge values from >multiple hierarchy levels; you will only get the value from the most-specific hierarchy level.

If you need to merge arrays or merge hashes from multiple hierarchy levels, you will have to use the hiera_array or hiera_hash >functions in the body of your classes.

So in your puppet module you could use this function and then call sensu

class sensu_install::profiles::sensu_server(
    $plugins = hiera_array('sensu_install::profiles::sensu_server::plugins')
    # or because of function you do not have to fully qualify
    #$plugins = hiera_array('plugins')
){
    class {'sensu':
        plugins => $plugins
    }
}

You may have to play with hiera deeper merge, though it sounds native might work in your scenario.

 # /etc/puppet/hiera.yaml
    ---
    :backends:
      - yaml
    :logger: puppet
    :hierarchy:
      - "%{hostname}"
      - common
    :yaml:
      :datadir: /etc/puppet/hieradata
    # options are native, deep, deeper
    :merge_behavior: deeper

The problem with the hiera functions if if the value does not exist it Errors and stop immediately but you can do a default ... which could later be ignored in the define... so it is possible but it is much easier to have a calling class (this may even work in a node definition as the hiera functions can go in the body of puppet)

@jlambert121
Copy link
Contributor

I'm going to go ahead and close this as I think it is hiera config rather than an issue with this module and there has been no activity for a few weeks. Let us know if this is incorrect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants