why does the create_resource functio not contain in local scope?

110 views
Skip to first unread message

Haani Niyaz

unread,
Nov 26, 2015, 10:34:37 PM11/26/15
to Puppet Users
I have the following class which purely initiates the create_resource function:

class server_packages (
    $server_packages
,
 $enable_repo
= '*'
){
   
Package {
      install_options
=> [ { '--disablerepo' => '*' } , { '--enablerepo' => $enable_repo }]
   
}
    create_resources
(package, $server_packages,)
}


This is called in a profile:

class { 'server_packages':
   
# list of packages
    server_packages  
=> hiera('server_packages'),
    enable_repo      
=> 'my-rpms,base',
 
}




class { 'some_class':
   
# params here
 
}



Puppet run:

Notice: Compiled catalog for automation01 in environment production in 2.44 seconds
Notice: /Stage[main]/Server_packages/Package[gcc-c++]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Server_packages/Package[openssl-devel]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Server_packages/Package[apr-util-devel]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Server_packages/Package[mysql.x86_64]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Server_packages/Package[glibc-devel.i686]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Server_packages/Package[libffi-devel]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Server_packages/Package[apr-devel]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Server_packages/Package[gcc]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Server_packages/Package[zlib-devel]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Server_packages/Package[libcurl-devel]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Server_packages/Package[httpd-devel]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Server_packages/Package[sqlite-devel]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Server_packages/Package[jre]/ensure: current_value absent, should be 1.7.0_79-fcs (noop)
Notice: /Stage[main]/Server_packages/Package[httpd]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/some_class::Install/Package[app]/ensure: current_value absent, should be 1.0-1 (noop)
Notice: Class[some_class::Install]: Would have triggered 'refresh' from 1 events
Notice: /Stage[main]/some_class::Config/File[/etc/init.d/appservice]/ensure: current_value absent, should be file (noop)
Notice: /Stage[main]/some_class::Config/File[/opt/vendor]/ensure: current_value absent, should be directory (noop)
Notice: /Stage[main]/some_class::Config/File[/opt/vendor/product-some_class/current/config/b.json]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/some_class::Config/File[/opt/vendor/product-some_class/current/scripts/run.rb]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/some_class::Config/File[/opt/app]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/some_class::Config/File[/opt/app/gem.sh]/ensure: current_value absent, should be file (noop)
Notice: /Stage[main]/some_class::Config/File[/opt/app/.bash_profile]/ensure: current_value absent, should be file (noop)
Notice: /Stage[main]/some_class::Config/File[/opt/app/app_stop.sh]/ensure: current_value absent, should be file (noop)
Notice: /Stage[main]/some_class::Config/File[/etc/logrotate.d/app]/ensure: current_value absent, should be file (noop)
Notice: /Stage[main]/some_class::Config/File[/opt/vendor/product-some_class/current/config/config.json]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/some_class::Config/File[/opt/vendor/product-some_class/mbct/mbct.properties]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/some_class::Config/File[/opt/app/app_startup.sh]/ensure: current_value absent, should be file (noop)
Notice: /Stage[main]/some_class::Config/File[/opt/ffmpeg]/ensure: current_value absent, should be directory (noop)
Notice: Class[some_class::Config]: Would have triggered 'refresh' from 13 events
Notice: /Stage[main]/some_class::Gem_install/Exec[/opt/app/gem.sh]/returns: current_value notrun, should be 0 (noop)
Notice: Class[some_class::Gem_install]: Would have triggered 'refresh' from 1 events
Notice: /Stage[main]/some_class::Service/Service[appservice]/ensure: current_value stopped, should be running (noop)
Notice: /Stage[main]/some_class::Service/Service[httpd]/ensure: current_value stopped, should be running (noop)
Notice: Class[some_class::Service]: Would have triggered 'refresh' from 2 events
Notice: /Stage[main]/Server_packages/Package[mysql-devel.x86_64]/ensure: current_value absent, should be present (noop)




As you can see in the output above server_packges will be executed again after the execution of some_class:
Notice: Class[some_class::Service]: Would have triggered 'refresh' from 2 events
Notice: /Stage[main]/Server_packages/Package[mysql-devel.x86_64]/ensure: current_value absent, should be present (noop)


I came across the following which seems to highlight the problem but it was fixed in an older version:


create_resources should contain native types in the local scope





Haani Niyaz

unread,
Nov 26, 2015, 10:35:50 PM11/26/15
to Puppet Users
Also my puppet (agent) version is 3.8.1. I run puppet apply.

jcbollinger

unread,
Nov 30, 2015, 9:19:39 AM11/30/15
to Puppet Users


On Thursday, November 26, 2015 at 9:34:37 PM UTC-6, Haani Niyaz wrote:
 
As you can see in the output above server_packges will be executed again after the execution of some_class:
Notice: Class[some_class::Service]: Would have triggered 'refresh' from 2 events
Notice: /Stage[main]/Server_packages/Package[mysql-devel.x86_64]/ensure: current_value absent, should be present (noop)



No, I don't see that, nor any reason to suppose it.  The output you presented lists Package[mysql-devel.x86_64] exactly once.  Puppet chooses to manage it later in the run than it does other packages that (I presume) are managed via your Class[server-packages], including the related package Package[mysql.x86_64], but you have not shown any ordering constraints that would instruct Puppet to do otherwise.

 

I came across the following which seems to highlight the problem but it was fixed in an older version:


create_resources should contain native types in the local scope




That bug was reported against Puppet 2.7.0 and fixed in version 2.7.3.  Nothing you have presented suggests a regression.

Probably you have a misunderstanding about the nature of Puppet classes.  Although classes serve as logical containers for resources, Puppet does not inherently prevent application of different containers from overlapping, which is what you appear to be seeing -- application of resources from at least two different containers interleaved.  If you want to influence the order in which resources are applied then you must employ appropriate order-of-application constraints.


John

Haani Niyaz

unread,
Dec 4, 2015, 12:09:47 AM12/4/15
to Puppet Users
Thanks for the clarification. I did forget to mention that I tried the ordering of my classes as well:

class { 'server_packages':
   
# list of packages
    server_packages  
=> hiera('server_packages'),
    enable_repo      
=> 'my-rpms,base',

 
} ->


class { 'some_class':
   
# params here
 
}

jcbollinger

unread,
Dec 4, 2015, 9:25:23 AM12/4/15
to Puppet Users


On Thursday, December 3, 2015 at 11:09:47 PM UTC-6, Haani Niyaz wrote:
Thanks for the clarification. I did forget to mention that I tried the ordering of my classes as well:

class { 'server_packages':
   
# list of packages
    server_packages  
=> hiera('server_packages'),
    enable_repo      
=> 'my-rpms,base',
 
} ->

class { 'some_class':
   
# params here
 
}



I see no reason to change my earlier remarks, but looking more closely, it does appear that you have a containment problem.  Although the evidence is in your log, it would have been more apparent if you had given a more complete representation of your Class[some_class].

Note in particular that your log excerpt does not show any resource belonging to Class[some_class] applied before Package[mysql-devel.x86_64] or any other resource declared by Class[server_packages].  What it shows is resources declared by other classes (e.g. Class[some_class::Service]) being applied in that window.  When one end of a relationship is a class, C, the relationship is transitive to the resources declared directly by C, but it is not automatically transitive to other classes declared by C.  That is, although classes serve as containers for the resources they declare, they do not automatically contain the other classes they declare.

That (lack of) class containment behavior is intentional and desirable as a default, but often enough you do want classes to contain other classes.  For that, there is the `contain` function, which provides include-like class declarations with containment semantics, and which therefore can be used also in addition to another declaration of the same class to add containment semantics.  Although the details of your Class[some_class] are unclear, you probably want something more or less along these lines:

class some_class (
   
# params here
) {
  contain some_class
::install
  contain some_class
::config
  contain some_class
::gem_Install
  contain some_class
::service

 
Class[some_class::install]
   
-> Class[some_class::config]
   
-> Class[some_class::gem_install]
   
-> Class[some_class::service]
}


John

Haani Niyaz

unread,
Dec 6, 2015, 3:04:45 AM12/6/15
to Puppet Users
Thanks John, I did this get to work. 
Reply all
Reply to author
Forward
0 new messages