Duplicate declaration problem

470 views
Skip to first unread message

Sean Korten

unread,
Apr 21, 2014, 1:31:52 PM4/21/14
to puppet...@googlegroups.com
So, I am trying to do something with a list (array) of users from hieara.  Here is the yaml:

profile::sysconfig::sftp_users: [ "joe", "bill", "nancy" ]

In my profile I have a defined class "debugUsers" that I am calling with the array I got from hiera:

class profile::sysconfig::sftpserver {
  define debugUsers {
    notify { "username: \"${user}\"": }
  }
  class doWork {
    $users = hiera('profile::sysconfig::sftp_users')
    validate_array($users)
    debugUsers { $users: }
  }
  include doWork
}

From everything I know and have read that should give me a notify line for user in my array.  But it doesn't.  Instead I get this error from the agent:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: Notify[username: ""] is already declared in file /etc/puppetlabs/puppet/environments/r10k/dev_users/modules/profile/manifests/sysconfig/sftpserver.pp:5; cannot redeclare at /etc/puppetlabs/puppet/environments/r10k/dev_users/modules/profile/manifests/sysconfig/sftpserver.pp:5 

Why am I getting duplicate null declarations?  If I call out specific elements of the array I get back exactly what I would expect:

class profile::sysconfig::sftpserver {
  class doWork {
    $users = hiera('profile::sysconfig::sftp_users')
    validate_array($users)
    notify { "user1: \"${users[0]}\"": }
    notify { "user2: \"${users[1]}\"": }
    notify { "user3: \"${users[2]}\"": }
  }
  include doWork

returns this:

Notice: user1: "joe"
Notice: /Stage[main]/Profile::Sysconfig::Sftpserver::Dowork/Notify[user1: "joe"]/message: defined 'message' as 'user1: "joe"'
Notice: user3: "nancy"
Notice: /Stage[main]/Profile::Sysconfig::Sftpserver::Dowork/Notify[user3: "nancy"]/message: defined 'message' as 'user3: "nancy"'
Notice: user2: "bill"
Notice: /Stage[main]/Profile::Sysconfig::Sftpserver::Dowork/Notify[user2: "bill"]/message: defined 'message' as 'user2: "bill"' 

I am sure this is something really stupid, but can someone point out what I'm doing wrong here?

Thanks,
--Sean

Sean Korten

unread,
Apr 21, 2014, 4:09:31 PM4/21/14
to puppet...@googlegroups.com
Found the problem.  When passing an array to a define the default variable name for the elements of the array is $name.  This works:

  define debugUsers {
    validate_string($name)
    notify { "username: \"${name}\"": }
  }
Reply all
Reply to author
Forward
0 new messages