Ask Your Question

Duplicate declaration error when using Ini_setting

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

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

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

                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

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

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

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

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) }
    'create_ini_settings(): Requires all arguments to be a Hash')

resources = settings.keys.inject({}) do |res, section|
    "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'   => value, }


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


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 -0600 )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 -0600 )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


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

Seen: 535 times

Last updated: Jan 18 '16