puppet restrict installed modules based on osfamily - puppet

I have configured puppet manifest as below,
class main_config{
if $::osfamily == 'windows' {
}
else {
class{main_config::install:} ->
class{main_config::config:}
}
}
Also I have installed puppet modules that are needed for both Linux and Windows. When I run puppet agent on Linux there are also Windows related modules like powershell exec which are installed and are not needed for Linux absolutely.
I am looking for the way to restrict modules based on OS type to avoid unnecessary modules getting installed.
For example, when I install puppetlabs-powershell puppet module on puppet master, then when I run puppet agent on clients on linux server then this windows module is also getting installed.

Related

/etc/init.d/puppet doesn't exist in puppet agent

I've followed this instructions to install the puppet agent in a docker with ubuntu 16.04.
https://puppet.com/docs/puppet/5.5/install_linux.html
So I've excecuted this
wget https://apt.puppetlabs.com/puppet5-release-xenial.deb
dpkg -i puppet5-release-xenial.deb
apt update
apt-get install puppet-agent
/opt/puppetlabs/bin/puppet resource service puppet ensure=running enable=true
The last line to start the service fails for this reason:
Error: Could not find init script for 'puppet'
Error: /Service[puppet]/ensure: change from 'stopped' to 'running' failed: Could not find init script for 'puppet'
service { 'puppet':
ensure => 'stopped',
enable => 'false',
}
The problem I think is that /etc/init.d/puppet doesn't exist.
The installer puppet agent version is 5.5.1.
Can you help me?
Thanks
Systemd, along with other init processes, are not installed by design, as you should be running your processes via an entrypoint or command option. In other words, the container should be running the command you are interested in, not a wrapper or bootstapping application.
In your case, puppet actually has a container that you can run out of the box for smoke-testing and such. You can find it here:
https://github.com/puppetlabs/puppet-in-docker
If though you are hell bent on running puppet agent jobs via systemd, you can actually attempt this with an example from a Redhat blog here:
https://developers.redhat.com/blog/2014/05/05/running-systemd-within-docker-container/

uninstall a module and its installed service using foreman puppet in Ubuntu

I have been playing with foreman for quite a while and now facing a problem with uninstalling modules.
When I try to uninstall a module using "Delete" button in Managing Class screen, I got an error that says "Module already used by host". Yes I understood, because its already mapped to host. I then revoked the module from host and deleted this module. This deletion happens only in foreman.
But I want to uninstall the service installed by foreman/puppet by puppet run (puppet agent -t ).
Do I have to use module's uninstall configuration, set appropriate values to params and do a puppet run to uninstall service before I delete module from foreman ?????
For example:
If I install apache with apache puppet module, it manages apache service, conf files, etc.... Now I want to completely remove apache service from all machines connected to my network.

puppet on solaris tries to update vim-enhanced

I have Solaris 10 operating system with puppet agent installed on it.
When I run puppet agent -t I get an Error:
Error: /Stage[main]//Package[vim-enhanced]/ensure: change from absent to latest failed: Could not update: Sun packages must specify a package source
I have no classes regarding updates of vim-enhanced on the master, so where is the error coming from ?
If I do have some classes that I'm not aware of, how do I specify a package source ?
You don't need to any classes, puppet "package" reference solving your problem.
Use this resource:
package {
'vim-enhanced':
ensure => present,
provider => rpm,
source => "puppet:///files/vim-enchanced.rpm";
}
But, only working if you are using puppet default file server!

How to set JAVA_HOME using puppet script on windows?

I am new to puppet and I want to install Java using puppet.
I have standalone puppet installed on my windows systems.
I was able to copy the binaries into specific folder using puppet but not able to set the path.
Can anyone please help me to set the simple JAVA_HOME/environment variable using puppet?
There is a module for managing environment variables in Windows.
For example
windows_env { 'JAVA_HOME':
ensure => 'C:\JDK',
mergemode => clobber,
}
The README even presents a specific example
windows_env { 'JAVA_HOME=%ProgramFiles%\Java\jdk1.6.0_02':
type => REG_EXPAND_SZ,
}

rpm installation using puppet

I am new to Puppet - I have been playing around learning the basics. Most of the examples ( except the very basic ones ) that are on the puppet page do not work for me - either some dependency is missing or package is not found. I do not see the logs explaining what went wrong ( even if I run the --test or --verbose option)
Can anyone clarify
1 What is the simplest process ( set of simple steps ) for installing a rpm package on a single Linux box ?
2 In general - how does one go about using the modules on the forge.puppetlabs ? Are the providers for these packages installed automatically or they have to be manually installed first ?
To install a package named pacman from command line:
puppet resource package pacman ensure=present
Corresponding puppet code will look like:
package { 'pacman':
ensure => '4.0.3-5',
}
Explore for more options about the package resource here
Regarding the question of installing puppet modules, have a look here. Official doc is your friend :)
Personally, I just copy-paste the module directory manually in a git repo which I use to maintain my puppet code.

Resources