Skip to content

add hash2ini function #620

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

Closed
wants to merge 1 commit into from
Closed

Conversation

mmckinst
Copy link
Contributor

No description provided.

h.keys.each do |section|
ini << "#{settings['section_prefix']}#{section}#{settings['section_suffix']}"
h[section].each do |k, v|
ini << "#{k}#{settings['key_val_separator']}#{settings['quote_char']}#{v}#{settings['quote_char']}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will behave strangely if v is not a string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is true. I can document that a string is expected for the value, all merging of of arrays of values must be done beforehand. There's no real standard on arrays of values for ini files so I'd just leave it up to the programmer to do what is necessary rather than put the logic in hash2ini().

@hunner
Copy link
Contributor

hunner commented Jul 19, 2016

I don't know if I feel comfortable adding this to stdlib. Perhaps needing this function indicates that the inifile module needs a way to manage the entire file instead of just by parts? This is possible with custom types that implement self.instances for purging, but not with ini_setting directly yet. It could be done though!

@hunner
Copy link
Contributor

hunner commented Jul 21, 2016

So, thinking about this it would be great if the inifile module got a new ini_file type that enabled purging via evalgenerate similar to how firewallchain does it. Here's an example interface:

$hash = {
  'main' => {
    'logging' => 'INFO',
    'limit'   => 314,
    'awesome' => true,
  },
  'dev' => {
    'logging'      => 'DEBUG',
    'log_location' => '/var/log/dev.log',
  }
}
$defaults = {
  path              => '/tmp/foo.ini',
  key_val_separator => ': ',
}
create_ini_settings($hash,$defaults)

ini_file { '/tmp/foo.ini':
  purge    => true,
}

@hunner hunner closed this Jul 21, 2016
@mmckinst
Copy link
Contributor Author

feature request filed at https://tickets.puppetlabs.com/browse/MODULES-3644 . TBD how it will be done.

@mmckinst
Copy link
Contributor Author

@hunner what are your thoughts on a hash2yaml and hash2json that work the same as the above. use cases are also config files written in YAML and JSON that you want to manage 100% from puppet.

FWIW, a function similar to hash2yaml was proposed in PR #259

jhoblitt added a commit to voxpupuli/puppet-extlib that referenced this pull request Feb 7, 2023
Based on / copied from:

https://github.com/mmckinst/puppet-hash2stuff/blob/master/lib/puppet/parser/functions/hash2ini.rb

The original author, @mmckinst, claims to have haulted support for this
code and has stated no objection to this function being migrated to
extlib:

mmckinst/puppet-hash2stuff#19

The original hash2ini() function was rejected from stdlib:

puppetlabs/puppetlabs-stdlib#620
cegeka-jenkins pushed a commit to cegeka/puppet-extlib that referenced this pull request Jan 8, 2024
Based on / copied from:

https://github.com/mmckinst/puppet-hash2stuff/blob/master/lib/puppet/parser/functions/hash2ini.rb

The original author, @mmckinst, claims to have haulted support for this
code and has stated no objection to this function being migrated to
extlib:

mmckinst/puppet-hash2stuff#19

The original hash2ini() function was rejected from stdlib:

puppetlabs/puppetlabs-stdlib#620
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

Successfully merging this pull request may close these issues.

2 participants