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

Overwrite single value with hiera #22

Open
linuxmail opened this issue Mar 24, 2017 · 4 comments
Open

Overwrite single value with hiera #22

linuxmail opened this issue Mar 24, 2017 · 4 comments

Comments

@linuxmail
Copy link

linuxmail commented Mar 24, 2017

hi,

I'm new to Hiera and I want to have the most parts as a classical manifest (profile::mysql::maxscale). but want to overwrite some lines, for example "password/user" or "servers" ...

Is that possible?

I tried the following:

maxscale::services_conf:
  default:
    config:
      Galera Monitor:
        user: 'foorbar'
        password: 'topsecret12354#'
        server: 'mariadb3.foo.example.com'

But it seems to be ignored. If it doesn't work, I expect, that I have to change the fixed name in the manifest, with variables. Right?

cu denny

@aerostitch
Copy link
Contributor

Hi @linuxmail ,

Can you show me your profile::mysql::maxscale profile please?
What do you mean by "doesn't work"? What does the generated /etc/maxscale.conf file on the server look like vs expected?
Your hiera config looks correct. It's missing the rest of the Galera Monitor service config I guess.

Thanks
Joseph

@linuxmail
Copy link
Author

linuxmail commented Mar 24, 2017

hi @aerostitch

that is our config profile and it works so far so good. But on one or two servers I want a slightly different configuration, for example the password hash, or user/server ..

With my knowledge, I would change the hardcoded lines with variables, getting from hiera, maybe with defaults e.g.

$maxscale_servers = hiera('maxscale::servers', 'mariadb1,mariadb2')

# profile::mysql::maxscale
# modules/profile/manifests/mysql/maxscale.pp
class profile::mysql::maxscale {
  class { '::maxscale':
    install_repository => false,
    repo_custom_url    => 'http://foo.bar/debian/',
    repo_fingerprint   =>  '56045F842...CBFA4C0',
    services_conf      => {
      'default'        => {
        ensure         => 'running',
        logdir         => '/var/log/maxscale',
        datadir        => '/var/lib/maxscale/data',
        piddir         => '/var/run/maxscale',
        svcuser        => 'maxscale',
        svcgroup       => 'maxscale',
        errmsgsys_path => '/var/lib/maxscale',
        configfile     => '/etc/maxscale.cnf',
        'config'       => {
          'maxscale'   => {
            'threads'  => 2
          },
          'Galera Monitor'   => {
            'type'           => 'monitor',
            'module'          => 'galeramon',
            'user'           => 'maxscale',
            'passwd'         => '<secrethash>',
            'servers'       => 'mariadb1,mariadb2',
            'monitor_interval' => '1000',
            'disable_master_failback' => true,
            'detect_stale_master' => true,
            'use_priority' => true,
            'detect_replication_lag' => true,
          },
          'RW Split Router'   => {
            'type'            => 'service',
            'router'         => 'readwritesplit',
            'user'        => 'maxscale',
            'servers' => 'maria1db,mariadb2',
            'passwd'        => '<secrethash>',
            'max_slave_connections' => '100%',
            'localhost_match_wildcard_host' => '1',
            'enable_root_user' => '1',
            'router_options' => 'slave_selection_criteria=LEAST_GLOBAL_CONNECTIONS',
          },
          'Debug Interface'   => {
            'type'            => 'service',
            'router'          => 'debugcli',
          },
          'CLI'      => {
            'type'   => 'service',
            'router' => 'cli',
          },
          'Debug Listener'   => {
            'type'           => 'listener',
            'service'        => 'Debug Interface',
            'protocol'       => 'telnetd',
            'address'        => '127.0.0.1',
            'port'           => 4442,
          },
          'CLI Listener'   => {
            'type'         => 'listener',
            'service'      => 'CLI',
            'protocol'     => 'maxscaled',
            'port'         => 6603,
          },
          'ina-mariadb1'   => {
            'type'         => 'server',
            'address'      => '192.168.1.51',
            'protocol'     => 'MySQLBackend',
            'port'         => 3306,
          },
          'ina-mariadb2'   => {
            'type'         => 'server',
            'address'      => '192.168.1.50',
            'protocol'     => 'MySQLBackend',
            'port'         => 3306,
          },
        },
      },
    },
  }
}

cu denny

@aerostitch
Copy link
Contributor

aerostitch commented Mar 24, 2017

We actually don't deep merge the default config with the configuration provided so you would need to declare the entire config inside your hash (can be done in hiera).
What I personally would do is have the following in your profile:

class profile::mysql::maxscale {
  include '::maxscale'
}

And have in hiera the config that would look like (You could have, for example maxscale::install_repository, maxscale::repo_custom_url and maxscale::repo_fingerprint inside your common.yaml to be applied to all your configs by default):

maxscale::repo_custom_url: 'http://foo.bar/debian/'
maxscale::repo_fingerprint: '56045F842...CBFA4C0'
maxscale::services_conf:
  'default':
    datadir: '/var/lib/maxscale/data'
    config:
      maxscale:
        threads: 2
      'Galera Monitor':  
        type: 'monitor'
        module: 'galeramon'
        user: 'maxscale'
        passwd: '<secrethash>'
        servers: 'mariadb1,mariadb2'
        monitor_interval: 1000
        disable_master_failback: true
        detect_stale_master: true
        use_priority: true
        detect_replication_lag: true
      'RW Split Router':
        type: 'service'
        router: 'readwritesplit'
        user: 'maxscale'
        servers: 'maria1db,mariadb2'
        passwd: '<secrethash>'
        max_slave_connections: '100%'
        localhost_match_wildcard_host: 1
        enable_root_user: 1
        router_options: 'slave_selection_criteria=LEAST_GLOBAL_CONNECTIONS'
      'Debug Interface':
        type: 'service'
        router: 'debugcli'
      'CLI':
        type: 'service'
        router: 'cli'
      'Debug Listener':
        type: 'listener'
        service: 'Debug Interface'
        protocol: 'telnetd'
        address: '127.0.0.1'
        port: 4442
      'CLI Listener':
        type: 'listener'
        service: 'CLI'
        protocol: 'maxscaled'
        port: 6603
      'ina-mariadb1':
        type: 'server'
        address: '192.168.1.51'
        protocol: 'MySQLBackend'
        port: 3306
      'ina-mariadb2':
        type: 'server'
        address: '192.168.1.50'
        protocol: 'MySQLBackend'
        port: 3306

Note: the values that are already declared as the default in the define (https://github.com/tubemogul/puppet-maxscale/blob/master/manifests/instance.pp) don't need to be re-declared.
You can use the hiera example shown in the "Working with a single instance" paragraph of the readme as an example.

Does that makes sense?

Try to avoid hard-coded stuffs, it always ends up being a mess. ;)

@linuxmail
Copy link
Author

hi @aerostitch

thanks for the example, but do I think right, that .. if we have 5 hosts, all with some slightly different configurations, I need the whole config (except the package defaults) ? Hmm, what I didn't say: I have the option ":merge_behavior: deeper" in hiera.yaml, so I thought, that it should work :-)
Maybe, I red something about - roles/%{calling_class_path} (in my case profile/{calling_class_path} so I can move the content from the node.yaml to profile and overwrite only what is needed.

Hhu .. so many new things :-)

Thanks for the help 👍

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

2 participants