Hey Stephen and all,
    You are correct in your assumptions, and this definitely solved my
problem.  I tried going down this path before but only met failure, looks
like my declaration syntax might have been wrong and I might have also had
issues with the define syntax itself but I'm unsure at this point.  Most
importantly, it works!

    So now that this is working, will it also work if I have multiple
different manifests declaring the same resource?  I'm trying to use the
concept of roles so that I can assign one to many roles to each host.  So
lets assume the username is *testing*.  If I have role1.pp declare
`base::systemusers { testing: }` and role2.pp also declares the same user,
I'm assuming that will also create a resource duplication.  If that
assumption is incorrect then I'm good, otherwise I'm not sure how to solve
that issue.  I've read up on virtual resources and I think I understand how
the declaration works however I'm unsure where to collect/realize that
resource.
Thanks,
-Dan

On Fri, May 3, 2019 at 10:14 AM Stephen Marlow <stephen.a.mar...@gmail.com>
wrote:

> Hey Dan,
>
>   The error you're getting is just saying that you've declared the
> Base::Systemusers class twice and a class can only be declared once. I
> suspect that your code looks something like this:
>
>   $systemusers   = lookup({ name => 'base::systemusers' })
>   $systemusers.each |$username, $userinfo| {
>     class { 'base::systemusers':
>       username => $username,
>     }
>   }
>
>   If that is the case then you should be able to fix the problem by
> changing Base::Systemusers from a class to a define. Defined types can be
> declared multiple times as long as each one has a unique title. You can
> find more information about defined types here:
> https://puppet.com/docs/puppet/6.4/lang_defined_types.html
>
>   The syntax to declare the defined type would change slightly. It should
> look like this:
>   base::systemusers { $username: }
>
>   Let me know if you have any questions (or if I guess incorrectly about
> what your code looks like).
>
>   - Steve
>
> On Fri, May 3, 2019 at 12:21 PM Daniel Kinon <dan.ki...@gmail.com> wrote:
>
>> Hello Everyone,
>>     So I'm trying to create templates for system users.  Here is my
>> systemusers class:
>> ~~~
>> class base::systemusers (
>>   $username = $title,
>>   $home     = "/var/lib/$username",
>> ) {
>>   $systemusers   = lookup({ name => 'base::systemusers' })
>>   user { $username:
>>     ensure     => present,
>>     system     => true,
>>     uid        => $systemusers[$username]['uid'],
>>     home       => $home,
>>     managehome => true,
>>     shell      => '/bin/bash',
>>   }
>>
>>   file { "$home/.ssh":
>>     ensure  => directory,
>>     owner   => $username,
>>     group   => $username,
>>     mode    => '0700',
>>   }
>>
>>   file { "/var/run/$username":
>>     ensure  => directory,
>>     owner   => $username,
>>     group   => $username,
>>     mode    => '0755',
>>   }
>>
>>   file { "/var/log/$username":
>>     ensure  => directory,
>>     owner   => $username,
>>     group   => $username,
>>     mode    => '0755',
>>   }
>> ~~~
>>
>> This works great when I only have 1 system user but the minute I have
>> more than 1 I get a *Duplicate declaration: Class[Base::Systemusers] *error.
>> I've looked at the docs for virtual resources (tbh, it breaks my brain a
>> little) but all the examples seem to be for general resources and not
>> classes.  I've tried a bunch of different iterations to solve this and I
>> haven't gotten any of them to work.  If someone could point me in the right
>> direction, I'd appreciate it.
>>
>> Thanks,
>> -Dan
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Puppet Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to puppet-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/puppet-users/CAMGSraH5Sn31xPt8Z4DN8Xj74g20TZZ4z%3DPgD5TwgP%3DtWRT%3DxQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/puppet-users/CAMGSraH5Sn31xPt8Z4DN8Xj74g20TZZ4z%3DPgD5TwgP%3DtWRT%3DxQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to puppet-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/CALGSqj%2BXChwjKqFqB%2B07uyNuK0ojNMV593pF9rbZ2_aRABZKUw%40mail.gmail.com
> <https://groups.google.com/d/msgid/puppet-users/CALGSqj%2BXChwjKqFqB%2B07uyNuK0ojNMV593pF9rbZ2_aRABZKUw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CAMGSraF0CkVEsodm8X%3D4--5uFzxnrc8HUV%2BCihRDx187cWKaDg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to