How to uninstall package using puppet - puppet

I have installed mysql in a client node using Puppet. Now I want to uninstall it in the client node. I tried the following configuration in site.pp:
package { '::mysql::server':
ensure => 'purged'
}
This did not work. Can someone show me how to uninstall mysql (or any package for that matter)?

That syntax is wrong. ::mysql::server is either referencing a puppet class or defined type. You only need to specify the package name to the package type.
package { 'mysql_package_name':
ensure => absent
}
Replacing mysql_package_name with the name of the package for the distro you are using.

Related

Puppet and version of a package to install

Tell me how to specify the correct version for the package to be installed. Updating Virtualbox. Updated normally. But, does it every time. Although, the latest version is already installed.
My manifest file:
class virtualbox {
package { "virtualbox":
provider => dpkg,
ensure => '5.2.18-124319~Ubuntu~trusty',
source => "/tmp/virtualbox-5.2_5.2.18-124319~Ubuntu~trusty_amd64.deb"
}
}
On client:
$ sudo service puppet stop
* Stopping puppet agent
$ sudo puppet agent -v --no-daemonize
Notice: Starting Puppet client version 3.4.3
Info: Retrieving plugin
Info: Caching catalog for w071
Error: Failed to apply catalog: Parameter ensure failed on Package[virtualbox]: Provider must have features 'versionable' to set 'ensure' to '5.2.18-124319~Ubuntu~trusty' at /etc/puppet/manifests/classes/1c_update.pp:7
Wrapped exception:
Provider must have features 'versionable' to set 'ensure' to '5.2.18-124319~Ubuntu~trusty'
If specify latest, the package will be updated every time.

require.resolve not resolving dependency

I was working on a node module, where I would have to check if the user had installed an specific package (that's the logic I have to follow) and if not, install that using child_process.exec.
That's where the problem appears, even though my script installed the package (node_modules contains it, also package.json), if I call require.resolve again, it says the module does not exist.
For what I found (from node github issues), node has sort of a "cache", where on the first call, if the package is not installed, the cache entry for this package is set to a random value which is not the path to it. Then when you install and try to call that again, it calls that cache entry.
Is there any other way to check if packages are installed, or my local node installation is broken?
Take a look into node.js require() cache - possible to invalidate?
It's possible to clean up the require cache, with something like this:
delete require.cache[require.resolve('./module.js')]
One way to check if a package is installed is trying to require it. Please see my code below that verifies if a package is not installed. Just add your code that installs it after the comment now install the missing package.
try {
require('non-existent-package');
} catch (error) {
// return early if the error is not what we're looking for
if (error.code != 'MODULE_NOT_FOUND') {
throw error;
}
// now install the missing package
}
Let me know if this works.

Puppet - install module through other module manifest

I'd like to use vcsrepo module in my puppet module manifest. So I need to install puppetlabs/vcsrepo.
Is it possible to avoid installing it manualy by command
sudo puppet install puppetlabs-vcsrepo?
I've tried to use somethink like this in my init.pp file
module { 'puppetlabs/vcsrepo':
ensure => installed,
}
but it doesn't work :(
The best way to use that module would be to add it to your metadata.json file as explained here: https://docs.puppetlabs.com/guides/style_guide.html#module-metadata
Once you've done so the module requested, in your case puppetlabs/vcsrepo will be installed.

Vagrant + chef-solo + berkshelf: node.js last version cookbook

Basically, i need a working machine with node.js & npm installed.
I've configured a vagrant + berkshelf + chef enviroment, but i can't find a lastest version (>= 4.0.0) nodejs cookbook as source for my berksfile.
I've tried with this:
https://supermarket.chef.io/cookbooks/nodejs
from chef supermarket but install a old version of node + npm.
I am experiencing for the first time vagrant and chef so i can't understand how find it.
Can someone help me?
In your role or node settings you can specify default attributes for any cookbook you use. Cookbook nodejs allows you to set NodeJS version with the attribute version (check its attributes/default.rb file). But this attribute is taken into account only when NodeJS is installed from precompiled binaries or sources. So you need to specify install_method as well (default is package, i.e. installation via system package manager).
One more thing: you need to manually specify binary package checksum, which you can find in every release folder here: https://nodejs.org/download/release/
So, to install the latest version from official binaries use the following settings in role or node:
"nodejs": {
"install_method": "binary",
"binary": {
"checksum": "75b029b30d4a4147d67cf75bf6e034291fb5919c6935ec23f8365cee2d463f12"
},
"version": "5.3.0"
}

Installing MongoDb with Puppet

I'm a newbie in Puppet, so maybe you'll find my question a bit stupid...
So, I'm looking for puppet recipe that will install and run Mongodb 2.2 on my machine. By googling I found this module http://forge.puppetlabs.com/puppetlabs/mongodb But I didn't understand clear what should I do?
It said I have to install module on puppet node first. What does exactly it means?
Let's say, I have a set of machines those must be configured via puppet.
What do I have to add to puppet recipe to reach this aim?
In case someone might be interest on installing the last version of MongoDB this worked very well for me. At the moment of writing the latest stable version is MongoDB 3.0.3.
First of all update your OS repositories via the puppet apt module (in case you're using a Debian or Ubuntu distribution). Change the data below according to your distribution and version. Check here to get the MongoDB official repositories information: http://docs.mongodb.org/manual/administration/install-on-linux/#recommended
# $::lsbdistcodename should contain what you usually get
# with the `lsb_release -sc` command
$server_lsbdistcodename = downcase($::lsbdistcodename)
apt::source { 'mongodb-org-3.0':
location => 'http://repo.mongodb.org/apt/debian',
release => "${server_lsbdistcodename}/mongodb-org/3.0",
repos => 'main',
key => '7F0CEB10',
key_server => 'keyserver.ubuntu.com',
include_src => false
}
And then set the mongodb::globals class properly to make sure you get MongoDB 3. The MongoDB puppet module I'm using is this one.
class { 'mongodb::globals':
manage_package_repo => false, # disable the 10gen repository
server_package_name => 'mongodb-org',
service_name => 'mongod',
version => '3.0.3',
}->
class { '::mongodb::server': }
Getting mongodb installed with puppet isn't as easy as it seems. It's somewhat difficult to get official Puppet Labs module v0.8.0 to install mongodb 2.6.3. You end up getting an apt error about mongodb-10gen=2.6.3 not being found. There's an issue and a patch already but it hasn't been published yet.
So here's what you need to do:
git clone https://github.com/puppetlabs/puppetlabs-mongodb.git
Then use the following puppet config:
class { '::mongodb::globals':
manage_package_repo => true,
server_package_name => 'mongodb-org',
version => '2.6.3'
}->
class { '::mongodb::server': }
This Worked for me.
If you are running puppet standalone, you will have already installed the puppet gem and have the puppet executable. To intall the module, you run puppet module install puppetlabs/mongodb. After the module installation, you can simply include the mongodb module in your node definition
node 'myhost' {
include mongodb
}
If you want to run a number of nodes that need access to the module, you'll have to setup a puppetmaster and install the node. See [Basic Agent/Master setup][1] for more info. Make sure that pluginsync=true is enabled in puppet.conf so the module can make it's way to the remote agents.
The puppetmaster will then need a file, normally site.pp defined with the nodes it should configure. Finally, include the mongodb module on each node you want to run mongodb and you should be up and running.

Resources