How to set JAVA_HOME using puppet script on windows? - puppet

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,
}

Related

How do I use puppet to execute a script on a linux VM

I need puppet to execute a script that is inside an installed app. In addition I need to run only if it detects an older version of the and is not on a certain server and then install the new version
I have tried a bunch of stuff and I am losing track. First I tried to use a cd to go to the where the script and then tried running the script directly but I keep getting the same error.
install.pp
# Install required packages
class tripwire::install {
exec { 'uninstall_tripwire':
command => './usr/local/tripwire/te/agent/bin/uninstall.sh',
cwd => '/usr/local/tripwire/te/agent/bin',
path => '/usr/bin/sh',
onlyif => [
"${::fqdn} != 'server.com'",
'/usr/bin/test -f
/usr/local/tripwire/te/agent/bin/uninstall.sh',
"grep -c '8.6.0' /usr/local/tripwire/te/agent/data/version",
],
notify => Exec['install_tripwire'],
I would think this would it would execute the script but all I get is:
Error: /Stage[main]/Tripwire::Install/Exec[uninstall_tripwire]: Could not evaluate: Could not find command 'server.com'
I need puppet to execute a script that is inside an installed app. In
addition I need to run only if it detects an older version of the and
is not on a certain server and then install the new version
The particular task you seem to be trying to perform with your Exec duplicates standard behavior of the Package resource. You really, really ought to manage software via packages, even if you have to do some packaging yourself and maintain a local package repository. The time spent on packaging is easily offset by the time saved managing software, even with Puppet in the mix.
Additionally, as far as controlling which machines to operate upon goes, you ought to be treating that as a matter of classification. If that class should not be applied to machine server.com then it should not be declared into that machine's catalog. If it should be applied differently to that machine than to others, then it should be appropriately parameterized, and those parameters used (at classification time, maybe with the help of Hiera) to select the appropriate behavior for each target machine.
Nevertheless, with respect to the code actually presented, the error message
Could not evaluate: Could not find command 'server.com'
reflects that this element of your onlyif array ...
"${::fqdn} != 'server.com'",
... is not a command. onlyif requires a command or an array of them that can be executed on the target system, so maybe this, instead:
"test ${::fqdn} != server.com",
Additionally, this looks wrong:
command => './usr/local/tripwire/te/agent/bin/uninstall.sh',
Remove the leading ., unless you really intend to resolve that path against the working directory. And if you do intend to resolve it as a relative path then I urge you to instead expand it to an absolute one.
Furthermore, this probably doesn't do what you intend:
path => '/usr/bin/sh',
The path attribute names a binary search path, like the PATH environment variable. You may indeed want to specify one, such as maybe '/bin:/usr/bin:/sbin:/usr/sbin', but if the intention of what you did put was for the commmand to be executed via a shell, then you were looking for
provider => 'shell',

puppet restrict installed modules based on osfamily

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.

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!

Installing several RPMs with custom install flags

I'm trying to do the initial work to get our dev shop to start using vagrant + puppet during development. At this stage in my puppet manifest development, I need to install several RPMs that are available via an internal http server (not a repo) with very specific flags ('--nodeps').
So, here's an example of what I need to install:
http://1.2.3.4/bar/package1.rpm
http://1.2.3.4/bar/package2.rpm
http://1.2.3.4/bar/package3.rpm
I would normally install them in this way:
rpm --install --nodeps ${rpm_uri}
I would like to be able to do something like this
$custom_rpms = [
'http://1.2.3.4/bar/package1.rpm',
'http://1.2.3.4/bar/package2.rpm',
'http://1.2.3.4/bar/package3.rpm',
]
# edit: just realized I was instantiating the parameterized
# class wrong. :)
class { 'custom_package': package_file => $custom_rpms }
With this module
# modules/company_packages/manifests/init.pp
define company_package($package_file) {
exec { "/bin/rpm --install --nodeps ${package_file} --nodeps" }
}
But, I'm not sure if that's right. Can some of you puppet masters (no pun intended) school me on how this should be done?
You may have already worked around this by now, but if not.
Using a repository is the preferred method as it will autoresolve all the dependancies, but it that's not available you can try the following. (I'm using epel as an example rpm)
package {"epel-release":
provider=>rpm,
ensure=>installed,
install_options => ['--nodeps'],
source=>"http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm",
}
It used to be that 'install_options ' was only supported in windows.
It appears that it is now supported in linux.
If there is sequence that would be helpful, add "require=Package["package3.rpm"]," to sequence.
Answered by Randm over irc.freenode.net#puppet
Create or use an existing repo and install them with yum so that it resolves the dependencies for you.

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