Puppet unzip file always into read only folder - linux

I am using following script part to unzip my zip file. But the problem is it unzips the file always into a readonly folder. How can this be fixed.
exec { "install appliction server to pc":
command => 'unzip wso2as-5.2.1.zip',
cwd => '/home/malintha/adikari3/',
path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
logoutput => true,
timeout => 3600,
require => File['/home/malintha/adikari3/wso2as-5.2.1.zip'],
}

There are three parameters to the exec type, of which you should use at least one, to control when and when not to run
onlyif
unless
creates
The unzipping of an archive typically lends itself to a creates solution
exec { "unzip-file":
cwd => "/path/for/extraction",
creates => "/path/for/extraction/software-x.y",
...
}
assuming that the zip extracts into a directory tree rooted at software-x.y.
For more details, see the reference documentation.

Related

Verifying if package is installed before downloading it in PUPPET

That is my manifest code which download, install and remove installer on a host.
class googlechrome_2 {
package { 'GoogleChrome':
ensure => installed,
source => 'C:\Soft\ChromeSetup.msi',
install_options => ['/qn'],
require => File['GoogleChromeMsi'],
}
file { 'GoogleChromeMsi':
ensure => file,
path => 'C:\Soft\ChromeSetup.msi',
source => 'puppet:///files/production/ChromeSetup.msi',
}
exec { 'msi_removing':
command => 'C:\Windows\System32\cmd.exe /c del C:\Soft\ChromeSetup.msi',
}
}
In this case my windows host always download chromesetup.msi regardless if google chrome already installed or not. How can I realize kind of "if condition" here to avoid downloading msi package each time in case if this package already installed?
In this case my windows host always download chromesetup.msi regardless if google chrome already installed or not.
Yes. Having the File resource in the node's catalog specifies that the file should be managed. Therefore, if it is not initially in the target state then Puppet will attempt to fix that.
By managing the file present but also including an Exec that removes the file, you ensure that the target node cannot achieve a stable state.
How can I realize kind of "if condition" here to avoid downloading msi package each time in case if this package already installed?
Simplest option: don't remove the installer.
Variation: Put the installer in an accessible network folder, so that you not only don't remove it, but you also don't install it.
If you really want a conditional: then it should be based on a custom fact that reports on the installation status of the package in question. You then use a Puppet if statement to control the contents of the node's catalog appropriately. Something along these lines, for example:
package { 'GoogleChrome':
ensure => 'installed',
source => 'C:\Soft\ChromeSetup.msi',
install_options => ['/qn'],
# relationhip with File['GoogleChromeMsi'] now declared on the other end
}
if $facts['chrome_is_installed'] {
file { 'GoogleChromeMsi':
ensure => 'absent',
path => 'C:\Soft\ChromeSetup.msi',
}
} else {
file { 'GoogleChromeMsi':
ensure => 'file',
path => 'C:\Soft\ChromeSetup.msi',
source => 'puppet:///files/production/ChromeSetup.msi',
before => Package['GoogleChrome'],
}
exec { 'msi_removing':
command => 'C:\Windows\System32\cmd.exe /c del C:\Soft\ChromeSetup.msi',
require => Package['GoogleChrome'],
}
}
I've solved this by using network shared folder in the package source:
class googlechrome_smb {
package { 'Google Chrome':
ensure => installed,
source => '\\\xxx.xxx.xxx.xxx\winfiles\ChromeSetup.msi',
install_options => ['/qn'],
}
}

How to copy list of files using puppet

In puppet is it possible to copy of list of files
Tried below code, but didn't work
$list_files = ['file1','file2','file2']
file { $list_files:
ensure => present,
path => /tmp,
source => 'puppet:///modules/$module_name/list_file_dir/$list_files',
}
any Suggestions?
As others have said you can use the each switch e.g.
['file1','file2','file2'].each |$flie| {
file{ "/tmp/${file}":
ensure => file,
source => "puppet:///modules/$module_name/list_file_dir/${file}",
}
}
however it is also worth noting that you can pass a directory to both the destination and the source parameter e.g. if you have the directory puppet:///modules/$module_name/list_file_dir on your puppet master with the files ['file1','file2','file2'] then you can copy them all to temp using the following
file { '/tmp':
ensure => directory,
source => 'puppet:///modules/$module_name/list_file_dir',
recurse => remote,
}
using recurse => remote remote ensures puppet only manages files which exist in the remote location (i.e. the puppetmaster)
https://puppet.com/docs/puppet/7/types/file.html#file-attribute-recurse

Puppet Could not find command 'cd'

Hi there this part of my code causes an error.
path => '/bin:/sbin/:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin',
cwd => "/var/rapid7installer && unzip ${install_file}",
creates => '/var/rapid7installer/agent_installer.sh',
timeout => $timeout,
require => [
Package['unzip'],
File["/var/rapid7installer/${install_file}"],
],
}->
This is the error I am getting.
Error: /Stage[main]/Profiles::Rapid7agent/Exec[Rapid7 Agent Installation Unzip]/returns: change from 'notrun' to ['0'] failed: Could not find command 'cd'
I am hoping someone can help me or point me in the right direction. Thank you for looking and your time.
The fragment presented in the question is an incomplete unit, but it appears to be part of the declaration of an Exec resource. In that case, the cwd attribute is surely incorrect:
cwd => "/var/rapid7installer && unzip ${install_file}",
, and it probably is directly responsible for the issue you observe. The value of that attribute should be the name of a directory that should be the working directory during execution of the exec's command. From context, it appears that that should be just the first part, /var/rapid7installer. The actual command to execute must be conveyed via the command attribute, which defaults to the resource title if not given explicitly.
Thus, it appears you want something more like this:
exec { 'Rapid7 Agent Installation Unzip':
command => "unzip ${install_file}",
path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin',
cwd => '/var/rapid7installer',
creates => '/var/rapid7installer/agent_installer.sh',
timeout => $timeout,
require => [
Package['unzip'],
File["/var/rapid7installer/${install_file}"],
],
}

Puppet: how to use ignore globbing on file resources

Consider the following puppet config snippet:
file { "/opt/app/${name}/traces" :
ensure => directory,
owner => 'appuser',
group => 'appuser',
ignore => [ '*.tra' ],
backup => false,
recurse => false
}
The folder will contain "${name}..tra" files and I don't want puppet to take care of these files.
When calling strace or lsof against the puppet client, I can see it still tries to do something with these files (probably checksuming, according to the time spent on each file).
Thanks a lot,
Adam.

Customize CFEngine3 temporary downloaded files location

I am facing a issue while trying configuring something with CFENGINE3.5, I have created a policy to install some package from source, which download tar balls from some url and then untar it and further digs it with make and make install, everything working fine except while it download tar balls it keeps at "/etc" location, I want cfengine to put this file at /tmp.
Is there any way to customize this default behavior of cfengine to keep all temporary downloaded files at "/tmp" instead of "/etc".
Here is the Policy snippet:
bundle agent install
{
vars:
"packages" slist => {
"Algorithm-Diff-1.1902",
"Apache-DB-0.13",
"Apache-DBI-1.06",
"Apache-Session-1.83",
"Apache-SessionX-2.01",
"AppConfig-1.65",
"Archive-Tar-1.32",
};
commands:
"/usr/bin/wget http://10.X.X.X/downloads/perl-modules/$(packages).tar.gz;
/usr/bin/gunzip $(packages).tar.gz;
tar -xf $(packages).tar;
cd $(packages);
/usr/bin/perl Makefile.PL;
/usr/bin/make;
/usr/bin/make install;"
contain => standard,
classes => satisfied(canonify("$(packages)-installed"));
}
body contain standard
{
useshell => "true";
exec_owner => "root";
}
Thanks in advance.
You can add the directory in which the commands should be executed to the contain body, like this:
body contain standard
{
useshell => "true";
exec_owner => "root";
chdir => "/tmp";
}
Please note there are already a few contain bodies in the standard library (lib/3.5/commands.cf), maybe one of those can be used so you don't have to write your own. Note that CFEngine already executes as root, so exec_owner => "root" is not strictly necessary.

Resources