class invocation conflicts

10 views
Skip to first unread message

Peter Berghold

unread,
May 20, 2019, 12:57:48 PM5/20/19
to puppet...@googlegroups.com
So here I am I have a base profile for my Ubuntu (Debian family) machines that invokes the class 

class{'apt':
    ... some paramters
}

I then invoke the class 

class{'postgresql': } 

and now Puppet is screaming that the class 'apt' cannot be invoked twice.   This seems to be a flaw in Puppet manifests to me.  How to fix?


--

Peter L. Berghold                       Salty....@gmail.com

http://devops.berghold.net


Henrik Lindberg

unread,
May 20, 2019, 3:33:39 PM5/20/19
to puppet...@googlegroups.com
On 2019-05-20 18:57, Peter Berghold wrote:
> So here I am I have a base profile for my Ubuntu (Debian family)
> machines that invokes the class
>
> class{'apt':
>     ... some paramters
> }
>
> I then invoke the class
>
> class{'postgresql': }
>
> and now Puppet is screaming that the class 'apt' cannot be invoked
> twice.   This seems to be a flaw in Puppet manifests to me.  How to fix?
>
>

The best practice is to not use the resource like `class { name: ... }`
syntax to declare a class and instead use `include name` and letting all
parameter values come from hiera via automatic parameter lookup.

That way, you can include the class as many times as you like - as the
parameters are the same every time. Unfortunately, the compiler cannot
do the same when classes are declared with parameters even if all places
this is done use the exact same values.

While it is possible to have a single `class { name: ... }` declaration
with subsequent `include name` declarations, the opposite does not work.

Hope this helps.
- henrik

> --
>
> Peter L. Berghold Salty....@gmail.com <mailto:Salty....@gmail.com>
>
> http://devops.berghold.net
>
>
> --
> 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...@googlegroups.com
> <mailto:puppet-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/CAArvnv2Ya1Vo1R%3D%2B3YW%3DMp%2BubL%2BZR_WFG1J4o_7OKe33tfm4vw%40mail.gmail.com
> <https://groups.google.com/d/msgid/puppet-users/CAArvnv2Ya1Vo1R%3D%2B3YW%3DMp%2BubL%2BZR_WFG1J4o_7OKe33tfm4vw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

Peter Berghold

unread,
May 21, 2019, 9:42:46 AM5/21/19
to puppet...@googlegroups.com
Using include instead of class makes sense to me and was my instinctive thought.

Why on earth, then, do all the (or most) of the Puppet Forge modules use the 

class{'myclass':
    param1 => 'thing'

patterns in their examples.  I had begun to believe that was the preferred pattern. 

I will mend my ways. 

To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/qbuve5%246tlm%241%40blaine.gmane.org.

For more options, visit https://groups.google.com/d/optout.


--

Rob Nelson

unread,
May 21, 2019, 1:42:31 PM5/21/19
to puppet...@googlegroups.com
Most likely because that’s an easy way to show the parameters a class supports. Some modules use hiera data to show that, though it is a bit more complicated to explain and understand, especially for novices.


For more options, visit https://groups.google.com/d/optout.
--
Rob Nelson
Reply all
Reply to author
Forward
0 new messages