If you are running with a master/slave setup functions are executed on the
puppet master as part of the compilation. So it won''t really work, and
there is no way to change the ordering.
To execute that on the client you will need to create a custom fact, but it will
always be executed before the puppet run starts. So if you are okay with it
taking two puppet runs to fully configure the node you can use that method and
the fact will be available on the second puppet run after the package has been
installed.
Another way would be to specify which package version you want and install that
version and use the same version variable in the template.
--
Erik Dalén
On Tuesday 23 October 2012 at 12:04, Apple Wang wrote:
> Hi, all
>
> I have some questions about the execution sequence in puppet.
>
> The background:
> I want to install mysql package and configure /etc/my.cnf according to the
version of mysql. So I wrote an user defined function to get mysql rpm version.
Codes are as follows.
> ------------------------------------------------
> class mysql {
> package { ''mysql'':
> ensure => latest,
> }
>
> $mysql_version = get_pkg_version("mysql")
>
> file { ''/etc/my.cnf'':
> ensure => present,
> mode => ''0644'',
> content => template(''mysql/mysql.cnf''),
> require => Package[''mysql''],
> }
> }
>
> Note: get_pkg_version is the user defined function to get mysql rpm
version.
>
-------------------------------------------------------------------------------------------
> Issue:
> The first time I execute puppet agent -t, the variable mysql_version
couldn''t get the version of mysql. And I found it was executed before
the installation of mysql package. And the second time I execute puppet agent
-t, the variable mysql_version got the version of mysql installed after the
first time.
>
> So, my question is that are variables assignment executed before the
resources such as Package, Service, File..etc?
> Is there any method can make $mysql_version =
get_pkg_version("mysql") executed after
Package[''mysql'']?
>
> Really looking forward to your answers!
>
> --
> 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/-/6NzlmgjiBHUJ.
> To post to this group, send email to puppet-users@googlegroups.com
(mailto:puppet-users@googlegroups.com).
> To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com
(mailto: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.