Apple Wang
2012-Oct-23 09:09 UTC
[Puppet Users] Is the assignment of variables executed before the package resource?
Hi, all I''m confused about the execution sequence in puppet. *The background:* * * I want to get mysql package version after installing it with the Package resource. And I''ll configure /etc/my.cnf according the version of mysql package. The code is as following. ----------------------------------------------- class mysql{ package { "mysql": ensure => latest, } $mysql_version = get_pkg_version("mysql") file { ''/etc/my.cnf'': ensure => present, content => template(''mysql/mysql.cnf''), require => Package["mysql"], } } ----------------------------- Note: get_pkg_version is a user defined function written by me. It can get mysql rpm version when mysql is installed. *Issue:* First time I executed *puppet agent -t, *the variable *mysql_version*didn''t get the value of mysql rpm version. But the second time, after mysql is installed. *mysql_version* can get the value of mysql rpm version. Can anyone help me with the problem? -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/4uL89crPzDsJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
David Schmitt
2012-Oct-23 14:48 UTC
Re: [Puppet Users] Is the assignment of variables executed before the package resource?
Hi, the function is executed on the puppet master at the time of compiling the catalog. The catalog is then transferred to the agent where all resources are applied. Depending on your setup this might not only be two different stages in the process, but also two different machines! This is explained in more depth here:> http://docs.puppetlabs.com/learning/manifests.htmlBest Regards, David On 23.10.2012 11:09, Apple Wang wrote:> Hi, all > I''m confused about the execution sequence in puppet. > *The background:* > ** I want to get mysql package version after installing it with the > Package resource. And I''ll configure /etc/my.cnf according the version > of mysql package. The code is as following. > ----------------------------------------------- > class mysql{ > package { "mysql": > ensure => latest, > } > $mysql_version = get_pkg_version("mysql") > > file { ''/etc/my.cnf'': > ensure => present, > content => template(''mysql/mysql.cnf''), > require => Package["mysql"], > } > } > ----------------------------- > Note: get_pkg_version is a user defined function written by me. It > can get mysql rpm version when mysql is installed. > > *Issue:* > First time I executed /*puppet agent -t*, /the variable > */mysql_version/* didn''t get the value of mysql rpm version. > But the second time, after mysql is installed. > */mysql_version/* can get the value of mysql rpm version. > > Can anyone help me with the problem? > > > -- > You received this message because you are subscribed to the Google > Groups "Puppet Users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/puppet-users/-/4uL89crPzDsJ. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en.-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Apple Wang
2012-Oct-23 16:44 UTC
Re: [Puppet Users] Is the assignment of variables executed before the package resource?
Hi, David Thanks for your reply. I have been more clear about the compiling of puppet. Do you have any good method to get the package version after installing if with Package resource? I need the version to configure the my.cnf file. I know a method to get the version of packages that already installed, which are as follows. Puppet::Parser::Functions::newfunction(:get_pkg_version, :type => :rvalue) do |args| pkg_name = args[0] pkg = Puppet::Type.type(:package).new(:name => pkg_name) version = pkg.retrieve[pkg.property(:ensure)].to_s version.split(/-|\+/).at 0 end But is there any function of Package type that can get the latest version in the software repository (e.g. yum or zypper)? So that I can get the version of a package which will be installed and configure its conf file. Really looking forward for your answer! Thanks Apple 在 2012年10月23日星期二UTC+8下午10时49分03秒,David Schmitt写道:> > Hi, > > the function is executed on the puppet master at the time of compiling > the catalog. > > The catalog is then transferred to the agent where all resources are > applied. > > Depending on your setup this might not only be two different stages in > the process, but also two different machines! > > This is explained in more depth here: > > > http://docs.puppetlabs.com/learning/manifests.html > > > Best Regards, David > > On 23.10.2012 11:09, Apple Wang wrote: > > Hi, all > > I''m confused about the execution sequence in puppet. > > *The background:* > > ** I want to get mysql package version after installing it with the > > Package resource. And I''ll configure /etc/my.cnf according the version > > of mysql package. The code is as following. > > ----------------------------------------------- > > class mysql{ > > package { "mysql": > > ensure => latest, > > } > > $mysql_version = get_pkg_version("mysql") > > > > file { ''/etc/my.cnf'': > > ensure => present, > > content => template(''mysql/mysql.cnf''), > > require => Package["mysql"], > > } > > } > > ----------------------------- > > Note: get_pkg_version is a user defined function written by me. It > > can get mysql rpm version when mysql is installed. > > > > *Issue:* > > First time I executed /*puppet agent -t*, /the variable > > */mysql_version/* didn''t get the value of mysql rpm version. > > But the second time, after mysql is installed. > > */mysql_version/* can get the value of mysql rpm version. > > > > Can anyone help me with the problem? > > > > > > -- > > You received this message because you are subscribed to the Google > > Groups "Puppet Users" group. > > To view this discussion on the web visit > > https://groups.google.com/d/msg/puppet-users/-/4uL89crPzDsJ. > > To post to this group, send email to puppet...@googlegroups.com<javascript:>. > > > To unsubscribe from this group, send email to > > puppet-users...@googlegroups.com <javascript:>. > > For more options, visit this group at > > http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/2qqLpZthbU4J. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2012-Oct-24 13:53 UTC
Re: [Puppet Users] Is the assignment of variables executed before the package resource?
On Tuesday, October 23, 2012 11:44:36 AM UTC-5, Apple Wang wrote:> > Hi, David > > Thanks for your reply. I have been more clear about the compiling of > puppet. > Do you have any good method to get the package version after installing if > with Package resource? I need the version to configure the my.cnf file. > > I know a method to get the version of packages that already installed, > which are as follows. > > Puppet::Parser::Functions::newfunction(:get_pkg_version, :type => :rvalue) > do |args| > pkg_name = args[0] > pkg = Puppet::Type.type(:package).new(:name => pkg_name) > version = pkg.retrieve[pkg.property(:ensure)].to_s > version.split(/-|\+/).at 0 > end > >I am pretty sure that doesn''t do anything like what you are looking for. In particular, because functions run *on the master*, it is incapable of telling you anything about the current state of the client (except when the client is the master itself). It looks like that might give you the value of the ''ensure'' property that you specify in your manifests for the Package resource of interest. If you ''ensure'' a specific version and your catalog is applied successfully, then that is indeed the version that the client will have after the Puppet run. In that case you would already know the version number to expect, however, so you wouldn''t need to query it. If you specify something like "ensure => ''latest''", however, or if you don''t give an explicit ensure at all, then that function isn''t even going to return a number.> But is there any function of Package type that can get the latest version > in the software repository (e.g. yum or zypper)? So that I can get the > version of a package which will be installed and configure its conf file. > >Now that''s an entirely different question. Supposing that you can rely on the master''s repository configuration to be the same as the client''s, you can write a custom function that runs "yum list <packagename>" and parses the version number out of the result. Really, though, I suspect you''re going about this in an unnecessarily difficult way. Why does the version number of the software need to be recorded in the software''s own configuration file? That seems redundant and brittle. Isn''t there an alternative that would Just Work? John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/ufPjpmGyj4cJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.