Ask Your Question
0

passing variable values between classes

asked 2015-04-27 15:03:08 -0500

R gravatar image

updated 2015-04-27 16:25:39 -0500

I am trying to use the exec resource type to execute a batch file. But I want to pass the value of variable $dsn_64bit from init.pp to install.pp. Please let me know how to achieve that:

Here is my init.pp

class exec_batchfile ($dsn_64bit = "false")
{
if $::osfamily == 'windows' {
include exec_batchfile::install
 }
 }

Here is my install.pp

class exec_batchfile::install 
{

 # Get the value (that was passed to init.pp) of $dsn_64bit here, it might be true or false

 if $dsn_64bit == true
{
  $hklm_path = 'HKLM\Software\Oracle'
  $Script_name = 'E:\\Path\\pupp_test64.bat'
}
else
{
  $hklm_path = 'HKLM\Software\WOW6432Node\Oracle'
  $Script_name = 'E:\\Path\\pupp_test.bat'
}
   exec { 'exec_batchfile':
   command => "${Script_name}",
   path => $::path,
   logoutput => true,
   unless => "cmd.exe /c reg query ${hklm_path} /v inst_loc",
 }
}

I looked at this link http://docs.puppetlabs.com/learning/modules2.html but could not find (or may be understand how to interpret the explanation). I kindly request anybody to help me out with this requirement.

Thanks a lot in advance

edit retag flag offensive close merge delete

Comments

please reformat your question to put four spaces in front of each line of your code examples. This will format those lines into code blocks that are readable.

JohnsonEarls gravatar imageJohnsonEarls ( 2015-04-27 15:24:58 -0500 )edit

Just edited it now. My apologies.

R gravatar imageR ( 2015-04-27 16:38:15 -0500 )edit

5 Answers

Sort by ยป oldest newest most voted
2

answered 2015-04-27 15:26:13 -0500

JohnsonEarls gravatar image

updated 2015-04-27 18:37:06 -0500

Try using $exec_batchfile::dsn_64bit or ${exec_batchfile::dsn_64bit} instead of just $dsn_64bit - that should reference the variable from the exec_batchfile class, as shown here:

class exec_batchfile::install 
{

 # Get the value (that was passed to init.pp) of $dsn_64bit here, it might be true or false

 if $exec_batchfile::dsn_64bit == true
{
  $hklm_path = 'HKLM\Software\Oracle'
  $Script_name = 'E:\\Path\\pupp_test64.bat'
}
else
{
  $hklm_path = 'HKLM\Software\WOW6432Node\Oracle'
  $Script_name = 'E:\\Path\\pupp_test.bat'
}
   exec { 'exec_batchfile':
   command => "${Script_name}",
   path => $::path,
   logoutput => true,
   unless => "cmd.exe /c reg query ${hklm_path} /v inst_loc",
 }
}
edit flag offensive delete link more
0

answered 2015-04-28 08:38:07 -0500

primyy gravatar image

Why don't you also parametrize your exec_batchfile::install class and include it with

class { 'exec_batchfile::install': dsn_64bit => $dsn_64bit }

?

edit flag offensive delete link more
0

answered 2015-04-27 16:47:33 -0500

R gravatar image

Thanks a lot for your response, I didn't get you. Do you mean adding it like this class exec_batchfile ($exec_{batchfile::dsn64bit} = "false"). Please let me know. Thanks again

edit flag offensive delete link more
0

answered 2015-04-30 17:21:54 -0500

R gravatar image
if $exec_batchfile::dsn_64bit == true

This also worked beautifully, thanks a lot!!!!

edit flag offensive delete link more

Comments

Thanks :) FYI - there's a link at the bottom of each answer called "Add a comment" that you can use to respond to an individual answer, rather than creating new answers each time.

JohnsonEarls gravatar imageJohnsonEarls ( 2015-04-30 21:52:15 -0500 )edit
0

answered 2015-04-27 18:45:55 -0500

R gravatar image

updated 2015-04-27 19:35:46 -0500

JohnsonEarls gravatar image

This link https://docs.puppetlabs.com/guides/scope_and_puppet.html#making-the-switch explained exactly what I wanted. this $local_var = "from parent::child" did the trick.

edit flag offensive delete link more

Comments

I'm not sure how that would have "done the trick", as that is simply assigning a static string to a local variable, but if it worked for you, great.

JohnsonEarls gravatar imageJohnsonEarls ( 2015-04-27 19:37:02 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-04-27 15:03:08 -0500

Seen: 721 times

Last updated: Apr 30 '15