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

introduce create_ini_settings #129

Merged
merged 2 commits into from
May 27, 2015
Merged

Conversation

duritong
Copy link
Contributor

@duritong duritong commented Oct 4, 2014

create_ini_settings is a function that allows you to create
ini_setting resources from a simple hash:

$settings = {  section1 => {
    setting1 => val1
  },
  section2 => {
    setting2 => val2,
    setting3 => {
      ensure => absent
    }
  }
}
$defaults = {
  path => '/tmp/foo.ini'
}
create_ini_settings($settings,$defaults)

Will create the following resources

ini_setting{'[section1] setting1':
  ensure  => present,
  section => 'section1',
  setting => 'setting1',
  value   => 'val1',
  path    => '/tmp/foo.ini',
}
ini_setting{'[section2] setting2':
  ensure  => present,
  section => 'section2',
  setting => 'setting2',
  value   => 'val2',
  path    => '/tmp/foo.ini',
}
ini_setting{'[section2] setting3':
  ensure  => absent,
  section => 'section2',
  setting => 'setting3',
  path    => '/tmp/foo.ini',
}

This allows one to create much easier classes
that should be able to manage an arbritary set of
ini-style settings without having to specify each
one of them.

@duritong
Copy link
Contributor Author

duritong commented Oct 4, 2014

The tests do not fail locally... :-/

@duritong
Copy link
Contributor Author

duritong commented Oct 4, 2014

duritong added a commit to duritong/puppet-influxdb that referenced this pull request Jan 26, 2015
So far one would have had to add for each configuration setting
to set a dedicated parameter and add an ini_setting.
This change introduces a simple hash structure to set configuration
values. This hash matches the influxdb toml file structure.
Unfortunately puppet doesn't yet have an easy way
(puppetlabs/puppetlabs-inifile#129) to do
things like that. Which means that I had to trick around a little
bit with puppet data structures.
This can be removed once create_ini_settings got merged into the
inifile module, until then this is a workaround, that makes the
configuration much more flexible.
duritong added a commit to duritong/puppet-influxdb that referenced this pull request Jan 26, 2015
So far one would have had to add for each configuration setting
to set a dedicated parameter and add an ini_setting.
This change introduces a simple hash structure to set configuration
values. This hash matches the influxdb toml file structure.
Unfortunately puppet doesn't yet have an easy way
(puppetlabs/puppetlabs-inifile#129) to do
things like that. Which means that I had to trick around a little
bit with puppet data structures.
This can be removed once create_ini_settings got merged into the
inifile module, until then this is a workaround, that makes the
configuration much more flexible.
@duritong
Copy link
Contributor Author

I would really like to see this getting merge. Would make things like jdowning/puppet-influxdb#20 wayyy easier....

create_ini_settings is a function that allows you to create
ini_setting resources from a simple hash:

    $settings = {  section1 => {
        setting1 => val1
      },
      section2 => {
        setting2 => val2,
        setting3 => {
          ensure => absent
        }
      }
    }
    $defaults = {
      path => '/tmp/foo.ini'
    }
    create_ini_settings($settings,$defaults)

Will create the following resources

    ini_setting{'[section1] setting1':
      ensure  => present,
      section => 'section1',
      setting => 'setting1',
      value   => 'val1',
      path    => '/tmp/foo.ini',
    }
    ini_setting{'[section2] setting2':
      ensure  => present,
      section => 'section2',
      setting => 'setting2',
      value   => 'val2',
      path    => '/tmp/foo.ini',
    }
    ini_setting{'[section2] setting3':
      ensure  => absent,
      section => 'section2',
      setting => 'setting3',
      path    => '/tmp/foo.ini',
    }

This allows one to create much easier classes
that should be able to manage an arbritary set of
ini-style settings without having to specify each
one of them.
@duritong
Copy link
Contributor Author

I did what was proposed by @cmurphy in duritong@4ab62d3#commitcomment-9479240 => remove the changes to .gitignore add forcing the files on the index , rebased the branch onto current master and also squeezed together the commits

@wcooley
Copy link

wcooley commented Mar 23, 2015

The more that I look at this, the more that I like it. I was going to suggest that the same thing can be done with create_resources from stdlib, but in constructing an example I realized how much cleaner create_ini_resources would be. I currently manage my puppet.conf like this and it isn't quite as nice. I start with Hiera like this:

puppet::config::puppet_conf::master:
  'puppet.conf/master/storeconfigs':
    setting:  'storeconfigs'
    value:    true
  'puppet.conf/master/storeconfigs_backend':
    setting:  'storeconfigs_backend'                                             
    value:    'puppetdb'
  'puppet.conf/master/reports':
    setting:  'reports'
    value:    'cimlog,puppetdb'

puppet::config::puppet_conf::agent:
  'puppet.conf/agent/runinterval':
    setting:  'runinterval'
    value:    '900'
  'puppet.conf/agent/report':
    setting:  'report'
    value:    true
  'puppet.conf/agent/graphdir':
    setting:  'graphdir'
    value:    '/var/lib/puppet/state/graphs'

And then use create_resources:

create_resources(ini_setting, hiera('puppet::config::puppet_conf::agent'), { 'path' => '/etc/puppet/puppet.conf', 'section' => 'agent'})
create_resources(ini_setting, hiera('puppet::config::puppet_conf::master'), { 'path' => '/etc/puppet/puppet.conf', 'section' => 'master'})

There is lots of redundancy with the resource titles and one has to either make multiple create_resources calls with each section or add each section repeatedly to the Hiera data. Using create_ini_resources could use only one function call and reduce the Hiera data considerably.

@duritong
Copy link
Contributor Author

@wcooley this is exactly what it is for 😄 It should get merged!

found some dead code to remove
@duritong
Copy link
Contributor Author

Any news?

@duritong
Copy link
Contributor Author

Ping

hunner added a commit that referenced this pull request May 27, 2015
@hunner hunner merged commit c72bfbb into puppetlabs:master May 27, 2015
@poikilotherm
Copy link
Contributor

@duritong, I just stumbled over this neat little function while searching for a more elegant way to inject settings from Hiera. It saved me from a LOT of pain. Why is there no word about it in the README?

@duritong
Copy link
Contributor Author

So let's update the README then. Do you like to propose a PR?

@poikilotherm
Copy link
Contributor

If you'd like me too - sure. Shall I open a ticket, too? (If yes: MODULES project? Or do puppetlabs modules have another tracker?)

@poikilotherm
Copy link
Contributor

@duritong: Please take look at https://github.com/poikilotherm/puppetlabs-inifile/tree/fix/master/add_create_ini_settings_to_readme#function-create_ini_settings before I open a ticket and/or PR.

Do you think this is a sufficient doc?

@duritong
Copy link
Contributor Author

Looks good to me, I guess more documentation is always welcomed.

@poikilotherm
Copy link
Contributor

Right. Then I'll open a PR and a ticket... This will take some time to complete. :-/

Edit: see https://tickets.puppetlabs.com/browse/MODULES-2158

cegeka-jenkins pushed a commit to cegeka/puppet-inifile that referenced this pull request Oct 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants