Ask Your Question
0

"Cannot reassign variable" error on Puppet 4.7, worked on 3.8

asked 2016-12-13 05:26:07 -0500

kranthi gravatar image

updated 2016-12-13 05:31:25 -0500

domcleal gravatar image

Hi Team,

I am not able to use the global variable on Puppet 4.7 version its throwing Cannot reassign variable, the same thing was working smoothly on Puppet 3.8 Version.

The below code used to work smoothly on Puppet 3.8 version, when I have migrated to Puppet 4.7 its throwing the below error.

Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Cannot reassign variable '$module_name' at /etc/puppetlabs/code/modules/tarball/manifests/init.pp:1 at /etc/puppetlabs/code/modules/pbis/manifests/init.pp:5 on node

Class example, I have used the "include" to run the classes in a specific order

class ubuntu {
  include pbis
  include certs
  include anyconnect
  include ifupvpn
  Class['pbis'] -> Class['certs'] -> Class['anyconnect'] -> Class['ifupvpn'] 
}

Can you please guide me on where I am missing.

Regards,

Kranthi

edit retag flag offensive close merge delete

Comments

The error message states that the problem is at `/etc/puppetlabs/code/modules/tarball/manifests/init.pp`, line 1, and possibly also `pbis/manifests/init.pp` line 5. Please include those files in your question.

domcleal gravatar imagedomcleal ( 2016-12-13 05:32:14 -0500 )edit

3 Answers

Sort by » oldest newest most voted
0

answered 2016-12-13 05:58:20 -0500

kranthi gravatar image

updated 2016-12-13 06:21:13 -0500

Hi,

I am using the same global variables to extract tar files into different locations via different modules. Please find the module details below. Let me know if you need any further information.

Tarball module:-

define tarball ($pkg_tgz, $module_name, $install_dir, $condition_check) {
  # create the install directory
   file { "$install_dir":
        ensure  => directory,
    }

    # download the tgz file
    file { "$pkg_tgz":
        path    => "/tmp/$pkg_tgz",
        source  => "puppet:///modules/$module_name/$pkg_tgz",
        notify  => Exec["untar $pkg_tgz"],
    }

    # untar the tarball at the desired location
    exec { "untar $pkg_tgz":
        command => "/bin/tar xzvf /tmp/$pkg_tgz -C $install_dir/",
        require => File["/tmp/$pkg_tgz", "$install_dir"],
        unless => "$condition_check",
     }
}

Pbis module:-

class pbis{

$pkg_name = "pbis.tgz"

tarball { "$pkg_name":
module_name => "pbisindia",
install_dir => "/opt/setups",
pkg_tgz     => "$pkg_name",
condition_check => "/bin/ls /opt | /bin/grep -i pbis > /var/tmp/pbisindiaextracted",
notify => Exec["Run Script"],
}

Regards,

Kranthi

edit flag offensive delete link more
0

answered 2016-12-13 09:14:26 -0500

domcleal gravatar image
define tarball ($pkg_tgz, $module_name, $install_dir, $condition_check) {

You will need to rename the $module_name parameter, it's a reserved variable from Facts and built-in variables.

Update both the name in the define and in any callers, such as your pbis class.

edit flag offensive delete link more
0

answered 2016-12-13 08:56:41 -0500

DarylW gravatar image

updated 2016-12-13 08:58:13 -0500

You shouldn't be reassigning modulename.. I think you want the built-in variable of caller_module_name. That will allow your code to reference the module that calls it, instead of hardcoding the values.

Compiler variables

These variables are set in every local scope by the compiler during compilation. They are mostly useful when implementing complex defined types.

These are not available in the $facts hash.

These variables are always defined (by the standards of the strict_variables setting), but their value is undef whenever no other value is applicable.

•$module_name — the name of the module that contains the current class or defined type.

•$caller_module_name — the name of the module in which the specific instance of the surrounding defined type was declared. This is only useful when creating versatile defined types which will be re-used by several modules.

edit flag offensive delete link more

Comments

Thanks a lot Dominic for guiding me in the correct path, I am always thankful for your support :-)

kranthi gravatar imagekranthi ( 2016-12-14 08:38:03 -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

2 followers

Stats

Asked: 2016-12-13 05:26:07 -0500

Seen: 397 times

Last updated: Dec 13 '16