On Thursday, May 9, 2013 10:23:25 PM UTC-5, Nan Liu wrote:
>
> On Thu, May 9, 2013 at 11:52 AM, James Kyle <li...@jameskyle.org<javascript:>
> > wrote:
>
>> I've run into several incidences where a module attempts to install a 
>> package before the apt::source is added or an update is run. Result is a 
>> bunch apt errors and explosions.
>>
>> Basically what should be done is all the apt::sources are added and and 
>> an update run _before_ any packages are installed to ensure you're pulling 
>> from the repos you want. 
>>
>> I've gone through several iterations in my attempt to achieve that 
>> behavior. The one that works best so far is stages and wrapper classes. 
>> Here's a terse example of what it looks like:
>>
>> class myorg::common {
>>   include stdlib
>>
>>   Apt::Source {stage => "setup"}  
>>
>>   apt::source { 'puppetlabs':
>>     location   => 'http://apt.puppetlabs.com',
>>     repos      => 'main',
>>     key        => '4BD6EC30',
>>     key_server => 'pgp.mit.edu',
>>   }
>>
>>   Exec['apt_update'] -> Package<|  title != 'ubuntu-cloud-keyring' |>
>> }
>>
>> node 'foo.bar.com' {
>>   include stdlib
>>   
>>   class {'myorg::common': stage => "setup"}
>> }
>>
>>
>> One thing that bothers me is you have to declare the stage for 
>> myorg::common in every node that uses it. And as the name implies, that's 
>> every node.
>>
>> Is there a way to get rid of that duplication? I've thought of node 
>> inheritance, but the docs seem to strongly steer you away from that pattern.
>>
>
> Doesn't the relationship do the right thing without stages?
>


It would depend on whether and how stages are used elsewhere in the 
manifest set.  With stages it's often "in for a penny, in for a pound."  
Generally speaking, though, it should be possible to do this sort of thing 
(or anything, actually) without stages.

 

> Does this work?
>
> class myorg::common (
>   $staging  = 'setup',
> ) { ...
>
> Nan
>


Provided that all of the relevant Apt sources are managed via Apt:::Source 
resources, and that no virtual Apt::Source or Package resources are 
declared without elsewhere being realized, this declaration should work:

Apt::Source<| |> -> Exec['apt_update'] -> Package<| |>

That declaration is not itself affected by or dependent on stages, but it 
is possible for the referenced resources to be assigned to stages in such a 
way that the chain closes one or more dependency cycles.  Such cycles would 
reflect an error in the stage assignments, however, for the chain 
expression succinctly and precisely describes the requested resource 
application order; as long as it does so, it *defines* the correct orders.  
It would be sufficient to make that declaration once, in some central 
place, but not harmful to make it multiple times.

There are all manner of tweaks and accommodations that could be applied to 
handle special cases, such as when there are virtual Apt::Source or Package 
resources must remain unrealized, but the chain above captures the 
essential essence of the required declaration.


John



-- 
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 post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to