1
votes

Trying to get some NPM packages installed both locally and globally. I am doing it like this:

$npm_packages_loc = {
    'mysql' => {
        'version' => 'latest',
        'ensure'  => 'present',
    },
    'googleapis' => {
        'version' => 'latest',
        'ensure'  => 'present',
    }
}

This simply says that I want the 'mysql' and 'googleapi' packages installed, and I want them at the latest version.

## Install NPM local packages
# Obtains and multiplexes NPM packages defgined in '$npm_modules_loc'
define npm_packages($version, $ensure) {
    npm_packages_loc_inst { $version:
        package => $name,
        ensure  => $ensure, 
    }
}
# Installs the packages via nodejs::npm
define npm_packages_loc_inst($package, $ensure) {
    $version = name
    nodejs::npm { "/opt/app/:${package}":
        ensure  => $ensure,
        version => $version,
    }
}
create_resources ('npm_packages', $npm_packages_loc)

However, when doing a puppet run I get the following error:

Duplicate declaration: myapp::Npm_packages_loc_inst[latest] is already declared in file /etc/puppet/modules/test/myapp/manifests/init.pp:79; cannot redeclare at /etc/puppet/modules/test/myapp/manifests/init.pp:79

Not sure why it is behaving like this, but I am obviously doing something wrong. Any help is appreciated :)

1

1 Answers

2
votes

I figured it out. It was because of this line:

npm_packages_loc_inst { $version:

As both 'versions' were set to 'latest', it thought there was a duplicate declaration (Npm_packages_loc_inst[latest]). Changing this to 'name' fixed the issue:

npm_packages_loc_inst { $name:

Now looks like:

Npm_packages_loc_inst[googleapis] \ Npm_packages_loc_inst[mysql]

Hence no duplicate declaration. Hope that helps other people out there.