Ask Your Question
0

Duplicate declaration error when using Ini_setting

asked 2015-12-08 23:53:58 -0500

CoryH gravatar image

I'm getting this error when using ini_setting and hiera

"Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Function Call, Duplicate declaration: Ini_setting[[database] connection] is already declared; cannot redeclare at /etc/puppetlabs/code/environments/production/manifests/site.pp:50:3 on node lib-glance.liberty.local"

I know why i am getting the error, here is my puppet code

node 'lib-glance' {

include glance::api
include glance::registry


}

class glance::api ($settings,){
#  validate_hash($apisettings)
  $defaults = { 'path' => '/etc/glance/glance-api.conf' }
  create_ini_settings($settings, $defaults)
}
class glance::registry($settings,){
 # validate_hash($registrysettings)
  $regdefaults = { 'path' => '/etc/glance/glance-registry.conf' }
  create_ini_settings($settings, $regdefaults)
}

And here is the associated heira

glance::api::settings:
        DEFAULT:
                notification_driver: "noop"
                verbose: "true"
        database:
                connection: "mysql://glance:%{hiera('databasePasswords::glance')}@%{hiera('mysql::virtualIP')}/glance"

glance::registry::settings:
        database:
                connection: "mysql://glance:%{hiera('databasePasswords::glance')}@%{hiera('mysql::virtualIP')}/glance

Clearly when the second create_ini_settings runs it is detects the duplicate variable definition from the database \ Connection setting and throws an error. But my intention is to write these values into separate config files(This works if i remove the duplication).

So how do I fix this?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-12-09 12:56:44 -0500

lavaman gravatar image

The title of an ini_setting isn't used for anything. It's just a label (unlike, say package, which uses the title to know what package to install). Call them something like glance-api-database and glance-registry-database and you won't have duplicate resources being created.

edit flag offensive delete link more
0

answered 2016-01-18 18:32:14 -0500

CoryH gravatar image

The problem here is that i'm calling create_ini_settings not ini_setting so i dont have much control over the title. I could call 'inisetting' directly but that would result in a significant increase to the amount of code i need to use, by utilizing create_ini_settings i can just pass an entire hiera schema and have it create a bunch of inisettings which is much more efficient(In my instance)

I have looked at code/environments/production/modules/inifile/lib/puppet/parser/functions/create_ini_settings.rb and have found this excerpt

  ) do |arguments|

raise(Puppet::ParseError, "create_ini_settings(): Wrong number of arguments " +
  "given (#{arguments.size} for 1 or 2)") unless arguments.size.between?(1,2)

settings = arguments[0]
defaults = arguments[1] || {}

if [settings,defaults].any?{|i| !i.is_a?(Hash) }
  raise(Puppet::ParseError,
    'create_ini_settings(): Requires all arguments to be a Hash')
end

resources = settings.keys.inject({}) do |res, section|
  raise(Puppet::ParseError,
    "create_ini_settings(): Section #{section} must contain a Hash") \
    unless settings[section].is_a?(Hash)

  settings[section].each do |setting, value|
    res["[#{section}] #{setting}"] = {
      'ensure'  => 'present',
      'section' => section,
      'setting' => setting,
    }.merge(if value.is_a?(Hash)
      value
    else
      { 'value'   => value, }
    end)
  end
  res
end

Puppet::Parser::Functions.function('create_resources')
function_create_resources(['ini_setting',resources,defaults])

end end

I attempted to modify the title definition from res["[#{section}] #{setting}"] = { to res["[#{section}] #{setting} #{value}"] = { but the error message does not change, so i don't think this change worked for some reason?

edit flag offensive delete link more

Comments

I have worked around the issue by providing each setting a unique number, it's no pretty but it works. I modified code/environments/production/modules/inifile/lib/puppet/parser/functions/create_ini_settings.rb Changed line 68 to `res["[#{section}] #{setting} " + Random.rand(99999).to_s] = {`

CoryH gravatar imageCoryH ( 2016-01-18 20:15:23 -0500 )edit

You have total control over the titles. You're passing them in your hiera data. It makes no difference that you're using the create_ini_settings function. Just change database in hiera to glance-api-database and glance-registry-database or similar.

lavaman gravatar imagelavaman ( 2016-01-19 13:08:53 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-12-08 23:53:58 -0500

Seen: 357 times

Last updated: Jan 18 '16